I am a Software Development Engineer in Test working for the Windows Sound team. You can contact me via email: mateer at microsoft dot com
Friend key: 28904932216450_59cd9d55374be03d8167d37c8ff4196b
Another programming contest asks to solve the Josephus problem.
Bad Perl solution (83 characters... so close...)
>perl -e"@_=(1..$ARGV[0]);++$c%$ARGV[1]?$i++:splice@_,$i%=@_,1while$#_;print@_" 40 328
EDIT: got it down to 80.
>perl -e"@_=(1..shift);++$c%$ARGV[0]?$i++:splice@_,$i%=@_,1while$#_;print@_" 40 328
EDIT2: 78 dropping the parentheses.
>perl -e"@_=1..shift;++$c%$ARGV[0]?$i++:splice@_,$i%=@_,1while$#_;print@_" 40 328
EDIT3: 66, shamelessly cannibalizing others' ideas from the contest (though I refuse to use "say")
>perl -e"$k=pop;@_=1..pop;@_=grep{++$i%$k}@_ while$#_;print@_" 40 328
I found this programming contest interesting: here's what I've got.
perl -e "($a,$b)=@ARGV;map{$c+=$_*$b}grep{$a&$_}map{1<<$_}(0..log($a)/log 2);print$c" 7 19
I'm calling this a one-liner because the part between the quotes is less than 80 characters (75, to be exact.) The full command line goes over :-(
Requires the inputs to be positive whole numbers.
Perfect example of Bad Perl. Exercise: rewrite in Good Perl.
EDIT: got the whole thing down to 80 characters (with single-digit multiplicands.)
perl -e "($a,$b)=@ARGV;map{$c+=$b<<$_ if$a>>$_&1}(0..log($a)/log 2);print$c" 8 7