Last active
August 29, 2015 13:55
-
-
Save l0gicpath/8733723 to your computer and use it in GitHub Desktop.
One liner ruby solution for project euler problem #2 because ruby is hardcore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(l ,ss = 4000000, proc {|p, n, s| p >= l || n >= l ? s : n.even?? ss[n, n + p, s + n] : ss[n, n + p, s] })[1][1, 2, 0] |
thanks for the explanation, i think the proc part and the multi assignment will help me alot with my scripts,
these are so little bits i miss while learning the language.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A highly-unrecommended way of doing ruby for a living:
Just a fun one-line solution to project euler problem #2 using parallel assignments and nested ternary operators(?:) with anonymous recursion in procs.
Preliminaries
The awkward syntax that seems to magically generate an array is a not so common parallel assignment technique that's not idiomatic.
Since we needed a reference to ourselves inside the proc for recursion and we needed the limit to be variable this prompted the notion described above
This gave us a limit value and a Proc object that are bound to scoped variables and are accessible from within our proc