Project Euler
- Retrofuturist
- Posts: 3131
- Joined: 2008.09.19 (06:55)
- MBTI Type: ENTP
- Location: California, USA
- Contact:
I know some of you must have heard of this, because it was here that I first heard of it and started on it. I didn't get very far before I stopped and forgot my login information.
Semi-recently, a computer science-oriented club I'm affiliated with has been discussing some of these problems, so I've gotten back in the game.
I've only really worked on them during biweekly club meetings, and I finished problem #25 earlier today at one of those meetings. (I've been doing them strictly in order, without skipping.)
Has anyone else worked on this / is anyone working on these problems actively?

- Demon Fisherman
- Posts: 1246
- Joined: 2008.10.01 (23:37)
- NUMA Profile: http://nmaps.net/squibbles
- MBTI Type: ENFP
- Location: Canberra
My computing class used to work on these in yr 12 once we finished our assignments, since we were not allowed to play games and all the computers had been reoriented so the screens faced the teacher's desk.
More often then not we ended up just writing programs to solve them for us, though.
- Retrofuturist
- Posts: 3131
- Joined: 2008.09.19 (06:55)
- MBTI Type: ENTP
- Location: California, USA
- Contact:
The directions tell you to do exactly that. The simplest of these are stupidly difficult without the aid of a computer.squibbles wrote:More often then not we ended up just writing programs to solve them for us, though.

- Demon Fisherman
- Posts: 1246
- Joined: 2008.10.01 (23:37)
- NUMA Profile: http://nmaps.net/squibbles
- MBTI Type: ENFP
- Location: Canberra
Well, either way, I'm up for a bit of a community race right now with these. Anyone else?
- RoboBarber
- Posts: 367
- Joined: 2008.09.30 (21:43)
- NUMA Profile: Legions of http://nmaps.net/user/Onesevennine
- MBTI Type: INFP
- Location: Texas'); DROP TABLE Members;--
Looking at question 1 alone, there are 98047 (as of today) people that like math a lot more than I do.
I'd join the race except for the fact that I can't find a single problem that I wouldn't just write a program to brute-force, other than possibly the first one which I could probably manage. Unless brute-forcing is how you're supposed to do it, which I doubt it is.

"Whosoever dies with his art on the most hard drives, wins." - Michael W. Dean'
- Retrofuturist
- Posts: 3131
- Joined: 2008.09.19 (06:55)
- MBTI Type: ENTP
- Location: California, USA
- Contact:
You're free to get the answer by any means you want, including brute-forcing. But many of the later problems introduce subtle complications that would make the brute force take ages if not optimized in some clever way.OneSevenNine wrote:I'd join the race except for the fact that I can't find a single problem that I wouldn't just write a program to brute-force, other than possibly the first one which I could probably manage. Unless brute-forcing is how you're supposed to do it, which I doubt it is.
If you want to get technical, the way I've solved most of these is through a brute-force approach, but very few of my solutions have taken more than a few seconds because I reduced the problem space dynamically based on the ongoing results of the brute-force search, and that is not something a common clueless code monkey would think or be able to do.
Additionally,
And obviously, the first few problems are a breeze. They're supposed to be.projecteuler.net wrote:I've written my program but should it take days to get to the answer?
Absolutely not! Each problem has been designed according to a "one-minute rule", which means that although it may take several hours to design a successful algorithm with more difficult problems, an efficient implementation will allow a solution to be obtained on a modestly powered computer in less than one minute.
When I finished problem #25, it said I earned "first level" and gave me a tetrahedron-shaped badge. It was a little weird, sure, but it also said that I achieved what 79% of people who tried Project Euler problems have not. So even though there are thousands of solutions per problem, only a fraction of those have actually gotten meaningfully far in the latter problems.

- On the Psychic Highway
- Posts: 290
- Joined: 2009.11.16 (05:05)
- NUMA Profile: http://nmaps.net/user/script
- MBTI Type: INTJ
- Location: On a boat

<Uuni> i dont see the escape in religion
- Retrofuturist
- Posts: 3131
- Joined: 2008.09.19 (06:55)
- MBTI Type: ENTP
- Location: California, USA
- Contact:
Ha!Scrivener wrote:my calculator... the only thing i can do programming of any real significance on.
Project Euler is not for you.

- Diagnosis Mohawk: Bahrain Cock Theory
- Posts: 1405
- Joined: 2008.09.23 (13:25)
- NUMA Profile: http://nmaps.net/user/spawn_of_yanni
- MBTI Type: ENFJ
- Location: Pittsburgh

feline disrespect from behind
- Demon Fisherman
- Posts: 1246
- Joined: 2008.10.01 (23:37)
- NUMA Profile: http://nmaps.net/squibbles
- MBTI Type: ENFP
- Location: Canberra
I need to find myself a compiler, however, as I accidentally lost it in my OS change, and thus cannot do much with Java right now.
-
- Raigan and the Horse-Woman
- Posts: 182
- Joined: 2008.09.27 (02:14)
- NUMA Profile: www.nmaps.net/user/sidke
- Steam: www.steamcommunity.com/id/shagdish
- Location: ⑨
- Contact:
also python makes these a lot easier, letting you spend more time on actual problem solving than code debugging

辻菜摘が好きじゃー ヽ(´ー`)ノ sig by peking duck
- Retrofuturist
- Posts: 3131
- Joined: 2008.09.19 (06:55)
- MBTI Type: ENTP
- Location: California, USA
- Contact:
Tangent:
Some time ago, I was interested in knowing a wide range of programming languages so that I had a bunch of useful tools to choose from for any particular task, but I noticed pretty quickly that just about anything I do with code fits pretty solidly into one of two categories:
- I need it to run extremely quickly.
- It's a totally non-intensive doodad that I want for convenience.
However, some of the brute-force approaches I took on some of the problems were simply taking far too long in Ruby, and though some part of me feels like it's cheating at Ruby Practice when I recode my algorithm in C and have it finish in under a second, for some of these problems, I just want to move past them and never think about them again.
Regarding Java, I am beside myself with joy to know that every CS professor I've had at UCSC despises Java. Fuck it, deep and in the skull, while its children watch.
Oh, and I've also been learning Scheme on the side, starting with the famous SICP (the MIT "wizard book") and moving on through The Little Schemer, The Seasoned Schemer, and the Reasoned Schemer. I'm about 20% of the way through Seasoned Schemer right now, having read the previous two mentioned. I haven't learned nearly enough of the language to actually work on these problems, though... maybe I'll try to kludge Scheme into use when I learn enough about it. The problem is primarily that the books (and, heck, the language itself) are designed more to help you think about computer science in novel ways rather than to teach you to write production code. I'm learning all kinds of weird, mind-bendy tricks with lambda functions, but still have yet to learn basic I/O or string manipulation. I should probably move on to Common Lisp when I finish with The Reasoned Schemer or something.

- RoboBarber
- Posts: 367
- Joined: 2008.09.30 (21:43)
- NUMA Profile: Legions of http://nmaps.net/user/Onesevennine
- MBTI Type: INFP
- Location: Texas'); DROP TABLE Members;--
Optimization of Brute-forcing? That's something I never thought about... I always assumed that the point was to find some sort of shortcut that you'd have to be a math/logic genius to recognize. I might try some with that in mind, though if I didn't think of it in the first place who knows how far I'll get.Tsukatu wrote: You're free to get the answer by any means you want, including brute-forcing. But many of the later problems introduce subtle complications that would make the brute force take ages if not optimized in some clever way.
If you want to get technical, the way I've solved most of these is through a brute-force approach, but very few of my solutions have taken more than a few seconds because I reduced the problem space dynamically based on the ongoing results of the brute-force search, and that is not something a common clueless code monkey would think or be able to do.
Just my luck, Java is the standard for what high schools teach around here. After three years of it, I've been thinking about trying teach myself python or something over the summer.Tsukatu wrote: Regarding Java, I am beside myself with joy to know that every CS professor I've had at UCSC despises Java. Fuck it, deep and in the skull, while its children watch.

"Whosoever dies with his art on the most hard drives, wins." - Michael W. Dean'
- On the Psychic Highway
- Posts: 290
- Joined: 2009.11.16 (05:05)
- NUMA Profile: http://nmaps.net/user/script
- MBTI Type: INTJ
- Location: On a boat
Stupid BASIC programming.OneSevenNine wrote:I've been thinking about trying teach myself python or something over the summer.

<Uuni> i dont see the escape in religion
- Retrofuturist
- Posts: 3131
- Joined: 2008.09.19 (06:55)
- MBTI Type: ENTP
- Location: California, USA
- Contact:
Fine, there is one thing worse than Java.Scrivener wrote:BASIC programming.

-
- Yes sir, no sir, three bags full sir
- Posts: 1561
- Joined: 2008.09.26 (12:33)
- NUMA Profile: http://nmaps.net/user/incluye
- MBTI Type: ENTP
- Location: USofA
- Contact:
If PHP counts, there are two things.Tsukatu wrote:Fine, there is one thing worse than Java.Scrivener wrote:BASIC programming.
Still, my best language (until I get better at Ruby) is PHP, so that's what I've been using.
Incidentally, are there any better tactics than brute-forcing with Problem 1? (As in a for loop, starting at 3, incrementing by 1 each step, if divisible by 3 or 5 add to total sum)

- Retrofuturist
- Posts: 3131
- Joined: 2008.09.19 (06:55)
- MBTI Type: ENTP
- Location: California, USA
- Contact:
You're doing upwards of 2000 computations (up to 2 division problems for each of 1000 iterations), and that's extremely wasteful. You can get away with it here for such a small range, but you'll need more clever solutions in later problems.incluye wrote:Incidentally, are there any better tactics than brute-forcing with Problem 1? (As in a for loop, starting at 3, incrementing by 1 each step, if divisible by 3 or 5 add to total sum)
Although I shouldn't be talking, because I think the way I did it ended up being a little more costly in terms of CPU time, but I think it's more elegant. :p
What I did was build sets of all multiples of 3 and all multiples of 5, take their union (which will weed out duplicates), and the sum up the values in that union. Rather than write my own set-intersection functions, though, I assumed that Ruby's was good enough. It was only the first problem, after all.
My solution was a one-liner in Ruby:
Code: Select all
((1..333).map { |i| i*3 } | (1..199).map { |i| i*5 }).inject(0) { |sum, n| sum + n }
Code: Select all
threes = (1..333).map { |i| i*3 }
fives = (1..199).map { |i| i*5 }
union = threes | fives
union.inject(0) { |sum, n| sum + n }

-
- Plus (Size) Member
- Posts: 42
- Joined: 2008.09.27 (02:56)
Each of these sums is the sum of natural numbers 1..N for some finite N, which is to say there is a closed form: N * (N+1) / 2. Net result: three increments, six multiplications, three right shifts (which could actually be done at the end, for only one right shift), an add, and a subtract.
- Retrofuturist
- Posts: 3131
- Joined: 2008.09.19 (06:55)
- MBTI Type: ENTP
- Location: California, USA
- Contact:
This is far superior. I was trying to come up with this solution, but I thought for more than five seconds about how to do it, which is the threshold amount of time I'd spend on a problem that can be brute-forced in under a second.taaveti wrote:Personally, I would add three times the sum of the natural numbers <= 333 (which is the sum of the multiples of three < 1000) and five times the sum of the natural numbers < 200 (which is the sum of the multiples of five < 1000), then subtract fifteen times the sum of the natural numbers <= 66 (which is the sum of the multiples of fifteen < 1000, i.e. those which were double-counted).
Each of these sums is the sum of natural numbers 1..N for some finite N, which is to say there is a closed form: N * (N+1) / 2. Net result: three increments, six multiplications, three right shifts (which could actually be done at the end, for only one right shift), an add, and a subtract.

-
- Life Time Achievement Award
- Posts: 253
- Joined: 2008.11.11 (23:53)
- NUMA Profile: http://nmaps.net/browse?q=author:Brainwasher
- MBTI Type: INTP
- Location: Around the usual places.

- Global Mod
- Posts: 1416
- Joined: 2008.09.26 (05:35)
- NUMA Profile: http://nmaps.net/user/scythe33
- MBTI Type: ENTP
- Location: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
My fault: http://forum.droni.es/viewtopic.php?f=32&t=2751Tsukatu wrote:http://www.projecteuler.net
I know some of you must have heard of this, because it was here that I first heard of it and started on it. I didn't get very far before I stopped and forgot my login information.
Semi-recently, a computer science-oriented club I'm affiliated with has been discussing some of these problems, so I've gotten back in the game.
I've only really worked on them during biweekly club meetings, and I finished problem #25 earlier today at one of those meetings. (I've been doing them strictly in order, without skipping.)
Has anyone else worked on this / is anyone working on these problems actively?
I haven't done a problem in months, but you can find me there under "_scythe". I think I've done about 37, the highest of which is #207.
- Retrofuturist
- Posts: 3131
- Joined: 2008.09.19 (06:55)
- MBTI Type: ENTP
- Location: California, USA
- Contact:

- Yet Another Harshad
- Posts: 471
- Joined: 2008.10.24 (09:39)
- NUMA Profile: http://nmaps.net/user/z3phyr
- MBTI Type: ISTP
- Location: Australia
Would WolframAlpha help?

Orange- N cannot be spoken, or even thought about in my household. If my parents ever found out that I have played N since the cleansing, my life would be ruined. I keep the game in a multi-passworded .rar on a USB flash drive inside a locked boron alloy container that requires two keys to open (I keep one under the 64th hammer in my piano, and the other one in a small section of removable ceiling in the corner of the attic) hidden in a wall compartment lined with aluminium foil to prevent sonar detection behind my 375 kg cupboard, which is bolted to the floor - the only way to reach it is to abseil outside the fourth floor window and use a screwdriver to unfasten the screws holding the secret brick in place on the opposite side of the wall, but the screwdriver must be a specific type like the one I own, since if any other screwdriver comes into contact with the screws, the entire building will explode, as will a seperate charge placed inside the boron alloy container, rendering the USB useless. Even once the container is retrieved, attemping to open it without the arming pin in place (which is kept inside the battery compartment of my Maglite) will cause the water reservoirs lining the container to burst and react with the caesium lining, causing the container to burst into flames - the only way to prevent this is to use the arming pins to shut off the reservoirs with a sliding steel door. The USB itself contains an accelerometer linked to an explosive charge, meaning that if the USB detects its own movement speed as being greater than 5 cm/s, it will explode - any person attempting to steal it would have to move at a uselessly slow speed. Once plugged into a computer, the USB will upload a ghost virus onto it, leaving no traces. Only the right password can deactivate this virus, and if it is left on the computer for more than six hours, it will format all drives.
As you can see, I take my N playing very seriously.
Guiseppi- I'd much rather watch animals get boned in the ass.
Yanni- If it's glad, it's not rape.
Tsukatu- I refuse to use throw-away bags for such a frequent purpose as buying groceries. Instead, I've collected the hair of my two pet dogs and have woven them together into an all-natural, 100% environmentally friendly bag that I bring with me everywhere. And when I buy products that come in glass and plastic containers, I track down the company that packages them and ship back their containers so that they don't take up space in landfills.
Yeah, I use plastic.
Tsukatu- I hear Ebony Online is great, too. Cum save your princess, my lord!
Ska- UR MUM LIKE IS SPICY
Ska- why d i get the feeling what i typed will end up in the quote depository; or worse: someone's sig.
KinGAleX- I did it on the couch a little while ago.
Zeph- I got too pissed at the knife in the end so I just broke the wood on my knee
[13:50:29] |<-- Zeph has left irc.mountai.net (Quit: Zeph)
[13:50:53] <Zeph> omfg 1950s jazz
[13:50:57] <WorldCupE> ZEPH
[13:51:01] <WorldCupE> WHAT
[13:51:11] <WorldCupE> hpw
[13:51:12] <WorldCupE> how
[13:51:12] <Zeph> everyone wears out halfway through the match
[13:51:15] <WorldCupE> ._.
[13:51:17] <WorldCupE> you
[13:51:19] <WorldCupE> aren't
[13:51:20] <WorldCupE> here
[13:51:24] <WorldCupikaze> I think the broadcasters lowered the volume for certain frequencies
[13:51:35] <WorldCupikaze> WOAH
[13:51:38] <WorldCupikaze> STOP IT ZEPH
[13:51:46] <WorldCupE> he's in #n
[13:51:49] <WorldCupE> but not here
[13:51:58] <Zeph> that nz guy wasn't fouled
[13:52:05] <WorldCupikaze> DUBBLE YOO. TEE. EFF.
[13:52:05] <WorldCupikaze> STOPIT
[13:52:29] <WorldCupE> I don't think Zeph can read what we say
[13:52:38] <WorldCupikaze> No
[13:52:41] <WorldCupikaze> But it still happens
[13:52:46] <WorldCupE> xD
[13:52:47] <Zeph> holy shot I'm vibrating to 1950s relaxing jazz
[13:52:58] <WorldCupE> ZEPH
[13:53:01] <WorldCupE> CAN YOYU HEAR ME
[13:53:20] <WorldCupE> donfuy
[13:53:23] <WorldCupE> have you seen this
[13:53:35] <Donfuy> i can't
[13:53:43] <WorldCupE> can't what
[13:53:47] <WorldCupE> Zeph isn't here
[13:53:48] <WorldCupikaze> WHAT's GOING ON
[13:53:51] <WorldCupE> but is speaking
[13:53:51] <WorldCupE> D:
[13:53:58] <Donfuy> can't see what huh?
[13:54:06] <WorldCupikaze> IT'S THE APOCALYPSE
[13:54:10] <Donfuy> where's zeph o_o
[13:54:18] <WorldCupE> precisely
[13:54:21] <WorldCupikaze> Exactly
[13:55:21] <WorldCupikaze> call wide
[13:55:24] <Zeph> Pooh
[13:55:28] <WorldCupikaze> EH?
[13:55:37] <WorldCupikaze> OOOOOOOOoh
[13:55:38] <Zeph> amazing slide tackle saves day
[13:55:48] <WorldCupikaze> WHY ARE YOU TALKING YOU AREN'T HERE
[13:56:53] <WorldCupikaze> call wide
[13:57:02] -->| Zeph ([email protected]) has joined #Worldcup
[13:32:33] |<-- Zeph has left irc.mountai.net (Quit: Zeph)
[13:32:43] <WorldCupE> ZEPH D:<
[13:32:44] <Zeph> fucking irc app
[13:32:47] <WorldCupE> O_O
[13:32:50] -->| Zeph ([email protected]) has joined #Worldcup
- Demon Fisherman
- Posts: 1246
- Joined: 2008.10.01 (23:37)
- NUMA Profile: http://nmaps.net/squibbles
- MBTI Type: ENFP
- Location: Canberra
For some puzzles, yeah, you could do it there, but you wouldn't be able to for a vast majority of them. :SZephyr wrote:Okay I made an account, I can only do a little bit of programming, but I guess I'll try.
Would WolframAlpha help?
- Yet Another Harshad
- Posts: 471
- Joined: 2008.10.24 (09:39)
- NUMA Profile: http://nmaps.net/user/z3phyr
- MBTI Type: ISTP
- Location: Australia

Orange- N cannot be spoken, or even thought about in my household. If my parents ever found out that I have played N since the cleansing, my life would be ruined. I keep the game in a multi-passworded .rar on a USB flash drive inside a locked boron alloy container that requires two keys to open (I keep one under the 64th hammer in my piano, and the other one in a small section of removable ceiling in the corner of the attic) hidden in a wall compartment lined with aluminium foil to prevent sonar detection behind my 375 kg cupboard, which is bolted to the floor - the only way to reach it is to abseil outside the fourth floor window and use a screwdriver to unfasten the screws holding the secret brick in place on the opposite side of the wall, but the screwdriver must be a specific type like the one I own, since if any other screwdriver comes into contact with the screws, the entire building will explode, as will a seperate charge placed inside the boron alloy container, rendering the USB useless. Even once the container is retrieved, attemping to open it without the arming pin in place (which is kept inside the battery compartment of my Maglite) will cause the water reservoirs lining the container to burst and react with the caesium lining, causing the container to burst into flames - the only way to prevent this is to use the arming pins to shut off the reservoirs with a sliding steel door. The USB itself contains an accelerometer linked to an explosive charge, meaning that if the USB detects its own movement speed as being greater than 5 cm/s, it will explode - any person attempting to steal it would have to move at a uselessly slow speed. Once plugged into a computer, the USB will upload a ghost virus onto it, leaving no traces. Only the right password can deactivate this virus, and if it is left on the computer for more than six hours, it will format all drives.
As you can see, I take my N playing very seriously.
Guiseppi- I'd much rather watch animals get boned in the ass.
Yanni- If it's glad, it's not rape.
Tsukatu- I refuse to use throw-away bags for such a frequent purpose as buying groceries. Instead, I've collected the hair of my two pet dogs and have woven them together into an all-natural, 100% environmentally friendly bag that I bring with me everywhere. And when I buy products that come in glass and plastic containers, I track down the company that packages them and ship back their containers so that they don't take up space in landfills.
Yeah, I use plastic.
Tsukatu- I hear Ebony Online is great, too. Cum save your princess, my lord!
Ska- UR MUM LIKE IS SPICY
Ska- why d i get the feeling what i typed will end up in the quote depository; or worse: someone's sig.
KinGAleX- I did it on the couch a little while ago.
Zeph- I got too pissed at the knife in the end so I just broke the wood on my knee
[13:50:29] |<-- Zeph has left irc.mountai.net (Quit: Zeph)
[13:50:53] <Zeph> omfg 1950s jazz
[13:50:57] <WorldCupE> ZEPH
[13:51:01] <WorldCupE> WHAT
[13:51:11] <WorldCupE> hpw
[13:51:12] <WorldCupE> how
[13:51:12] <Zeph> everyone wears out halfway through the match
[13:51:15] <WorldCupE> ._.
[13:51:17] <WorldCupE> you
[13:51:19] <WorldCupE> aren't
[13:51:20] <WorldCupE> here
[13:51:24] <WorldCupikaze> I think the broadcasters lowered the volume for certain frequencies
[13:51:35] <WorldCupikaze> WOAH
[13:51:38] <WorldCupikaze> STOP IT ZEPH
[13:51:46] <WorldCupE> he's in #n
[13:51:49] <WorldCupE> but not here
[13:51:58] <Zeph> that nz guy wasn't fouled
[13:52:05] <WorldCupikaze> DUBBLE YOO. TEE. EFF.
[13:52:05] <WorldCupikaze> STOPIT
[13:52:29] <WorldCupE> I don't think Zeph can read what we say
[13:52:38] <WorldCupikaze> No
[13:52:41] <WorldCupikaze> But it still happens
[13:52:46] <WorldCupE> xD
[13:52:47] <Zeph> holy shot I'm vibrating to 1950s relaxing jazz
[13:52:58] <WorldCupE> ZEPH
[13:53:01] <WorldCupE> CAN YOYU HEAR ME
[13:53:20] <WorldCupE> donfuy
[13:53:23] <WorldCupE> have you seen this
[13:53:35] <Donfuy> i can't
[13:53:43] <WorldCupE> can't what
[13:53:47] <WorldCupE> Zeph isn't here
[13:53:48] <WorldCupikaze> WHAT's GOING ON
[13:53:51] <WorldCupE> but is speaking
[13:53:51] <WorldCupE> D:
[13:53:58] <Donfuy> can't see what huh?
[13:54:06] <WorldCupikaze> IT'S THE APOCALYPSE
[13:54:10] <Donfuy> where's zeph o_o
[13:54:18] <WorldCupE> precisely
[13:54:21] <WorldCupikaze> Exactly
[13:55:21] <WorldCupikaze> call wide
[13:55:24] <Zeph> Pooh
[13:55:28] <WorldCupikaze> EH?
[13:55:37] <WorldCupikaze> OOOOOOOOoh
[13:55:38] <Zeph> amazing slide tackle saves day
[13:55:48] <WorldCupikaze> WHY ARE YOU TALKING YOU AREN'T HERE
[13:56:53] <WorldCupikaze> call wide
[13:57:02] -->| Zeph ([email protected]) has joined #Worldcup
[13:32:33] |<-- Zeph has left irc.mountai.net (Quit: Zeph)
[13:32:43] <WorldCupE> ZEPH D:<
[13:32:44] <Zeph> fucking irc app
[13:32:47] <WorldCupE> O_O
[13:32:50] -->| Zeph ([email protected]) has joined #Worldcup
Who is online
Users browsing this forum: No registered users and 10 guests