mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Programming (https://www.mersenneforum.org/forumdisplay.php?f=29)
-   -   Scratch challenge! (https://www.mersenneforum.org/showthread.php?t=16846)

Xyzzy 2012-05-26 03:47

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]

Xyzzy 2012-05-27 04:47

001
 
1 Attachment(s)
[COLOR=White].[/COLOR]

Xyzzy 2012-05-27 04:48

002
 
1 Attachment(s)
[COLOR=White].[/COLOR]

Dubslow 2012-05-27 05:11

[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]

Xyzzy 2012-05-27 05:18

See the attached PDF for a fancy way of doing the problem.

Edit: Um, see message #7.

:smile:

Batalov 2012-05-27 05:36

[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:

Xyzzy 2012-05-27 05:45

Oops! It has been removed.

If you want to see the PDF, solve problem #2 at Project Euler.

:blush:

Dubslow 2012-05-27 05:58

[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?

R. Gerbicz 2012-05-27 10:36

1 Attachment(s)
Solution of p9, it will take some time to solve it with (almost completely) brute force.

LaurV 2012-05-27 16:30

"play sound: meow!"
:cmd:
That is why it takes so long... :razz:

R. Gerbicz 2012-05-27 19:57

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.