Code Golf: Beehive

Perl, 99 characters @P=map{$/.substr$”.’__/ \\’x99,$_,$W||=1+3*pop}0,(3,6)x pop; chop$P[0-$W%2];print” __”x($W/6),@P Last edit: Saved one character replacing -($W%2) with 0-$W%2 (thanks A. Rex) Explanation: For width W and height H, the output is 2+2 * H lines long and 3 * W+1 characters wide, with a lot of repetition in the middle of the output. For convenience, we … Read more

Code Golf: Leibniz formula for Pi

J, 14 chars 4*-/%>:+:i.1e6 Explanation 1e6 is number 1 followed by 6 zeroes (1000000). i.y generates the first y non negative numbers. +: is a function that doubles each element in the list argument. >: is a function that increments by one each element in the list argument. So, the expression >:+:i.1e6 generates the first … Read more

Code Golf – Banner Generation

J, 133 135 79 83 84 88 characters (utf-8 encoding) ;/5 3$”1(‘ ‘,.s){~”1#:3 u:(ucp’翇篭篯礧歮禧禤祯寭璗牯宭䤧彭忭筯篤筿殭秏璒孯孪寿咕寏犧’){~0>.64-~a.i.s=: Usage: ;/5 3$”1(‘ ‘,.s){~”1#:3 u:(ucp’翇篭篯礧歮禧禤祯寭璗牯宭䤧彭忭筯篤筿殭秏璒孯孪寿咕寏犧’){~0>.64-~a.i.s=:’ABCDEFGHIJKLMNOPQRSTUVWXYZ !’ ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ │AAA│BBB│CCC│DD │EEE│FFF│GGG│H H│III│JJJ│K K│L │M M│N N│OOO│PPP│QQQ│RR │SSS│TTT│U U│V V│W W│X X│Y Y│ZZZ│ │!!!│ │A A│B B│C │D D│E │F │G │H H│ I │ J│K K│L │MMM│NNN│O O│P P│Q Q│R R│S │ T … Read more

Code Golf: Spider webs

Perl, 164 chars 195 184 171 167 164 print@o=((map{$z=_ x($x=1+$N-$_);$”x$x.”https://stackoverflow.com/”x$_.”\\$z|$z/”.’\ ‘x$_.$/}0..($N=<>)), “_/”x++$N.” “.’\_’x$N.$/); y’/\\’\/’,@o||y#_# #,$t++||y#_ # _#,print while$_=pop@o First statement prints out the top half of the spider web. Second statement uses transliteration operations to create a reflection of the top half. This next one weighs in closer to 314 chars (of productive code), but … Read more

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: 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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)