I see lots of complex solutions when binary data packing/unpacking should be relatively compact and optimized. Hopefully this helps give people some ideas!
# Read a line and parse it w/ convertdefparse(data)(convert(data[0..6],'F','B')*8)+convert(data[7..9],'L','R')end# Converts data into a binary 0/1 string and then gets the dec valuedefconvert(data,off_char,on_char)data.scan(/[#{off_char}|#{on_char}]/).map{|c|c==off_char?0:1}.join('').to_i(2)end# Part Oneseats=File.readlines('input.txt').map{|s|parse(s)}.sortpseats.last# Part Twoparted_seats=seats.slice_when{|i,j|i+1!=j}.to_ap(parted_seats.first.last..parted_seats.last.first).to_a[1]
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Ruby, Late to the party - catching up!
I see lots of complex solutions when binary data packing/unpacking should be relatively compact and optimized. Hopefully this helps give people some ideas!