Code Golf: Seven Segments

Perl, 134 characters All linebreaks may be removed. @s=unpack”C*”,~”P\xdbLI\xc3a`[\@AB\xe0t\xc8df”; $_=<>;for$s(6,3,0){print map$s[hex$&]&1<<$_+$s?$_%2?”_”:”|”:” “, 0..2while/./g;print$/} Explanation @s stores the bits for each segment. The entries are in order from 0 to F (thanks to hex()) and the bits map to segments in this order: 6 7 x 3 4 5 0 1 2 with 0 being the … Read more

Code Golf: XOR Encryption

Repent, 13 7 chars (No file support), 14 char (With file support) Repent is an esoteric stack-based toy language of my own, with inspiration from J, APL, Golfscript and Python. Here is a short solution. I will explain it, but is very late and this is doing my head in, so I’ll explain it and … Read more

Code golf: the Mandelbrot set

There was a perl solution already some years ago posted in perlmonks, it reads: #!/usr/bin/perl $r=25; $c=80; $xr=6;$yr=3;$xc=-0.5;$dw=$z=-4/ 100;local$”;while($q=$dr=rand() /7){$w+=$dw;$_=join$/,map{$Y=$_* $yr/$r; join”” ,map{$ x=$_*$ xr/$c;($ x,$y)= ($xc+$x *cos($ w)-$Y* sin$w,$yc+ $x*sin ($w)+$Y*cos $w);$ e=-1;$ a=$b=0 ;($a,$b) =($u-$v+$x,2*$a* $b+$y) while( $ u=$a*$ a)+($v=$b*$b)<4.5 &&++$e <15;if (($e>$ q&&$e< 15)||($e==$q and rand() <$dr)) {$q=$e;($d0,$d1) =($x,$ y); } chr(+( … Read more

Code Golf: Morris Sequence

GolfScript – 41 (extra credit: 40) 1{.p`n+0:c:P;{:|P=c{c`P|:P!}if):c;}%~1}do {~.p`n+0:c:P;{:|P=c{c`P|:P!}if):c;}%1}do What? The procedure for getting the next number in the sequence: Convert the current number to a string, append a newline and loop over the characters. For each digit, if the previous digit P is the same, increment the counter c. Otherwise, add c and P to … Read more