Project Euler in Haskell
I recently solved a bunch of Project Euler questions in Haskell.
I probably won't be 'solving' very many more.
Read on to find out why.
I recently solve 75+ Project Euler problems in Haskell, but nobody cares. I actually solved a few more than that using other methods (list look ups, other languages, and/or with lots of help from outside sources -- i.e. I cheated), but I'm not counting those, only the ones I solved on my own in using Haskell. But nobody cares.
Of course, nobody cares what I write on this web page and I'm not crying about that, so this page isn't about the lack of awareness in the general viewing public as to my stupendous achievement (i.e. solving 75+ Project Euler problems in Haskell - just in case we weren't all clear on that).
And then, of course, when I say nobody cares, what I really mean is that the two fine folks (fine folks wearing stylish fedoras full of fancy feathers) that I recently interviewed with-to-for for a programming job, didn't seem all that much impressed by the accomplishment. And here's the reason (I believe) that they didn't care:
Person 1: thought I was too advanced for the job
Person 2: thought I wasn't advanced enough
Sort of ironic really, but good to keep in mind.
Of course, that's probably not clear, so let me spell it out. Project Euler is of no importance to a techie (Star Trek or otherwise), those folks only only care about your tech, skills, knowledge, and/or ability to answer Science Fiction Trivia.
And by the same token, Project Euler is of no importance to a high grade math flunky (call them pHd's if you like), because solving a few problems is not a replacement for having spent the last ten years solving problems ten times as complex.
So, anyway, bitch, moan, here's what I learned from my time with Project Euler (learn from my mistakes so you don't have to, whatever that means):
If you're going to walk that walk, these sites are your friends; but then, seriously, if you don't already know about these sites or you don't find them intrinsically interesting, Project Euler might just be a mistake for you in the long run (waste of time and all that, oh, and links disabled for... reasons see bottom of page):
The Wikipedia of the Math World
A Cloud Based Number Theory Calculator
Oh, and if you're not sure what that last means, there's still time to back out and leave Project Euler well enough alone...
OEIS (the organization)
Numbers! Numbers, everywhere!
As to Haskell, Haskell was fun, but if I was to listify a short list of the things I learned from 'playing' with the language in a list like manner, those things listed in no particular order would be:
Monads: are an overly complex way of saying Haskell is written by and for people who care about Category Theory. If you don't know what either a Monad or Category Theory is (and don't want to spend your life learning), likely you will just be a tourist, passing through the land of Haskell.
Do: Haskell is not about the do notation, the do notation is a way of slipping procedural programming into Haskell, so if that's how you're solving Haskell problems, for the most (always there will be exceptions), one is not 'doing' Haskell.
While: I learned to love while loops in Haskell. No, Haskell doesn't have while loops, but if you want to export what you learned in Haskell to an imperative programming language, you'll most likely take 'while' with you. It's the lazy man's way to program lazily, if you catch my drift.
Lists: Haskell is modern day LISP (or so, I will claim). And LISP stands for List Processing System (or something like that). Haskell is all about lists. Haskell is lists. Learn them, love them, the first fifty problems in Project Euler are a breeze, after one understands little more than how to make a list in Haskell. Seriously, play with Haskell just so you learn how to make list comprehensions in other languages, it's that good.
Filters: I will define a filter (for ease of comprehension) as any function that returns True or False. I don't think I ever made a function that returned True or False before I met Senior Haskell; and now that I've seen the light, I'm using them all the time. Guess what? My code is better for it.
Fold, Map, Reduce: are all cut from the same cloth, and without going into the specifics, I would say that the key here is to keep your eye on the ball, which probably isn't very clear; but then, I'm hardly going to explain what Fold, Map, and Reduce do in any sort of meaningful way, so suffice it to say, that after one has learned Fold (and learned it but good), one will have learned the art of only tracking what is important and letting go of the rest. A function that does only one thing to a lot of things (adds them together, finds the highest, computes a moving average), yeah, that's where the Fold Class of Functions (once again, whatever that means) excels.
And that might not sound like much for three months of effort (and we're talking full time job level effort here), but the
while function alone is so amazingly powerful. It's almost embarrassing how little I used it before...
And if I invented a fictional command When, I might be able to explain the virtue of Lazy Programming in only a few words. Functional Programming is all about doing things only While you need them and only When you need them.
Anyhow, I doubt I'll ever come back and add anything to that list, but one never knows, and it's there if I feel the compulsion.
After my interviews, after Project Euler, and after Haskell, I decided I needed to focus on a Tech Stack and at this point, for me, that tech stack is Python, Python, and Python. And since Project Euler worked so good for me in learning Haskell, I decided I'd give RosaLind a shot, but I gave it up after a day. Oh, it was a glorious day, but at the end, I figured I was probably better off working on my own custom code than answering yet another bank of frustrating questions.
I like Graph Theory, I was solving the Graph Theory questions, and was fairly far into them; and as such is my want, rather than programming everything from the ground up (reinventing the wheel as it were), I was using a library: networkx, to be exact.
Anyhow, long story short, networkx has four different functions that kick back the number of connected components in a graph, and between the four functions I got two different answers... none of which, of course, matched the answer RosaLind was looking for. Well, RosaLind was NOT telling me why I was wrong, how I was wrong, or even what answer it was expecting (and one of the big selling points of Rosalind is that they use different data sets for each 'attempt', which is all the more reason to provide the answer for any failed 'attempts', as it has no bearing on the next 'attempt'). Anyway, if the networkx functions couldn't agree on the answer, I lost heart in trying to guess what RosaLind's interpretation of the answer might be. Math is like that sometimes.
And, now, I'm done with RosaLind... and Project Euler... and probably even Haskell, that is, unless you want to give me a job programming in same.
Of course, I'll probably stall out on my own projects (and have nothing to rant about to fill the day, hey, it could happen); and I've already sort of decided that one day I'll go back to Project Euler (perhaps make it a monthly thing). But when I do, I have every intention of 'cheating', getting all the 'help' I can beg, borrow, or steal, and not making it a brain teaser exercise, but rather a coding exercise: knowing this, can I program that, or at the very least, follow along in someone else's footsteps.
So, yeah, I solved 75+ Project Euler problems the hard way (on my own) using Haskell as my programming language of choice. Sometime in the future, I'll do a hundred more in Python, 'cheating' every step of the way, because I am never going to get that job as a math whiz, Number Theory pHd, but I might get one as their assistant, following their instructions, coding as they tell me to do, and Project Euler might just help with that.
Did I say Python?
Let's not be hasty.
I've heard good things about Scala.
And then, there's Clojure.
Let's not forget about Clojure...
now, there's a language for the true connoisseur...
© copyright 2014 Brett Paufler
The reasons for non-active links are simple enough. In many ways, I'm a control freak... or so I have been told. But even I know that tells nothing. So, want another useless example? I don't have active external links for (about) the same reason I just changed the © symbol above to
© down in the code. Which still isn't clear, can't possibly be clear, and won't even be clear to me in five weeks, let alone five years. So, let's go back to the start; and once again claim, the primary reason for no external links is control. I want to know what's going on with my site, keep the quality as high as possible (but hey, let's not get carried away here), and most importantly, not let anyone else hijack my domain name or any of the pages therein. And that last is where the lack of external links comes in. One of the easiest ways to hijack a site it to add extraneous external links. And one of the easiest ways to make extraneous links stand out is by having their signature (their look and feel) contrast significantly from the desired links. So, um, if that's not clear, limit the links (to basically none) and it's pretty darn simple to differentiate the good link (as in mostly non-existent) from the bad (pretty much any outward facing link). And in the end, it really is that simple.
Or if you want to look at it in a more poetic light, I'm a hermit that's taken to singing loudly at night and who takes a perverse sort of joy in knowing my neighbours can hear me belt another one out, but I'll be damned if I'm going to listen to their new fangled music, 'cause, you know, it's not what I call rock and roll...