#!/usr/bin/fish set lines (cat input) function traverse set hv $argv[1] set vv $argv[2] set pos 0 set trees 0 set i -1 for val in $lines set i (math $i + 1) if test (math $i % $vv) -ne 0 continue end set width (string length $val) set char (string sub -s (math $pos + 1) -l 1 $val) set pos (math "($pos + $hv) % $width") if test "$char" = "#" set trees (math $trees + 1) end end echo $trees end set a (traverse 1 1) set b (traverse 3 1) set c (traverse 5 1) set d (traverse 7 1) set e (traverse 1 2) echo "Total number of things is ($a * $b * $c * $d * $e) " (math "$a * $b * $c * $d * $e")