------ art_159584_9769599.1155829003296
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
The week is nearly up but here is my solution. My program solved it for 5
and 6 in about a second but is taking much longer for the rest.
(5..10).each { |i| Quiz90.new(i).solve }
Success after 440 iterations!
+-------------------+
| 13 3 22 14 4|
| 24 16 11 25 17|
| 21 8 5 20 9|
| 12 2 23 15 1|
| 6 19 10 7 18|
+-------------------+
Success after 19953 iterations!
+-----------------------+
| 6 26 12 7 27 13|
| 23 9 4 24 10 1|
| 17 33 21 18 36 31|
| 5 25 11 8 28 14|
| 22 19 3 32 20 2|
| 16 34 29 15 35 30|
+-----------------------+
class Array
def shuffle
ret elf.dup
len elf.length
rand(2*len).times do
r1 and(len)
r2 and(len)
ret[r1],ret[r2] et[r2],ret[r1]
end
return ret
end
end
class Point
attr_accessor :x, :y
# two constructors in one!
# x,y for creation from integers
# "[x,y]" for creation from a Point.to_s string
#
# This is needed for a hash lookup because the hash lookup using a point
# with a certain xy value can't be found with a different point that has
# the same xy values. Arrrgh! Am I just doing something wrong?
def initialize *args
if 2 args.length
@x rgs[0]
@y rgs[1]
else
@x,@y rgs[0].gsub(/\[|\]/,'').split(',')
@x x.to_i
@y y.to_i
end
end
# reminder: "