diff --git a/Makefile b/Makefile index 212ec4f..4d5b133 100644 --- a/Makefile +++ b/Makefile @@ -23,4 +23,7 @@ brain-calc: ./bin/brain-calc brain-gcd: - ./bin/brain-gcd \ No newline at end of file + ./bin/brain-gcd + +brain-progression: + ./bin/brain-progression \ No newline at end of file diff --git a/bin/brain-progression b/bin/brain-progression new file mode 100755 index 0000000..1221cc2 --- /dev/null +++ b/bin/brain-progression @@ -0,0 +1,9 @@ +#!/usr/bin/env php + questionHandler(); + + return $module; +}; + +/** + * Returns a question and its expected answer. + * + * - 0: The question (string) + * - 1: The expected answer (string) + * + * @return array{ + * 0: string, + * 1: string + * } + * @throws Exception + */ +function questionHandler(): array +{ + $lengthProgression = 10; + $step = random_int(2, 10); + $shift = random_int(1, 10); + $progression = range($shift, $shift + (($lengthProgression - 1) * $step), $step); + $guessIndex = random_int(0, 8); + $expectedAnswer = $progression[$guessIndex]; + $progression[$guessIndex] = '..'; + $question = implode(' ', $progression); + return [$question, $expectedAnswer]; +}