4 ms·
And starting out in programming, for the love of code, learn how to do these. They set your brain in motion. And ProjectEuler.net
by knob 13y ago
And starting out in programming, for the love of code, learn how to do these.
They set your brain in motion.
And ProjectEuler.net
- miloshadzic 13y agoProject Euler, while great, is more about neat math tricks than actual programming.
- Apocryphon 13y agoWhat about TopCoder?
- miloshadzic 13y agoI've never participated much but people say that if you get some practice there, algorithm heavy interviews go a lot smoother.
- RyanMcGreal 13y agoIt's about solving logical problems and expressing those solutions using code. Definitely useful.
- miloshadzic 13y agoNever said that it isn't useful.
- VLM 13y agoAgreed that there's an intense math flavor, but the "right" way to do lower level PE problems mathematically can be more fun to play with programming ideas. Problem 1 is basically a fizz buzz and its funny to try alternative algorithms. So, yeah, brute force its pretty obviously a for loop with a subtotal, two mod tests connected by an or, you get the idea. And that is the first way to do it in a new language. So you wanna try recursion? I feel fuzzy at this time but something like you call recurse(1000) and it calls recurse(999) and so on until it hits 0 and stops. Now from memory my weird design was the return was returning the (the returned subtotal from calling recurse(x-1)) + x when x is a mult of 3 and not a mult of 5 + x when x is a mult of 5 and not a mult of 3 + x when x is a mult of 15 (15 is 3 and 5 at the same time)) Yeah or something like that. (edited what the heck was I thinking? I'll leave this as unedited, but thats not right. This is a good fizz buzz example of give them the question, a wrong answer, and ask them to debug it.) Another one to demonstrate your ability at screwing around with arrays is simply make an array size 1000 all zeroed out and a for loop to run thru all indexes of that array (now try not to fall off either edge) and if the array index is a mult of 3 or a mult of 5 then set that array value to the array index. Finally add together all the values of the array. Hmm so you've got a minor parallel processing cluster on hand and everyone runs some language you're unfamiliar with and has access to a shared NFS dir so all 100 of your hosts run the worlds dumbest program that checks to see if 1000 files exist, if not, it picks a psuedo-random number between 0 and 1000, checks to see if its already been calculated, if not, it decides if that number is a mult of 3 or 5 and if it is, then a filename "random-number" appears using dd if=/dev/urandom of="random-number" and you copy 1K blocks equal to the number of blocks in the random number (so file 14.crazy is zero bytes long but 15.crazy is precisely 15K in length) then given 100 workers randomly selecting a random number less than 1000 you have to run way more than 10 rounds but eventually all the shell scripts simultaneously terminate on all the worker nodes because ls | wc -l returned 1000 aka all 1000 results have been calculated. Then you run cat * > result and du -k result to see how many K are used which is the sum of all the mults of 3 and 5 between 0 and 1000... I did this to torture test a small cluster and its NFS server and its network and disk IO a long while back. I remember it took more rounds than you'd guess to test all 1000 digits and of course if varies, unless your psuedo-random number generator is screwed up. Or you could intentionally use a screwed up RNG to see if its any good. Also I did my run using M not K although a motivated lunatic would use G, I suppose, to really torture a NAS. Isn't this a diabolically insane and funny way to solve the problem? On a simpler level, or a differently crazy level, you can do all your math in octal, just because. It won't really change anything but it looks entertaining. And why not write your own octal-dec conversion routine, to print out the result, just because? The point is not to do it the fastest or most obvious way but to screw around with odd ideas, not the same old boring fizzbuzz. Graphical is hilarious instead of using a boring old array. So what happens if you use a PNG graphics image to store your table of multiples? So 15 is 15 black pixels? This is an interesting way to test your ability to squirt out and in pixels. Also does your PNG library interface like 1e6x1 graphics images and how scalable is it when you access the same graphics image 1e3 times does it scale? There is a tiny problem that someone who thinks this is hilarious might use hilarious designs in production code.