28 lines
876 B
Ruby
28 lines
876 B
Ruby
initial_string = [*0..255]
|
|
suffix = [17, 31, 73, 47, 23]
|
|
# shifts = File.open('puzzle_10.txt').read.split(',').map(&:to_i) + suffix
|
|
# shifts = [1, 2, 3] + suffix
|
|
# shifts = suffix
|
|
string = '129,154,49,198,200,133,97,254,41,6,2,1,255,0,191,108' # File.open('puzzle_10.txt').read
|
|
shifts = string.split('').map(&:ord)
|
|
shifts = shifts + suffix
|
|
skip_size = 0
|
|
offset = 0
|
|
shifts = shifts * 64
|
|
for shift in shifts do
|
|
initial_string.rotate! offset
|
|
if shift > 0 then
|
|
rotated_bit = initial_string[0..shift - 1]
|
|
kept_bit = initial_string[shift..initial_string.length-1]
|
|
initial_string = rotated_bit.reverse + kept_bit
|
|
end
|
|
initial_string.rotate! -offset
|
|
offset += shift + skip_size
|
|
skip_size += 1
|
|
end
|
|
blocks = initial_string.each_slice(16).to_a
|
|
hash = blocks.map do |block|
|
|
block.inject(0) { |x, y| x^y }.to_s(16)
|
|
end
|
|
puts hash.join('')
|