mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2012-05-26, 03:47   #1
Xyzzy
 
Xyzzy's Avatar
 
"Mike"
Aug 2002

7,559 Posts
Default Scratch challenge!

Pretty cool language, eh?

After solving a Project Euler 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.



To the forum: Can we solve all of Project Euler's problems in Scratch?
Xyzzy is offline   Reply With Quote
Old 2012-05-27, 04:47   #2
Xyzzy
 
Xyzzy's Avatar
 
"Mike"
Aug 2002

7,559 Posts
Default 001

.
Attached Thumbnails
Click image for larger version

Name:	001.png
Views:	88
Size:	3.3 KB
ID:	8053  
Xyzzy is offline   Reply With Quote
Old 2012-05-27, 04:48   #3
Xyzzy
 
Xyzzy's Avatar
 
"Mike"
Aug 2002

7,559 Posts
Default 002

.
Attached Thumbnails
Click image for larger version

Name:	002.gif
Views:	64
Size:	7.9 KB
ID:	8054  
Xyzzy is offline   Reply With Quote
Old 2012-05-27, 05:11   #4
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×29×83 Posts
Default

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))
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))
Dubslow is offline   Reply With Quote
Old 2012-05-27, 05:18   #5
Xyzzy
 
Xyzzy's Avatar
 
"Mike"
Aug 2002

7,559 Posts
Default

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

Edit: Um, see message #7.

Xyzzy is offline   Reply With Quote
Old 2012-05-27, 05:36   #6
Batalov
 
Batalov's Avatar
 
"Serge"
Mar 2008
Phi(3,3^1118781+1)/3

5×1,811 Posts
Default

Quote:
Originally Posted by that PDF
Copyright Project Euler, further distribution without the consent of the author(s) prohibited

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.

Last fiddled with by Batalov on 2012-05-27 at 05:57
Batalov is offline   Reply With Quote
Old 2012-05-27, 05:45   #7
Xyzzy
 
Xyzzy's Avatar
 
"Mike"
Aug 2002

755910 Posts
Default

Oops! It has been removed.

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

Xyzzy is offline   Reply With Quote
Old 2012-05-27, 05:58   #8
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×29×83 Posts
Default

Quote:
Originally Posted by Batalov View Post
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.
Are greenies allowed into The Hoff?
Dubslow is offline   Reply With Quote
Old 2012-05-27, 10:36   #9
R. Gerbicz
 
R. Gerbicz's Avatar
 
"Robert Gerbicz"
Oct 2005
Hungary

2×3×227 Posts
Default

Solution of p9, it will take some time to solve it with (almost completely) brute force.
Attached Thumbnails
Click image for larger version

Name:	pic.gif
Views:	93
Size:	10.1 KB
ID:	8035  
R. Gerbicz is offline   Reply With Quote
Old 2012-05-27, 16:30   #10
LaurV
Romulan Interpreter
 
LaurV's Avatar
 
Jun 2011
Thailand

32·953 Posts
Default

"play sound: meow!"

That is why it takes so long...
LaurV is online now   Reply With Quote
Old 2012-05-27, 19:57   #11
R. Gerbicz
 
R. Gerbicz's Avatar
 
"Robert Gerbicz"
Oct 2005
Hungary

136210 Posts
Default

Solution of p6 is really fast with brute force:
Attached Thumbnails
Click image for larger version

Name:	p6.gif
Views:	74
Size:	6.6 KB
ID:	8038  
R. Gerbicz is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pls Help. On one computer (Win 10), every time restart Prime95, it restarts from scratch??!!! king Information & Answers 4 2018-02-14 07:49
A CD player from scratch Orgasmic Troll Puzzles 31 2012-09-12 21:47
Cat scratch! mfgoode Science & Technology 0 2007-06-08 09:05
Need to learn how to edit, and make from scratch, NewPGen files. jasong Software 2 2006-05-28 21:16
The Program Seems to Start from Scratch Each Time I Load it JackMama Software 13 2002-12-20 14:17

All times are UTC. The time now is 03:45.

Sat Jul 4 03:45:24 UTC 2020 up 101 days, 1:18, 1 user, load averages: 1.21, 1.15, 1.20

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.