Entries from 2007-02-01 to 1 month
about 500 lines of tk codes for Bisector CRUD #!/usr/bin/env ruby require 'tk' PntRad = 3 # Point radius of TkcOval ScrHgt = 600 # Screen Hight class Geom Infinity = 10*ScrHgt @@canvas = Hash.new attr_accessor :g def initialize @g = nil en…
class Array def power inject([[]]){|ps, e| ps + ps.map{|s| s + [e]}} end end p [1,2,3].power [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]
Given a 8 by 8 grid and a robot that moves from the left bottom corner (0, 0) to the right top corner (7, 7) by stepping either right (East) or upward (North) in total 14 steps, find all possible paths.A sample solution: def C(i, j) if i =…
require 'tk' root = TkRoot.new $canvas = TkCanvas.new(root) { width 360 height 60 } $canvas.pack colors = ['00', '33', '66', '99', 'cc', 'ff'] d = 10 for i in 0..5 for j in 0..5 for k in 0..5 c = '#' + colors[i] + colors[j] + colors[k] x =…
gets chomp h=Hash['I',1,'V',5,'X',10,'L',50,'C',100,'D',500,'M',1000] s=u=0 split(//).each{|r|v=h[r] s+=u
module Enumerable def bop(op, m) map {|i| m.send(op, i)} end end class Array def | other return self + other if empty? or other.empty? case first <=> other.first when -1, 0; e = shift when 0, 1; e = other.shift end return (self | other).un…