Skip to main content
added 508 characters in body; edited body
Source Link
Timwi
  • 13k
  • 3
  • 46
  • 66

Perl, 110 characters

$p=144;$p+=(1,-17,-1,17)[($d+=($f[$p]^=2)+1)%4]for 1..<>;$f[$p]=1;print$_%17?'':$/,qw(_ @ #)[$f[$_]]for 0..288 

Number is read from the first line of STDIN. Rest of input is ignored.

Slightly more readable:

$p=144; $p += (1,-17,-1,17)[($d+=($f[$p]^=2)+1) % 4] for 1..<>; $f[$p]=1; print $_%17 ? '' : $/, qw(_ @ #)[$f[$_]] for 0..288 

Edits

  • (112 → 111) No need to update $d with the modulo-4 value.

  • (111 → 110) Can now inline the $d increment

Addendum (109 characters)

We can have it one character shorter if you’re happy to have the special case of N=0 fail (it doesn’t output the @ character for the ant). All other inputs work correctly:

$p+=(1,-17,-1,17)[($d+=($f{$p+0}^=2)+1)%4]for 1..<>;$f{$p}=1;print$_%17-9?'':$/,qw(_ @ #)[$f{$_}]for-144..144 

The differences are that we now use %f instead of @f so we can use negative indices, and we iterate from -144..144 instead of 0..288. It saves having to initialise $p.

Perl, 110 characters

$p=144;$p+=(1,-17,-1,17)[($d+=($f[$p]^=2)+1)%4]for 1..<>;$f[$p]=1;print$_%17?'':$/,qw(_ @ #)[$f[$_]]for 0..288 

Number is read from the first line of STDIN. Rest of input is ignored.

Slightly more readable:

$p=144; $p += (1,-17,-1,17)[($d+=($f[$p]^=2)+1) % 4] for 1..<>; $f[$p]=1; print $_%17 ? '' : $/, qw(_ @ #)[$f[$_]] for 0..288 

Edits

  • (112 → 111) No need to update $d with the modulo-4 value.

  • (111 → 110) Can now inline the $d increment

Perl, 110 characters

$p=144;$p+=(1,-17,-1,17)[($d+=($f[$p]^=2)+1)%4]for 1..<>;$f[$p]=1;print$_%17?'':$/,qw(_ @ #)[$f[$_]]for 0..288 

Number is read from the first line of STDIN. Rest of input is ignored.

Slightly more readable:

$p=144; $p += (1,-17,-1,17)[($d+=($f[$p]^=2)+1) % 4] for 1..<>; $f[$p]=1; print $_%17 ? '' : $/, qw(_ @ #)[$f[$_]] for 0..288 

Edits

  • (112 → 111) No need to update $d with the modulo-4 value.

  • (111 → 110) Can now inline the $d increment

Addendum (109 characters)

We can have it one character shorter if you’re happy to have the special case of N=0 fail (it doesn’t output the @ character for the ant). All other inputs work correctly:

$p+=(1,-17,-1,17)[($d+=($f{$p+0}^=2)+1)%4]for 1..<>;$f{$p}=1;print$_%17-9?'':$/,qw(_ @ #)[$f{$_}]for-144..144 

The differences are that we now use %f instead of @f so we can use negative indices, and we iterate from -144..144 instead of 0..288. It saves having to initialise $p.

added 78 characters in body; added 56 characters in body; added 2 characters in body
Source Link
Timwi
  • 13k
  • 3
  • 46
  • 66

Perl, 112110 characters

$p=144;$d+=($f[$p]^=2)+1,$p+=$p=144;$p+=(1,-17,-1,17)[$d%=4]for[($d+=($f[$p]^=2)+1)%4]for 1..<>;$f[$p]=1;print$_%17?'':$/,qw(_ @ #)[$f[$_]]for 0..288 

Number is read from the first line of STDIN. Rest of input is ignored.

Slightly more readable:

$p=144; $d+=($f[$p]^=2)+1,$p $p+=+= (1,-17,-1,17)[$d%=4][($d+=($f[$p]^=2)+1) % 4] for 1..<>; $f[$p]=1; print $_%17 ? '' : $/, qw(_ @ #)[$f[$_]] for 0..288 

Edits

  • (112 → 111) No need to update $d with the modulo-4 value.

  • (111 → 110) Can now inline the $d increment

Perl, 112 characters

$p=144;$d+=($f[$p]^=2)+1,$p+=(1,-17,-1,17)[$d%=4]for 1..<>;$f[$p]=1;print$_%17?'':$/,qw(_ @ #)[$f[$_]]for 0..288 

Number is read from the first line of STDIN. Rest of input is ignored.

Slightly more readable:

$p=144; $d+=($f[$p]^=2)+1, $p+=(1,-17,-1,17)[$d%=4] for 1..<>; $f[$p]=1; print $_%17 ? '' : $/, qw(_ @ #)[$f[$_]] for 0..288 

Perl, 110 characters

$p=144;$p+=(1,-17,-1,17)[($d+=($f[$p]^=2)+1)%4]for 1..<>;$f[$p]=1;print$_%17?'':$/,qw(_ @ #)[$f[$_]]for 0..288 

Number is read from the first line of STDIN. Rest of input is ignored.

Slightly more readable:

$p=144; $p += (1,-17,-1,17)[($d+=($f[$p]^=2)+1) % 4] for 1..<>; $f[$p]=1; print $_%17 ? '' : $/, qw(_ @ #)[$f[$_]] for 0..288 

Edits

  • (112 → 111) No need to update $d with the modulo-4 value.

  • (111 → 110) Can now inline the $d increment

added 178 characters in body
Source Link
Timwi
  • 13k
  • 3
  • 46
  • 66

Perl, 112 characters

$p=144;$d+=($f[$p]^=2)+1,$p+=(1,-17,-1,17)[$d%=4]for 1..<>;$f[$p]=1;print$_%17?'':$/,qw(_ @ #)[$f[$_]]for 0..288 

Number is read from the first line of STDIN. Rest of input is ignored.

Slightly more readable:

$p=144; $d+=($f[$p]^=2)+1, $p+=(1,-17,-1,17)[$d%=4] for 1..<>; $f[$p]=1; print $_%17 ? '' : $/, qw(_ @ #)[$f[$_]] for 0..288 

Perl, 112 characters

$p=144;$d+=($f[$p]^=2)+1,$p+=(1,-17,-1,17)[$d%=4]for 1..<>;$f[$p]=1;print$_%17?'':$/,qw(_ @ #)[$f[$_]]for 0..288 

Number is read from the first line of STDIN. Rest of input is ignored.

Perl, 112 characters

$p=144;$d+=($f[$p]^=2)+1,$p+=(1,-17,-1,17)[$d%=4]for 1..<>;$f[$p]=1;print$_%17?'':$/,qw(_ @ #)[$f[$_]]for 0..288 

Number is read from the first line of STDIN. Rest of input is ignored.

Slightly more readable:

$p=144; $d+=($f[$p]^=2)+1, $p+=(1,-17,-1,17)[$d%=4] for 1..<>; $f[$p]=1; print $_%17 ? '' : $/, qw(_ @ #)[$f[$_]] for 0..288 
Source Link
Timwi
  • 13k
  • 3
  • 46
  • 66
Loading