<?php

// je récupère la map de base
$map = array_map('str_split', explode("\n", file_get_contents('input.txt')));
$height = count($map);
$length = count($map[0]);

// je la multiplie pour qu'elle soit complète
$multiply_by = ceil($height / $length) * 4;
array_walk($map, static function(&$row) use ($multiply_by) {
    $row = str_split(str_repeat(implode('', $row), $multiply_by));
});
$height = count($map);
$length = count($map[0]);

// je la visite et compte les arbres
$right = 0;
$down = 0;
$count_trees = 0;
while ($right < $length && $down < $height) {
    if ($map[$down][$right] === '#') {
        $count_trees++;
    }

    $right += 3;
    ++$down;
}

echo $count_trees;