11 ms·
Project Euler
- MontagFTB 5y agoI have found this series of problems to be a good way of getting started with a new language. Because they are straightforward, the main issue with the problem isn’t as much how you solve them, but how to get what I have in my head into a language I’m unfamiliar with.
- jacquesm 5y agoThat's exactly how I use them. After the first 50 or so the ROI of that diminishes and you need to move on to something more effective. For that I use a project that I keep re-doing in different languages / eco-systems (a simple spaced repetition learning application).
- wging 5y agoThey start off that way, so it is good for that, but that flips around in later problems... coding them is not the hard part. Many require nontrivial mathematical insight to solve in any practical time frame.
- cameronh90 5y agoMakes me wonder if there's something like Project Euler but for more programming-like problems. Logic, application of well known algorithms, modelling, etc.
- Q6T46nT668w6i3m 5y agoLeetCode
- rawling 5y agoCodeWars?
- elsjaako 5y agoThere is cryptopals for crypographic security exploit stuff. It's very good! https://cryptopals.com/sets/1 https://cryptopals.com/sets/1
- gfosco 5y agoAlso, CodeChef. https://www.codechef.com/ https://www.codechef.com/
- wging 5y agoI really like Advent of Code for that. https://adventofcode.com/ https://adventofcode.com/
- Igelau 5y agoRosetta Code might fit the bill... http://rosettacode.org/wiki/Rosetta_Code http://rosettacode.org/wiki/Rosetta_Code As long as you just read the problem description first, and don't cheat by skipping right to the implementations.
- kadoban 5y agoCompetitive programming sites are at least a lot more like that than PE. Examples: cses.fi/problemset , codeforces.com , codechef.com , hackerrank.com (tho HR makes it harder to find the good problems every time I look).
- genewitch 5y agoStack exchange has their competitions, where, for example, you write a bot to compete against other bots, as well as code golf and things like "fastest solutions" to problems. I once wasted two weeks just reading the problems. https://codegolf.stackexchange.com/tags https://codegolf.stackexchange.com/tags
- julienpalard 5y agoI learned Python using Project Euler, and then created https://hackinscience.org https://hackinscience.org, it's the same but different (only Python, running unit tests against your code).
- __s 5y agoSame here for me 15 years ago (& then C when my brute force approaches needed the perf boost to finish in a timely manner) Recently ran into Project Euler again while benchmarking my recent Befunge JIT work. Most Befunge programs are pretty light computationally, but https://github.com/Mikescher/Project-Euler_Befunge https://github.com/Mikescher/Project-Euler_Befunge solves the first 102 problems in Befunge It's given me reason to go beyond spec & eventually I'll implement 64 bit cells with unbounded space so that I can execute their entire catalog
- wging 5y agoI really like Project Euler. I'm unsure why it's coming up now, but everyone is new to it at some point. Some advice: people should definitely start off in linear order to warm up, and it's worth sticking with a problem for a while... but I think at some point it becomes valuable to skip around a bit and do the next one if you get stuck. These are the sort of problems where a fresh perspective can be very valuable. Also, reading the solutions from the forum thread that is unlocked after you solve one will give you a LOT of insight - definitely do that.
- rotexo 5y agoI’m definitely curious about other people’s approach to Project Euler. My experience was that the first several were pretty straightforward, but I pretty quickly ran into a wall where I couldn’t rely on my intuition to generate a solution that would work in an acceptable time frame (python is a hobby for me, and I’m not sure that I have the quantitative ability to go much farther than that. Im curious how many other people look up algorithms and then implement them when they run into a similar wall, or how many people sit and think and implement ideas until they have an answer.
- adenozine 5y agoProject Euler problems for the most part aren't like brainteasers. Sometimes you just do not have the mathematical context to arrive at an optimal solution. Browse Wikipedia a bit or watch some math videos or something when you're stuck, and think about how to exploit the fast nature of computers with what rigorous mathematical understanding of the problem you have. Also, I once spent over thirty cumulative hours on a single PE problem, and I never solved it, I gave up. Don't feel bad. It doesn't make you a bad programmer, just a bad mathematician. That's probably not that big of a deal!
- can16358p 5y agoI don't think it necessarily makes you a bad mathematician either. We all sometimes focus on a problem and start thinking inside the box whereas it has a simple out-of-the-box solution that we're missing because of our focus. Just like a novice programmer can sometimes easily spot an expert programmer's bug in a mere of minutes.
- mirekrusin 5y agoOnes that get you stuck are the best ones. That's the ones with potential to teach you something you didn't know and improve your skills. Find a way to fall in love with training. Don't fixate on holding the trophy.
- weatherlight 5y ago
- yeellow 5y agoIs there a website that would gather different solution to those problems (or other similar problems, like Advent of Code) written in Python preferably sorted by some rating? I don't want to scroll the long list of similar solutions but I would like to see selected interesting attempts. I think it's a good way to learn new tricks and useful libraries, but searching for different solutions on blogs/git repos/long reddit threads is no fun.
- emi2k01 5y agoProject Euler explicitly says this [1]: > I learned so much solving problem XXX, so is it okay to publish my solution elsewhere? > It appears that you have answered your own question. There is nothing quite like that "Aha!" moment when you finally beat a problem which you have been working on for some time. It is often through the best of intentions in wishing to share our insights so that others can enjoy that moment too. Sadly, that will rarely be the case for your readers. Real learning is an active process and seeing how it is done is a long way from experiencing that epiphany of discovery. Please do not deny others what you have so richly valued yourself. > However, the rule about sharing solutions outside of Project Euler does not apply to the first one-hundred problems, as long as any discussion clearly aims to instruct methods, not just provide answers, and does not directly threaten to undermine the enjoyment of solving later problems. Problems 1 to 100 provide a wealth of helpful introductory teaching material and if you are able to respect our requirements, then we give permission for those problems and their solutions to be discussed elsewhere. I'd advise anyone who wants to solve the first 100 problems against looking their solutions online. They are simple enough to not require you to research complex topics to solve them as later problems do. I'd recommend Rosetta Code [2] if someone wants to have a look at a programming language in action. [1] https://projecteuler.net/about https://projecteuler.net/about [2] http://www.rosettacode.org/wiki/Category:Programming_Languages http://www.rosettacode.org/wiki/Category:Programming_Languag...
- dahart 5y agoProject Euler has exactly what you’re asking for. The catch is that you have to solve the problem first before seeing the list of selected solutions. Once you input the right answer, the solutions there are limited to solutions that have been upvoted, and recent solutions. The recent solutions disappear as new ones arrive, but the upvoted ones stick around. This is a fabulous way to learn new tricks and insights, as long as you’re up for sticking with it. Solving the problems does force you to be invested, and it’s great to see how much better/faster/smaller/smarter some other people’s solutions are once you’ve had to come up with your own way.
- deleted 5y ago[deleted]
- kadoban 5y agoPE is fun. I feel like for the vast majority of programmer types though, something like: cses.fi/problemset , codeforces.com , codechef.com are better places to do problems. PE gets _very_ math heavy past the beginning ones. Competitive programming problems get difficult as well, but they focus more on algorithms and data structures that programmers are more likely to have a solid background for.
- ketanmaheshwari 5y agoI am on a mission to solve 100 Project Euler problems using the Awk programming language. About 20 solved so far: https://github.com/ketancmaheshwari/projecteuler https://github.com/ketancmaheshwari/projecteuler
- Smaug123 5y ago(Note for everyone: Project Euler requests that people only post public solutions to problems 1-100, per https://projecteuler.net/ https://projecteuler.net/.)
- marcodiego 5y agoTook a look at the simplest problem: Multiples of 3 or 5 Problem 1 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. The naive idea is: iterate from 0 to 1000, test each number, add it to an (initially zeroed) accumulator when adequate. A little bit of thinking... ok, sum the multiples of 3, add the multiples of 5 and subtract multiples of 15. A little more bit of thinking: sum of multiples of 3, 5 and subtract multiples of 15. These can be calculated using an arithmetic progression formula in O(1) and limits can be found using rest of division operation. Cool! Even a simple problem made me think of a naive solution and how to iteratively improve it.
- rand846633 5y agoAn you explain me the difference between your solution 2 and 3?
- dan-robertson 5y agoAs in: 1. sum [i | i <- [1..1000], i % 3 == 0 || i % 5 == 0] 2. sum [3,6..1000] + sum [5,10..1000] - sum [15,30..1000] 3. rsum 3 + rsum 5 - rsum 15 where rsum n = let (k,r) = 1000 `divMod` n in rsum' 0 (1000 - r) k rsum' f l n = (n*(f + l)) `div` 2
- jacquesm 5y ago1. is the best solution. That's because it is the only solution that encodes the problem in a way that it is still obvious what is being done. 2. and 3. are incomplete without a pile of documentation to explain why they do what they do and what you'd need to do to modify them in case the inputs change.
- dan-robertson 5y agoThe first runs in linear[1] time and the last in constant time. One can write it more readably: sum_arithmetic_progression first last length = -- to compute S = first + (first+k) + (first+2k) + … + (first+length*k = last) -- write it backwards and add corresponding terms: -- 2S = (first+last) + ((first+k)+(last-k)) + … + (last+first) -- = (first+last) + … + (first+last) -- \____ length times ___________/ (first + last) * length `div` 2 -- = sum [i | i<- [1..upperBound], i%n == 0] but fast sum_multiples n upperBound = sum_arithmetic_progression n last count where (count,r) = upperBound `divMod` n last = upperBound - r subsets [] = [[]] subsets (x:xs) = [set | sub <- subsets xs, set <- [x:sub,sub]] -- given some sets [A,B,…,C] and a function count_intersection which acts like the sum of some function on the elements in the intersection of a list of sets, compute the count of their union using the inclusion–exclusion principle. inclusion_exclusion count_intersection sets = sum [count_intersection sub * (if odd (length sub) then 1 else -1) | sub <- subsets sets, sub != []] answer = inclusion_exclusion sum_multiples' [3,5] where sum_multiples' factors = -- the sum of the numbers which are multiples of all the numbers in factors is the sum of the multiples of their lowest common multiple sum_multiples (foldr lcm 1 factors) 1000 The point of project Euler is not to make you write clean or clear code but rather to make you write code that exploits the mathematical structure of the problem to find the answer with less computation.
- rfreiberger 5y agoSo I'm a mostly self trained low level programmer and found Project Euler is great but there is a level of math knowledge that left me more puzzled on the formulas than actual coding. Is this something I should focus on as someone learning to code, or the other coding puzzle sites with "linked list" type of challenges are just as good.
- dealpete 5y agoThere's no real need to know so much math for most professional programming jobs. Math problems tend to be over-represented on challenge sites because they are easy to implement.
- kadoban 5y agoNo, you shouldn't focus on this. PE is _mostly_ a math site, which if you want to learn that is great, but it's not the same as programming. What other sites are you looking at? I don't actually know that I'd recommend any puzzle sites to a new programmer. The ones I know of are for fun, not for improving your software dev skills.
- danielvaughn 5y agoA friend of mine applied to Amazon, and they told him he should do the first ~100 problems of Project Euler to prep for the interview. As someone who is not at all advanced in math, I found this to be fairly discouraging. I feel like I’m a reasonably strong programmer without advanced math knowledge, and not sure why it would be necessary for a general dev job.
- kadoban 5y agoThat sounds like pretty bad advice. Does Amazon really ask interview questions based on those? I'd be very surprised if they did. Competitive programming problems as interview requirements are bad enough (don't get me wrong, I find the problems fun, they just don't have much to do with software dev). But yeah, as a good programmer with a job at a large company, you _definitely_ don't need to do 100 PE problems, and any company asking for that (for general software dev role) has lost their mind.
- omosubi 5y agoProject Euler is why I am a programmer - i spent many nights in university doing PE problems instead of studying and nothing in class gave me the visceral excitement like doing PE
- shiado 5y agoYears back I did a couple hundred problems on this site. It's very good at making you learn about important results in basic math and algorithm complexity. It forces you to write your own library of efficient functions for factoring, etc... because you have to use them so many times and as the problems get harder anything brute force will take too long.
- jkhdigital 5y ago> It forces you to write your own library of efficient functions for factoring, etc Yes! This is when I knew I was in too deep lol
- nsa_magic 5y agoProject Euler was how I learned to program back in the days. I used to do a lot of Math but I was terrible at programming and really hated the way it was taught at school.
- kaba0 5y agoThere is a very interesting problem I’ve yet to crack (as per the sites guidelines, do not share solutions here, please): You have a triangle with equal sides. You shoot a laser at the minuscule opening at one corner, where it gets inside and bounces off the inner surface of the sides. How many angles exist from which shooting the laser, it will bounce N times and exit through the same hole it entered from? I have tried doing it in the naive way by writing a scala program that calculates reflections on the sides of the triangle and my idea was that iterating the degree in small quantities and plotting the distance of the Nth ray to the enter/exit corner would give me a visual way to count the angles we are looking for. The accuracy of doubles disallowed me from doing even the given N=11 example, so I made/reuse a rational number lib and I got the correct number for this sample. But the actual question wants N on the order of millions… I’m thinking that maybe some mathematical series could help, but haven’t tried cracking it since. But it was a great feeling writing even this easy version (I have even made a visual version with scala.js :D)
- enriquto 5y agoThis is a very beautiful geometric problem! EDIT: removed hint.
- random314 5y agoGood problem! Solution is very simple Edit : REMOVED HINT
- karmakurtisaani 5y agoA wonderful problem. I must have spent over a year thinking about this on and off before arriving to the critical insight. The funny thing with some of these problems is that you get an amazing rush on the moment you solve a problem, but afterwards just feel kinda stupid for not seeing the solution much much earlier. Years later, I was able to impress my colleagues by solving a similar problem someone posed over beers in an instant. Have fun!
- rawling 5y agoI've seen this puzzle before and not had any idea how I'd solve it. I think everyone saying that a simple solution exists has just solved it for me!
- guessmyname 5y agoI find it interesting how many people love solving problems like the ones available in Project Euler [1] and Advent of Code [2], but are opposed to solving similar problems during a technical interview at a tech company. [1] https://news.ycombinator.com/from?site=projecteuler.net https://news.ycombinator.com/from?site=projecteuler.net [2] https://news.ycombinator.com/from?site=adventofcode.com https://news.ycombinator.com/from?site=adventofcode.com
- chrisaycock 5y agoPE is untimed and no one is looking over my shoulder. Plus there's a right answer---no hidden test suite.
- guessmyname 5y ago> PE is untimed and no one is looking over my shoulder. Fair enough. I suppose many programmers suffer from anxiety during those interviews. > Plus there's a right answer---no hidden test suite. This statement makes no sense, though. Both Project Euler and LeetCode-type of problems have a right answer, in fact, LeetCode-type of problems have more than one right answer, making them even easier than Project Euler problems. Also, having a hidden test suite means nothing because the (single) test used to verify the answer for a Project Euler problem is also hidden.
- anandoza 5y agoDo you know if it's the same people, or just two significant (but possibly disjoint) populations of people?
- gigalord 5y agoI learned to code on the side from Project Euler 9 years ago. It changed my life.
- siddboots 5y agoI have big love for PE. I've learnt so much in the process of trying to solve some of these problems. In particular, number theory and data structures are two fields that I have come to love almost entirely because of this website. I did a random selection of the first 200 problems on my own about a decade ago but ran out of steam as the problems got harder. Recently, however, I introduced it at work as a way of encouraging the team I manage to work collaboratively. We have a fortnightly catch up where we talk through solutions, pick new problems (we have a script that randomly picks an easy, medium and hard problem, which has become an exciting ritual), and then we have an initial discussion about each of the new problems. It's a good way to foster group work. It's also a great way to introduce people to using version control and pull-requests in a non-scary way!
- nnoitra 5y agoDo DT problems pop-up in PE? To me it seems most are related to number theory.
- philiplu 5y agoMost PE problems are more math than data-structure based. There are plenty of number theory problems, but lots of other areas as well, especially combinatorics and probability. I’ve learned about many more niche areas, like impartial games and chromatic polynomials, via PE. But there are definitely more CS-oriented problems. I can recall problems solved by using segment trees, Aho-Corasick, simple parsing, etc. And lots and lots of dynamic programming. Also, working your way through the first 100 problems will require writing code to evaluate poker hands and solve Sudoku boards.
- dang 5y agoPast related threads: Project Euler - https://news.ycombinator.com/item?id=15893911 https://news.ycombinator.com/item?id=15893911 - Dec 2017 (163 comments) Project Euler Humble Return - https://news.ycombinator.com/item?id=10025042 https://news.ycombinator.com/item?id=10025042 - Aug 2015 (119 comments) Project Euler has been hacked - https://news.ycombinator.com/item?id=9990221 https://news.ycombinator.com/item?id=9990221 - Aug 2015 (35 comments) Project Euler's 500th problem - https://news.ycombinator.com/item?id=8977550 https://news.ycombinator.com/item?id=8977550 - Jan 2015 (56 comments) Project Euler Returns - https://news.ycombinator.com/item?id=8181773 https://news.ycombinator.com/item?id=8181773 - Aug 2014 (100 comments) Project Euler is partly back - https://news.ycombinator.com/item?id=7928107 https://news.ycombinator.com/item?id=7928107 - June 2014 (16 comments) Project Euler is offline - https://news.ycombinator.com/item?id=7896621 https://news.ycombinator.com/item?id=7896621 - June 2014 (19 comments) Project Euler - https://news.ycombinator.com/item?id=7056888 https://news.ycombinator.com/item?id=7056888 - Jan 2014 (134 comments) Project Euler - https://news.ycombinator.com/item?id=1262968 https://news.ycombinator.com/item?id=1262968 - April 2010 (20 comments) Project Euler - Fun Math and Programming Problems - https://news.ycombinator.com/item?id=86365 https://news.ycombinator.com/item?id=86365 - Dec 2007 (10 comments) I included the ones about the 2014 downtime because they're mostly general threads about PE. Other general threads: Project Euler 001 the Hard Way - https://news.ycombinator.com/item?id=22209793 https://news.ycombinator.com/item?id=22209793 - Feb 2020 (41 comments) Consider Yourself a Developer? You Should Solve the Project Euler Problems - https://news.ycombinator.com/item?id=19174947 https://news.ycombinator.com/item?id=19174947 - Feb 2019 (31 comments) Solving Project Euler problems - https://news.ycombinator.com/item?id=1062209 https://news.ycombinator.com/item?id=1062209 - Jan 2010 (27 comments)
- ajakate 5y agoFor people that love Project Euler, check out project rosalind! http://rosalind.info/about/ http://rosalind.info/about/ Conceptually similar, but the problems are focused around bioinformatics. Most lot of the problems contain some background context that teaches you a little biology/statistics as well.
- mayankkaizen 5y agoFor me it's been other way round. I mean I was actually very much interested in genetics so I encountered Rosalind. Going through Rosalind, I realized I need to learn Python and I didn't know any programming till then. So my first lessons of Python were from Rosalind! I started loving Python and programming. Then I encountered Project Euler...
- mdturnerphys 5y agoI recently got back into the Euclidia geometric puzzle app [0]. You start with compass and straightedge tools and build up the techniques to exactly construct the solution to various challenges with the minimal set of operations. [0] https://www.euclidea.xyz/ https://www.euclidea.xyz/
- arksingrad 5y agoI found this app recently, it's great. It's a nice refresher on basic geometry, and I haven't done many geometric constructions in a while. It's a really neat way of exploring geometry and discovering insight after finishing a puzzle to try and optimize it
- dahart 5y agoSee also Ancient Greek Geometry https://sciencevsmagic.net/geo/#0A1.N https://sciencevsmagic.net/geo/#0A1.N There are hidden puzzles, you can solve for larger polygons like the 17-gon.
- meken 5y agoLove PE. Back in undergrad, we kept a leaderboard amongst each other to see who could solve the most problems. I had just learned python and thought I was cool. Good times.
- dan-robertson 5y agoIn general I think there are a lot of project Euler problems (at least after the first 100) that are basically “here is some theorem/construction you might see in undergrad (or maybe early postgrad) number theory, except we don’t tell you what it is, instead we just give you a problem to which it applies.” And if you don’t know the theorem you are SOL. When I was last doing PE, that Knowledge was relatively fresh in my mind so I could know that the solution was Pell’s equation or whatever (good luck finding the wiki page if you don’t know the name…) but even then it felt a bit silly. I think the solution I was most proud of was to an older problem (they weren’t adding new ones at the time) with less than 100 solves and it basically boiled down to Gaussian elimination without much mathematical knowledge. Mostly I was proud because I got the achievement for solving one early.
- brundolf 5y agoIn my experience some of the most fun programming problems are the ones where an optimum solution is known to academia, but the participant doesn't know the optimum and has to cobble together the best suboptimal solution they can come up with on their own
- randomswede 5y agoWhen I was poking PE many many years ago, one approach I took was "make a brute-force solver, feed it small inputs, see if there is an easy way to reason myself to a closed form". This sometimes involved looking sequences up in OEIS, sometimes the closed for was obvious from the sequence, and sometimes I used differentials to find it.
- MetaWhirledPeas 5y agoRobert Martin has some cool videos on this. https://www.youtube.com/watch?v=8L05WmSXv7k https://www.youtube.com/watch?v=8L05WmSXv7k
- utopcell 5y agoA friend got me hooked on PE by pointing me to #208 many years back. Lovely problem, recommended fun time. I wonder if folks here have favorite problems they've worked on as well.
- philiplu 5y agoFor me, lots of candidates, but I'll go with #589, Poohsticks Marathon, because of my history solving it. I worked on it for a month after I'd solved about 200 problems, and got nowhere. Dropped it for 2 years, then decided after I'd solved 500 problems that I should give it another go for solution 501. I'd learned plenty of techniques in the interim, and finished it off in a couple days. What's fascinating to me about this one, though, is its difficulty level, versus what the design team thought that level would be. Those levels are set automatically based on how quickly PE members manage to solve it, and this one took 32 weeks to hit 100 solvers, for a 95% difficulty. But problems are usually scheduled in batches of 6, one per week, with an expected difficulty cadence of Medium, Easy, Medium, Easy, Medium, Hard. And #589 was expected to be an _easy_ problem! I can actually see, having solved it, why the team thought it deserved its easy slot, but, wow, did things work out differently. For a more general favorite, I really enjoy solving any of the impartial game problems. I'm not pointing out which those are - part of the fun is discovering that that's what you're looking at.
- laurentl 5y agoI love 202 for sentimental reasons (latest problem available when I picked up PE, seemed impossible at the time, felt thrilled to solve it) and 422 because I find the solution so elegant. I haven't touched PE in years but I still remember these problems and their solutions off the top of my head.
- sizzzzlerz 5y agoI solved about 270 problems several years ago, had fun doing it, mostly in python, but I reached a point where I just didn’t have the math theory chops to continue. I visit the site every now and then, try a few new problems, but without success. Some problems I can get started but seem to run into a brick wall. Others, I don’t even know how to approach the problem. All in all, however, it’s a great site to learn more about math.
- uyt 5y agoIf you're the competitive type, http://codeforces.com http://codeforces.com is also very good. You get an elo rating and they use chess titles (candidate master, master, grandmasters, etc). The lower division generally has around 20k participants per contest which mostly (but not always) happens on weekends.
- rhardih 5y agoI've enjoyed solving PE problems. I think I managed to clear about 50 of them, before loosing interest. To be honest, I think they are simply too hard for most average programmers, like myself. I only really have highschool level math skill, and when I get stuck, I don't even know what to look for or read up on. I'm simply too far removed from the level required. I do enjoy the learning aspect though, so what I feel is missing most of all, is a way to figure out what to study, in order to solve a problem, without giving away the solution.
- dennis714 5y agoThe website with problems in reverse engineering: https://challenges.re/ https://challenges.re/ Created in similar vein as PE.