Tuesday, December 16, 2014

7L7W Week 2: Io Day 2 round 2>Finding my feet

I might be getting the hang of this.
recursiveFibonacci := method(n, 
if(n == 0, 
0,
if(n == 1,
1,
recursiveFibonacci(n - 1) + recursiveFibonacci(n - 2)
)
)
)

loopedFibonacci := method(n,
nSub1 := 0;
currentN := 1;
for(i, 1, n, 
currentN = currentN + nSub1;
nSub1 = if(i == 1, 0, currentN - nSub1))
currentN
)

Number recursiveFibonacci := method( 
if(call target == 0, 
0,
if(call target == 1,
1,
((call target - 1) recursiveFibonacci) + ((call target - 2) recursiveFibonacci)
)
)
)

Number loopedFibonacci := method(
nSub1 := 0;
currentN := 1;
for(i, 1, call target, 
currentN = currentN + nSub1;
nSub1 = if(i == 1, 0, currentN - nSub1))
currentN
)

Do I get double bonus points? Hm, no, probably not. It's not exactly a stretch to move from a parameter to calling the message target is it? These seem pretty self explanatory to me (Fib numbers aren't a new science after all) but I can't help feeling like it could be done better.

Division by zero? Sure, let's break basic math... >.<

Number divide := Number getSlot("/")
Number / = method(n,
if(n == 0,
0,
call target divide(n)
)
)

I did cheat a bit. StackOverflow pointed me in the right direction.

And it's bedtime now. I'll get the rest of the self study done tomorrow (with a grain of salt). So progress has definitely slowed in my 7(3!) week journey. However it's also getting more interesting so assuming there's a correlation between difficulty and interest... yeah.
Then again it may be due to my lack of cohesive sleep schedule (have I mentioned lately that ridiculous software installs suck?) which sadly will only get worse. There's another install this weekend (end of year compliance, yippee) then a family vacation (meaning all my wife's immediate family, which is neither vacation nor particularly conducive to any kind of study) right after Christmas... which is itself a disruption. Then of course there's the end of the year, which is another all-nighter (I've really got to streamline the end of month process)... I probably could have started this at a better time of year. Then again interrupted progress is better than sitting around playing video games or trying to study something that has gotten stale and boring. Maybe I'll take a break from 7L7W after week 2 and get back to some C#. Play the flipflop game with them. Or maybe not. Since I'm playing dablling all over the place maybe I'll crack that LISP book back open. I'm not sure the original  rationale for shelving it still holds. Ah, the possibilities.

Also, the song that's been driving me today like Paul Revere on speed. That's good stuff there. I must recant my uninformed, juvenile opinions of rap. I clearly had an insufficient sample size to base opinion on.

No comments: