Last active
August 29, 2015 13:59
-
-
Save jeremyheiler/10572988 to your computer and use it in GitHub Desktop.
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
: fib ( a b -- x y ) [ + ] keep swap ; | |
! My goal was to implement this with produce. | |
1 1 | |
[ dup 4000000 < ] [ fib dup ] produce | |
2nip ! Remove the workspace | |
dup length 1 - swap remove-nth ! Remove the extra value | |
[ dup odd? [ drop 0 ] when ] | |
map-sum |
Also, head-slice*
would be slightly more efficient compared to head*
in this case, since it's modifying the virtual sequence rather than outputting a new sequence, but it won't realistically make a difference for this problem.
Thanks! I like how simple it is to replace logical sections of code with different words. After doing these two Euler problems, and you suggesting fixes that would be obvious to me in, say, Clojure, suggests that I am thinking too deeply about the stack. Needless to say, Factor is really messing with my brain, so that's good.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looking good! Sticking with your usage of
produce
, there are a few built-in words that can clean things up a bit:...can be replaced with:
And:
...can be replaced with: