puzzles/longest-sub-seq/longest-seq.awk
Zoé Cassiopée Gauthier 7e4f02547b Initial commit
2024-04-02 17:01:09 -04:00

13 lines
246 B
Awk

# echo -n '1,9,87,3,10,4,20,2,45' | tr ',' '\n' | sort -g | tr '\n' ' ' | awk -f longest-seq.awk
BEGIN {getline;
i = 2
j = 1
while (i < NF) {
if ($(i) - $(j) != i - j) {
j++
}
i++
}
}
END { printf "longest: %s\n", i-j }