14_one_time_pad.rb
# One-pass run through all indices.
#
# Unfortunately, I tried to code this while going for the leaderboard,
# and ended up with a buggy implementation
# (with quintuplets qualifying themselves as keys)
#
# Premature optimisation did not serve me well.
# Next time, I'll probably try the naive caching approach first.
One-pass run through all indices.
Unfortunately, I tried to code this while going for the leaderboard,
and ended up with a buggy implementation
(with quintuplets qualifying themselves as keys)

Premature optimisation did not serve me well.
Next time, I'll probably try the naive caching approach first.
One - pass run through all indices . Unfortunately I tried to code this while going for the leaderboard and ended up with a buggy implementation ( with quintuplets qualifying themselves as keys ) Premature optimisation did not serve me well . Next time I ' ll probably try the naive caching approach first .
def pads(inputs)
  pads = []
  stop = 1.0 / 0.0
  triplets = Hash.new { |h, k| h[k] = [] }
  0.step { |i|
    md5 = inputs[i]
    md5.scan(/(.)\1\1\1\1/).each { |(char)|
      candidates = triplets.delete(char)
      candidates.select { |n| n + WINDOW >= i }.each { |n|
        pads << n
        stop = n + WINDOW if pads.size == NUM_KEYS
      }
    }
    m = (/(.)\1\1/.match(md5))
    triplets[m[1]] << i if m
    return pads.sort if i >= stop
  }
end
def pads ( inputs ) pads = [ ] stop = 1.0 / 0.0 triplets = Hash . new { | h , k | h [ k ] = [ ] } 0 . step { | i | md5 = inputs [ i ] md5 . scan ( / (.) \1 \1 \1 \1 / ) . each { | ( char ) | candidates = triplets . delete ( char ) candidates . select { | n | n + WINDOW >= i } . each { | n | pads << n stop = n + WINDOW if pads . size == NUM_KEYS } } m = ( / (.) \1 \1 / . match ( md5 ) ) triplets [ m [ 1 ] ] << i if m return pads . sort if i >= stop } end
One-pass run through all indices.
One - pass run through all indices .
# Still need to check for any numbers undercutting n.
inputs
<not_specific>