File tree 4 files changed +18
-17
lines changed
4 files changed +18
-17
lines changed Original file line number Diff line number Diff line change 1
- module CompSci
2
- # thanks apeiros
3
- # https://gist.github.com/rickhull/d0b579aa08c85430b0dc82a791ff12d6
4
- def self . power_of? ( num , base )
5
- return false if base <= 1
6
- mod = 0
7
- num , mod = num . divmod ( base ) until ( num == 1 ) || ( mod > 0 )
8
- mod == 0
9
- end
10
- end
1
+ module CompSci ; end
Original file line number Diff line number Diff line change
1
+ module CompSci
2
+ # thanks apeiros
3
+ # https://gist.github.com/rickhull/d0b579aa08c85430b0dc82a791ff12d6
4
+ def self . power_of? ( num , base )
5
+ return false if base <= 1
6
+ mod = 0
7
+ num , mod = num . divmod ( base ) until ( num == 1 ) || ( mod > 0 )
8
+ mod == 0
9
+ end
10
+ end
Original file line number Diff line number Diff line change 39
39
puts <<EOF
40
40
41
41
#
42
- # timing CompleteTree#push where N is the count of pushes
42
+ # timing CompleteTree#push where N is the count of pushes per batch
43
43
#
44
44
45
45
EOF
Original file line number Diff line number Diff line change 1
- require 'compsci'
1
+ require 'compsci/util '
2
2
require 'minitest/autorun'
3
3
4
4
describe CompSci do
5
5
parallelize_me!
6
6
7
- it "must determine if num is a power of base" do
8
- powers = { }
7
+ it "determines if num is a power of base" do
8
+ powers = Hash . new [ ]
9
9
basemax = 12
10
10
expmax = 10
11
11
2 . upto ( basemax ) { |base |
12
12
0 . upto ( expmax ) { |exp |
13
- powers [ base ] ||= [ ]
14
- powers [ base ] << base **exp
13
+ powers [ base ] += [ base **exp ]
15
14
}
16
15
}
17
16
18
17
# 12k assertions below!
19
18
2 . upto ( basemax ) { |base |
20
19
1 . upto ( 2 **expmax ) { |num |
21
- expect ( CompSci . power_of? ( num , base ) ) . must_equal powers [ base ] . include? ( num )
20
+ x = powers [ base ] . include? ( num )
21
+ expect ( CompSci . power_of? ( num , base ) ) . must_equal x
22
22
}
23
23
}
24
24
end
You can’t perform that action at this time.
0 commit comments