Skip to content

Instantly share code, notes, and snippets.

@takahashilabo
Created June 17, 2017 04:39
Show Gist options
  • Save takahashilabo/ec4084c9e82add45447c00b7fac51243 to your computer and use it in GitHub Desktop.
Save takahashilabo/ec4084c9e82add45447c00b7fac51243 to your computer and use it in GitHub Desktop.
This code counts consecutive lines in standard input
cnt = 1
prev_s = ""
while s = gets do
s.chomp!
if prev_s == "" then
prev_s = s
next
end
if s == prev_s then
cnt += 1
else
print prev_s, ",", cnt, "\n"
prev_s = s
cnt = 1
end
end
print prev_s, ",", cnt, "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment