Code Golf: Playing Cubes

Perl 157 characters This entry was inspired by gnibbler’s Ruby entry, including the part about embedding the cube in the code. Also thanks to Kinopiko for schooling me on the 4 arg version of substr. @O=($/.$”x99)x99;map{for$n(0..$_-1,$_..-1){map{substr$O[50-2*$n+$_],$W+4/$_,6, (_,”__” ,”/__ /|”, “| | |”, “|___”https://stackoverflow.com/”)[$_]}1..4}$W+=4}@ARGV;print grep/\S/,@O Explanation: Line 1: Choose where cubes go Lines 2-5: Put cubes … Read more

Code Golf: Conway’s Game of Life

Mathematica – 179 163 154 151 chars a = {2, 2, 2}; s = Export[“out.txt”, CellularAutomaton[{224, {2, {a, {2, 1, 2}, a}}, {1,1}}, (ReadList[#1, Byte, RecordLists → 2>1] – 46)/ 42, #2]〚#2〛 /. {0 → “.”, 1 → “X”}, “Table”] & Spaces added for readability Invoke with s[“c:\life.txt”, 100] Animation: You can also get a … Read more

Code Golf: Playing Tetris

GolfScript – 181 characters Newlines are not necessary. Output is in standard output, although some errors are present in stderr. \10 should be replaced by the corresponding ASCII character for the program to be 181 characters. {):X!-{2B{” #”=}%X” “:f*+-1%}%:P;:>.{\!:F;>P{\(@{3&\(@.2$&F|:F;|}%\+}%\+F![f]P+:P ;}do;{“= “&},.,7^.R+:R;[>0=”#”/f*]*\+}0″R@1(XBc_””~\10″{base}:B/3/~4*”nIOZTLSJR ” “;:”*~;n%)n*~ 10R*+n* Sample I/O: $ cat inp [ ] [ ] [ ] … Read more

Code Golf: Piano

Perl, 133 (129) chars Perl, 167 160 156 147 142 133 D’oh! 147 144 137 134 133 chars $_=shift;die grep{5>$n?y/*/#/:y/#*/ |/;$n++-8||y/ /_/} @Q=(substr((“*# #”.(“*# #*# | #”)x2)x9, 4*/#/+(7&ord)*5,1+/#/+5*pop).$/)x9 Here’s a 129 char solution, borrowing several ideas from molf’s Ruby solution: ($_,$c)=@ARGV;$j=($k=/#/)+ord; for$n(0..8){print$/,substr+(join”,map{8-$n?5>$n&&$_%7%4?”### ” :” | “:”_|___”}$j..$j+$c),!$k,-3} and with help from the Acme::AsciiArtinator: sub init_piano{$S=$”;$H=’#’; ( … Read more

Code Golf – π day

C: 131 chars (Based on the C++ solution by Joey) main(i,j,c,n){for(scanf(“%d”,&n),c=0,i|=-n;i<n;puts(“”),i+=2)for(j=-n;++j<n;putchar(i*i+j*j<n*n?c++,42:32));printf(“%g”,2.*c/n/n);} (Change the i|=-n to i-=n to remove the support of odd number cases. This merely reduces char count to 130.) As a circle: main(i,j, c,n){for(scanf( “%d”,&n),c=0,i=1| -n;i<n;puts(“”),i+= 0x2)for(j=-n;++j<n; putchar(i*i+j*j<n*n ?c++,0x02a:0x020)); printf(“%g”,2.*c/ n/n);3.1415926; 5358979;}

Code Golf: Lasers

Perl, 166 160 characters Perl, 251 248 246 222 214 208 203 201 193 190 180 176 173 170 166 –> 160 chars. Solution had 166 strokes when this contest ended, but A. Rex has found a couple ways to shave off 6 more characters: s!.!$t{$s++}=$&!ge,$s=$r+=99for<>;%d=’>.^1<2v3’=~/./g;($r)=grep$d|=$d{$t{$_}},%t; {$_=$t{$r+=(1,-99,-1,99)[$d^=3*/\\/+m</>]};/[\/\\ ]/&&redo}die/x/?true:false,$/ The first line loads the input into … Read more

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