Sentinel+run_detection.rb
This content was produced by an LLM and could include errors.
This script processes an array, grouping non-empty words. It counts the number of elements in each group and prints the corresponding word (label) and the final count.
# frozen_string_literal: true
#=> nil
seq = ['ONE', '', '', 'TWO', '', 'THREE', '', '', '',]
#=> ["ONE", "", "", "TWO", "", "THREE", "", "", ""]
seq.push('END')
#=> ["ONE", "", "", "TWO", "", "THREE", "", "", "", "END"]
count = 0
#=> 0
label = ''
#=> ""
index = 0
#=> 0
loop do
current = seq[index]
label = current unless current.empty?
# processing 1
count += 1
next_value = seq[index + 1]
unless next_value.empty?
# processing 2
puts "#{label}: #{count}"
break if next_value.eql?('END')
# initialize
count = 0
end
index += 1
end
ONE: 3
TWO: 2
THREE: 4
#=> nil
Ruby 4.0.3