![]() |
Scratch challenge!
Pretty cool [URL="http://scratch.mit.edu/"]language[/URL], eh?
After solving a [URL="http://www.projecteuler.net/"]Project Euler[/URL] problem they let you view a forum where you get to see all the neat ways to solve the problems. Our way is probably always going to be brute force. To a hammer, everything looks like a nail. [B]To the forum: Can we solve all of Project Euler's problems in Scratch?[/B] |
001
1 Attachment(s)
[COLOR=White].[/COLOR]
|
002
1 Attachment(s)
[COLOR=White].[/COLOR]
|
[code]#! /usr/bin/env python3
i = 0 j = 1 tmp = 0 sum = 0 while tmp <= 4000000: tmp = i + j if tmp % 2 == 0: sum = sum + tmp # sum += temp i = j j = tmp # i, j = j, tmp print(str(sum)) [/code]My one complaint about Python is that it refuses to implicitly convert ints to strs. How I would have done it: [code]#! /usr/bin/env python3 sum, i, j = 0, 0, 1 while j < 4000000: if j % 2 == 0: sum += j i, j = j, i+j print(str(sum))[/code] |
See the attached PDF for a fancy way of doing the problem.
Edit: Um, see message #7. :smile: |
[QUOTE="that PDF"]Copyright Project Euler, further distribution without the consent of the author(s) prohibited[/QUOTE]
:max: Let's not set up a bad example. Right! I think their hidden forum that opens after one solves a problem is very similar to the Hoff forum. Everyone wants to get in. Few do.:flex: |
Oops! It has been removed.
If you want to see the PDF, solve problem #2 at Project Euler. :blush: |
[QUOTE=Batalov;300356]
Right! I think their hidden forum that opens after one solves a problem is very similar to the Hoff forum. Everyone wants to get in. Few do.:flex:[/QUOTE] Are greenies allowed into The Hoff? |
1 Attachment(s)
Solution of p9, it will take some time to solve it with (almost completely) brute force.
|
"play sound: meow!"
:cmd: That is why it takes so long... :razz: |
1 Attachment(s)
Solution of p6 is really fast with brute force:
|
| All times are UTC. The time now is 08:00. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.