This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang planet neil/sicp | |
(define (mu_compute mu_initialize mu_iterate mu_finished? mu_finalize) | |
(define (mu_iterate_repeat x guess) | |
(if (mu_finished? x guess) | |
guess | |
(mu_iterate_repeat x (mu_iterate x guess)))) | |
(lambda(x) (mu_finalize (mu_iterate_repeat x (mu_initialize x))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rex@rex-desktop:~/ruby_stuff/knight_puzzle$ ruby test_pair_speeds.rb | |
Rehearsal --------------------------------------------------------- | |
Create Array Pairs: 0.230000 0.020000 0.250000 ( 0.292854) | |
Create Hash Pairs: 1.340000 0.040000 1.380000 ( 1.432234) | |
Create Object Pairs: 0.600000 0.010000 0.610000 ( 0.638025) | |
------------------------------------------------ total: 2.240000sec | |
user system total real | |
Create Array Pairs: 0.190000 0.000000 0.190000 ( 0.197217) | |
Create Hash Pairs: 1.250000 0.010000 1.260000 ( 1.309144) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
class Pair | |
attr_accessor :x,:y | |
def initialize(x,y) | |
@x = x | |
@y = y | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KnightBoard | |
attr_reader :kb_size | |
attr_reader :squares | |
attr_reader :distances | |
def initialize(kb_size) | |
@kb_size = kb_size | |
@squares = [] | |
@distances = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@squares = [] | |
@distances = {} | |
@squares = [] | |
0.upto(kb_size-1) do |xi| | |
0.upto(kb_size-1) do |yi| | |
@squares << [xi,yi] | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KnightBoard | |
attr_reader :kb_size | |
attr_reader :squares | |
attr_reader :square_pairs | |
attr_reader :distances | |
def initialize(kb_size) | |
@kb_size = kb_size | |
@squares = [] | |
@square_pairs = [] |