During one of those lapses in motivation this afternoon at work I had a go at putting together a Powershell script to list a sequence of Fibonacci numbers (in true geek style, did I do it because I needed to? No. Did I do it because I wanted to see if I could? Yes). Disappointingly I got it done pretty swiftly which meant that I had to get back to doing some real work, but being able to make it a one-liner was quite satisfying:
$1=0;$2=1;$3=$1+$2;do{$3;$1=$2;$2=$3;$3=$1+$2} while ($3 -lt 10000000)
The code above uses 0 & 1 as the starting numbers (just change the values assigned to $1 and $2 to use others) and keeps going until the result is greater than 10000000. If I get bored next week (ha, ha! as if....) I might use the speech capability I mentioned here to get the script to read out the numbers for me, interspersed with profanities....
No comments:
Post a Comment