Skip to content

Instantly share code, notes, and snippets.

@wperron
Created February 21, 2022 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wperron/865d9c5b59bc3ded43553b43c924e17a to your computer and use it in GitHub Desktop.
Save wperron/865d9c5b59bc3ded43553b43c924e17a to your computer and use it in GitHub Desktop.
# 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 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment