3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function move($past, $current) { if($current == 15) return 1; $x = $current >> 2; $y = $current % 4; $valid_moves = array(); if($x < 3) { $possible = $current+4; if(!isset($past[$possible])) { $valid_moves[] = $possible; } } if($x > 0) { $possible = $current-4; if(!isset($past[$possible])) { $valid_moves[] = $possible; } } if($y < 3) { $possible = $current+1; if(!isset($past[$possible])) { $valid_moves[] = $possible; } } if($y > 0) { $possible = $current-1; if(!isset($past[$possible])) { $valid_moves[] = $possible; } } if(empty($valid_moves)) return 0; else { $score = 0; $past[$current] = true; foreach($valid_moves as $valid_move) { $score += move($past, $valid_move); } return $score; } } echo move(array(),0);
Output for 4.3.0 - 7.1.0
184