[2016-05-30] Challenge #269 [Easy] BASIC Formatting

Solution in PHP, without bonus +/u/CompileBot PHP <?php $input = <<<INPUT 12 ···· VAR I ·FOR I=1 TO 31 »»»»IF !(I MOD 3) THEN ··PRINT "FIZZ" ··»»ENDIF »»»»····IF !(I MOD 5) THEN »»»»··PRINT "BUZZ" ··»»»»»»ENDIF »»»»IF (I MOD 3) && (I MOD 5) THEN ······PRINT "FIZZBUZZ" ··»»ENDIF »»»»·NEXT INPUT; $level = 0; $all = explode("\n", $input); $all_count = count($all); $output = ""; for ($i = 0; $i < $all_count; $i++) { $line = $all[$i]; $line = ltrim($line, "·» \t"); if (is_numeric($line) || empty($line)) { continue; } if (stripos($line, 'NEXT') === 0 || stripos($line, 'ENDIF') === 0) { $level -= 4; } $output .= str_repeat("·", $level) . $line . "\n"; if (stripos($line, 'FOR') === 0 || stripos($line, 'IF') === 0) { $level += 4; } } echo $output;

/r/dailyprogrammer Thread