CREATE 'TURN HERE' SIGNS

Опубликовано: 30 Март 2026
на канале: One Person Studio
66
1

Secretary of Transportation Pete has asked you to program electronic signs to communicate to drivers that they need to turn left or turn right.

EXPLANATION CODE:
1) The input is read from standard input using fgets(STDIN), trimmed to remove any leading or trailing whitespace using trim(), and then split into individual values using explode(). These values are assigned to variables representing the direction, number of arrows, height, thickness, spacing, and additional spaces.

2) The $arrow variable is created by repeating the arrow symbol based on the given direction ($direction) for the specified thickness ($thickness).

3) The $space variable is created by repeating the space character multiple times based on the given spacing value ($spacing).

4) The arrow pattern rows are iterated using a for loop. The loop utilises the loop counter variable $j and runs for the given height ($height).

5) Inside the loop, the number of extra spaces at the beginning of each row is determined based on the direction. If the direction is "right", the extra spaces are calculated by subtracting the difference between half the height and the difference between half the height and the current row index ($j). If the direction is "left", the extra spaces are calculated by subtracting the absolute difference between half the height and the current row index ($j).

6) The current row of the arrow pattern is generated using echo. It consists of the following concatenated elements:

Extra spaces at the beginning of the row, created by repeating spaces (“ ”) based on the calculated number of extra spaces ($extraSpace) multiplied by the additional spaces value ($additional).

The arrow symbols, created by repeating the $arrow string for the specified number of arrows ($nbr), and joining them with the $space string as the separator using implode().

A newline character (PHP_EOL) to start a new line for the next row.

7) The for loop keeps running until all rows have been created.

Contents:
0:00 - Reading
1:45 - Solving
6:08 - Explaining

#codingame #coding #game #programming #easy #difficulty #reading #arithmetic #php #learntocode #tutorial #education #problemsolving #algorithmic #asmr #asmrtyping #create #turn #here #signs #loops #logic #stringmanipulation #string #manipulation #asciiart #ascii #art