Project Euler - Learning to code efficiently

General chat, humour, riddles, logic/lateral/word puzzles...
Post Reply
Posts: 4
Joined: Mon Oct 22, 2018 7:24 pm

Project Euler - Learning to code efficiently

Post by mafridi »


I was advised that this website can help me learn to code better so that I may perform better in solving "leet" code type examples during interviews. I've been out of school for a long time and don't remember much math if any and my style of coding is pretty much brute force where I'm basically analyzing each element one at a time. I read somewhere about how I need to write code following the log(n) method. Will the questions help me learn how to code more efficiently following the log(n) principles? Any good resource material on what exactly log(n) is?


User avatar
Posts: 160
Joined: Mon Feb 19, 2018 3:05 am
Location: Northern California, USA

Re: Project Euler - Learning to code efficiently

Post by kenbrooker » ... c01240266b

Something to ponder until a(n official) Project Euler reply is posted and...
Something mOre... ... d575e7eec4

((EDIT in parenthesis))
"Good Judgment comes from Experience;
Experience comes from Bad Judgment

User avatar
Posts: 37
Joined: Tue Oct 12, 2010 11:25 pm

Re: Project Euler - Learning to code efficiently

Post by timday »

I would not say that Project Euler (PE) will teach you to code efficiently; more that you will need to learn to code efficiently to solve Project Euler problems. PE itself doesn't actually give you much to show you what efficient coding looks like (apart from some hints about prime sieving in PDFs accompanying earlier problems, I seem to recall). Just to be clear: by "efficient coding" I do indeed generally mean finding or devising a suitable algorithm so that a problem is soluble in, say, O(log n) time rather than O(n), or in O(n log n) rather than O(n^2).

I came to PE from an applied math/physics background and only had minimal previous exposure to formal treatment of algorithms and big-O. PE has been quite a revelation about the power of these ideas... it still astonishes me every time I use techniques like Dynamic Programming or Modular Matrix Exponentiation to crush something which might take years or even centuries to solve by a naive, bruteforce approach down to a virtually instantaneous runtime. On other forums, you occasionally come across people who are new to PE thinking they can somehow achieve the necessary runtime improvements by optimisation tricks like inline assembly code or persuading their compiler to vectorize using SSE/AVX instructions and so on... but such approaches will get you nowhere; it is algorithmic optimization which is needed).

Bear in mind "coding" alone is not really enough; you'll need to know/learn a fair amount of mathematics too (especially Number Theory, but also combinatorics) to get anywhere.

Post Reply