Skip to main content
2 of 5
-2 bytes + explanation
Jo King
  • 48.1k
  • 6
  • 131
  • 187

Perl 6, 46 bytes

{$!=0;(($!-=.[$!]=-.[$!])%=$_)xx 2**$_;!.[$!]} 

Try it online!

Represents halt by 0 and returns true if the machine halts. This repeats the logic 2**(length n) times, where if the pointer ends up on the halt cell, it stays there, otherwise it will be on a non-halt cell. This works because there are only 2**n possible states (ignoring halt cells) for the Foo machine to be in, since each non-halt cell has only two states.

Explanation:

{ } # Anonymous code block $!=0; # Initialise $! to 0 ( )xx 2**$_ # Loop 2**n times .[$!]=-.[$!] # Negate the current cell $!-= # And subtract the result from the pointer ( )%=$_ # Modulo the result by n to wrap around ;!.[$!] # Return if halted 
Jo King
  • 48.1k
  • 6
  • 131
  • 187