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

Evaluating a string of simple mathematical expressions [closed]

Assembler 427 bytes Obfuscated, assembled with the excellent A86 into a .com executable: dd 0db9b1f89h, 081bee3h, 0e8af789h, 0d9080080h, 0bdac7674h, 013b40286h dd 07400463ah, 0ccfe4508h, 08ce9f675h, 02fc8000h, 013b0057eh, 0feaac42ah dd 0bedf75c9h, 0ba680081h, 04de801h, 04874f73bh, 04474103ch, 0e8e8b60fh dd 08e8a003fh, 0e880290h, 0de0153h, 08b57e6ebh, 0d902a93eh, 046d891dh dd 08906c783h, 05f02a93eh, 03cffcee8h, 057197510h, 02a93e8bh, 08b06ef83h dd 05d9046dh, 02a93e89h, 03bc9d95fh, 0ac0174f7h, 074f73bc3h, 0f3cac24h … 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)