Last active
June 27, 2021 16:20
-
-
Save drupol/e42ac5106fa38973ef871338cb1b1d96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Factorial of a number | |
| printf("\nype a number: ") | |
| && ($g = (int) trim(fgets(STDIN))) && (fn(int $g, $y) => | |
| printf($y(static fn (callable $function) => static fn ($n = 1) => (1 >= $n) ? 1 : $n * $function($n - 1))($g)) | |
| )( | |
| $g, | |
| static fn (callable $g): callable => (static fn ($f): callable => $f($f))(static fn ($f): callable => $g(static fn ($x) => $f($f)($x))) | |
| ); | |
| // Collatz/Syracuse conjecture | |
| printf("\nType a number: ") | |
| && ($g = (int) trim(fgets(STDIN))) && (fn($g, $y) => | |
| $y(static fn (callable $loop) => static fn (int $n) => printf('%s,', $n) && (1 === $n ? 1 : $loop(0 === $n % 2 ? $n / 2 : $n * 3 + 1)))($g) | |
| )( | |
| $g, | |
| static fn (callable $g): callable => (static fn ($f): callable => $f($f))(static fn ($f): callable => $g(static fn ($x) => $f($f)($x))) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment