You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
418 B
25 lines
418 B
8 years ago
|
def step(a)
|
||
|
b = a.reverse.tr('10', '01')
|
||
|
"#{a}0#{b}"
|
||
|
end
|
||
|
|
||
|
def checksum(data)
|
||
|
checksum = data.chars
|
||
|
loop do
|
||
|
checksum = checksum.each_slice(2).map {|a,b| (a == b) ??1:?0 }
|
||
|
break if checksum.length.odd?
|
||
|
end
|
||
|
checksum.join
|
||
|
end
|
||
|
|
||
|
seed = '10001110011110000'
|
||
|
target_length = 272
|
||
|
|
||
|
state = seed
|
||
|
while state.length < target_length
|
||
|
state = step(state)
|
||
|
end
|
||
|
|
||
|
data = state[0...target_length]
|
||
|
puts checksum(data)
|