public
Description: assorted codes
Clone URL: git://github.com/jorrel/codes.git
Search Repo:
removed active_support dependency by creating own 'core_ext' file
jorrel (author)
Thu May 01 09:10:54 -0700 2008
commit  a53e0049806f0b34f087603c99fbd1fa73ca103f
tree    2b29ec6c7a69d3ae402cfa996f1364e07d79988e
parent  9c2647846ff3e828de6fd78f60f55fc5f0ccf68b
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
 
25
26
27
...
110
111
112
113
 
114
115
116
...
163
164
165
166
 
167
168
169
...
195
196
197
198
199
200
201
...
206
207
208
 
 
 
 
209
210
211
...
1
 
 
 
 
 
 
 
 
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
7
8
...
91
92
93
 
94
95
96
97
...
144
145
146
 
147
148
149
150
...
176
177
178
 
179
180
181
...
186
187
188
189
190
191
192
193
194
195
0
@@ -1,27 +1,8 @@
0
 require 'rubygems'
0
-
0
-# because shoes uses its own ruby, we need to specify this
0
-# TODO: remove active_support dependency
0
-$: << '/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib'
0
-$: << '/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support'
0
-$: << '/usr/lib/ruby/1.8'
0
-require 'active_support'
0
-
0
 require 'timeout'
0
 
0
-class Array
0
- def none?(&block)
0
- not any?(&block)
0
- end
0
-
0
- def uniq_contents?
0
- size == uniq.size
0
- end
0
-
0
- def no_dup_of_non_zero_nums?
0
- map(&:to_i).reject(&:zero?).uniq_contents?
0
- end
0
-end
0
+$:.unshift File.join(File.dirname(__FILE__))
0
+require 'core_ext'
0
 
0
 module Sudoku
0
   class InvalidBoard < ArgumentError; end
0
@@ -110,7 +91,7 @@ module Sudoku
0
           proc { |a| a.transpose.all? { |b| b.no_dup_of_non_zero_nums? } }, # no same number in 1 column
0
           proc { |cells| # no same number in 1 set
0
             s = 3; rng = (0...s)
0
- sets = returning([]) { |sets|
0
+ sets = [].tap { |sets|
0
               rng.each do |r|
0
                 rng.each do |c|
0
                   sets << rng.collect { |r2| rng.collect { |c2| cells[s*r+r2][s*c+c2] } }.flatten
0
@@ -163,7 +144,7 @@ module Sudoku
0
       def box_sets
0
         s = 3 # size basic sudoku has size 3 (3 x 3 x 3 x 3)
0
         rng = (0...s)
0
- returning [] do |sets|
0
+ [].tap do |sets|
0
           rng.each do |r|
0
             rng.each do |c|
0
               sets << rng.collect { |r2| rng.collect { |c2| cells[s*r+r2][s*c+c2] } }.flatten
0
@@ -195,7 +176,6 @@ module Sudoku
0
       class Cell
0
         attr_reader :value, :fixed
0
         alias :fixed? :fixed
0
- delegate :blank?, :to => :value
0
 
0
         def initialize(value, fixed = true)
0
           @fixed = fixed
0
@@ -206,6 +186,10 @@ module Sudoku
0
           @value = Sudoku::Board::Cell.empty?(value) ? nil : value.to_i
0
         end
0
 
0
+ def blank?
0
+ value.blank?
0
+ end
0
+
0
         def clear
0
           @value = nil
0
         end

Comments

    No one has commented yet.