Sha256: 1ef926c7fa20544f5f0c1bcf64ebada3335cf1665a4ae059d00674a756fea66f
Contents?: true
Size: 791 Bytes
Versions: 5
Compression:
Stored size: 791 Bytes
Contents
module Hanoi module Jane class Lifter < Array attr_reader :lifted def initialize stack stack.map { |i| self.push i } @lifted = false end def lift start = Lifter.position self item = self[start] self[start] = nil next_pos = start + 1 if next_pos >= self.length @lifted = true else self[next_pos] = item end end def each until @lifted lift yield self end end def Lifter.position stack pos = nil stack.reverse.each_with_index do |item, index| if item pos = index break end end stack.length - 1 - pos end end end end
Version data entries
5 entries across 5 versions & 1 rubygems