Challenge!

A while ago I started doing this with Python:

Today it dawned on me that maybe I could do it in Dynamo. :smiley:

So I just had a go.

Problem #1 is super easy in Dynamo! So much easier than I found it in Python.

However Problem #2 would be a total monster in Dynamo I think so I cheated and used a Python node. :smiley:

The logic of #3 was shockingly easy in Dynamo, however I got to see a new (to me) error message:
image

I just tried a work around but I think I have killed Dynamo :face_with_open_eyes_and_hand_over_mouth:

I thought some of you may fancy having a go at these challenges too… But watch out for #3 :laughing:

1 Like

@Aparajit_Pratap
it looks like this message it thrown when the process runs out of memory, when OutOfMemoryException Class (System) | Microsoft Docs is thrown…

I’ve never seen it before. Always fun seeing new errors, I must be getting better :laughing:

3 Likes

@Alien can you share the Dynamo graph that produced this warning?

The error happens in the first couple of nodes, not surprising though if you look at the challenge:
image

That’s a large number.

Had the same issue trying to stick it into a Python node too:

It kills regular (not in Dyno) python too… I think I need to rethink my logic :smiley:

What about not starting at 2 but at n - 10.000 or so?

Also, you could skip over all even numbers by starting on an uneven number and doing something like this:

N-10000…N…2;

Yeah, I tried a few variations. It hates anything over 6-7 figures though so I’m rethinking the strategy.

1 Like

image

Got it working in a Python node but don’t think I can Dynamo it without murdering Dynamo.

Not really. Done in a flash.

def fb(a:var[]..[])
{
	b = Math.Sum(List.TakeItems(a,-2));
	return List.AddItemToEnd(b,a);
};

def fib(a)
{
	b = fb(1..2);
	return [Imperative]
	{
		c = [];
		while (List.LastItem(b) < a)
		{
			c = fb(b);
			b = c;
		}
		return List.DropItems(c,-1);
	}
};

f1 = fib(4000001);
f2 = f1 % 2 == 0;
Math.Sum(List.FilterByBoolMask(f1,f2)["in"]);
3 Likes

I did it in Python in Dyno.

By Dyno, I mean actual code blocks.

image

While I don’t really understand designscript, what I can make out looks like we used the same logic. :smiley:

1 Like

#2 much improve :smiley:

image