--ylS2wUBXLOxYXZFQ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Wed, Mar 09, 2005 at 04:27:10AM +0900, Bill Guindon wrote:
> given 5 variables... incoming, minimium, current, maximum, reserve
> 
> produce a text file that shows every possible map of the variable relations.
> 
> Something along the lines of this:
> 
>   minimum < current < hidden  ncoming  eserve

I've sent my solution already offlist, but now I see William James sent
one publicly, so I make it public as well. His solution gives 541
relation, I have 1305... interesting, which could be the good one?

Csaba

--ylS2wUBXLOxYXZFQ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="puzzle.rb"


def onp n  # as in ordered number theoretic partition
 n.zero? and return [[]]
 res  ]
 (1..n).each { |k| 
   onp(n-k).each { |a| 
     res << [k]+a 
   } 
 }
 res
end

def perm n
 n.zero? and return [[0]]
 res  ]
 perm(n-1).each{ |pe| 
   (0..n).each{|j| 
     res << pe.dup.insert(j,n)
   }
 }
 res
end

def show(n)
  onp(n).each{|o| 
    perm(n-1).each{|pe| 
      catch(:bad) { 
        b
        o.each{|i| 
          b << []
          i.times{b[-1] << pe.shift}
          ((q1]).size-2).times{|i| q[i] < q[i+1] or throw :bad}
        }
        yield b
      }
    }
  }
end

if $0 __FILE__
  words(minimum current hidden incoming reserve).sort 
  show(5) { |db| 
    puts db.map{|e| 
      e.map{|i| words[i]}.join "  
    }.join(" < ") 
  }
end

--ylS2wUBXLOxYXZFQ--