24games 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/24games +4 -4
- data/lib/calc24/calc24_core.rb +4 -4
- data/lib/calc24/ext.rb +17 -13
- data/lib/calc24/version.rb +1 -1
- metadata +3 -3
data/bin/24games
CHANGED
@@ -6,22 +6,22 @@ require 'calc24'
|
|
6
6
|
require 'calc24/version'
|
7
7
|
|
8
8
|
begin
|
9
|
-
|
9
|
+
numbers = []
|
10
10
|
|
11
11
|
raise Calc24::VERSION if ['--version', '-v'].include? ARGV[0]
|
12
12
|
|
13
13
|
if ARGV.count == 1 and ARGV[0].size == 4
|
14
14
|
ARGV[0].each_char do |c|
|
15
|
-
|
15
|
+
numbers << c.to_i
|
16
16
|
end
|
17
17
|
elsif ARGV.count == 4
|
18
|
-
|
18
|
+
numbers = ARGV.to_i
|
19
19
|
else
|
20
20
|
raise " inputs 4 numbers such as: 5959 or 5 9 5 9"
|
21
21
|
end
|
22
22
|
|
23
23
|
t0 = Time.now
|
24
|
-
player = Calc24::TwentyFourGamePlayer.new(
|
24
|
+
player = Calc24::TwentyFourGamePlayer.new(numbers)
|
25
25
|
|
26
26
|
if player.solutions.empty?
|
27
27
|
puts "no solutions"
|
data/lib/calc24/calc24_core.rb
CHANGED
@@ -125,16 +125,16 @@ module Calc24
|
|
125
125
|
|
126
126
|
@@objective = Rational(24,1)
|
127
127
|
|
128
|
-
def initialize(
|
129
|
-
@
|
128
|
+
def initialize(numbers)
|
129
|
+
@numbers = numbers
|
130
130
|
@solutions = {}
|
131
131
|
solve
|
132
132
|
end
|
133
133
|
|
134
|
-
attr_reader :
|
134
|
+
attr_reader :numbers, :solutions
|
135
135
|
|
136
136
|
def solve
|
137
|
-
|
137
|
+
numbers.permutation.to_a.uniq.each do |a,b,c,d|
|
138
138
|
MAN4D4S.each do |expr|
|
139
139
|
# evaluate using rational arithmetic
|
140
140
|
test = expr.gsub('%d', 'Rational(%d,1)') % [a, b, c, d]
|
data/lib/calc24/ext.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
1
|
class Array
|
2
2
|
def to_i
|
3
|
-
self.map do |
|
4
|
-
|
5
|
-
case arg.upcase
|
6
|
-
when 'J' then 11
|
7
|
-
when 'Q' then 12
|
8
|
-
when 'K' then 13
|
9
|
-
when 'A' then 1
|
10
|
-
else Integer(arg)
|
11
|
-
end
|
12
|
-
rescue ArgumentError
|
13
|
-
raise " unknown digit: '#{arg}'"
|
14
|
-
end
|
3
|
+
self.map do |char|
|
4
|
+
char.to_i
|
15
5
|
end
|
16
6
|
end
|
17
7
|
end
|
18
8
|
|
19
9
|
class String
|
10
|
+
def to_i
|
11
|
+
begin
|
12
|
+
case self.upcase
|
13
|
+
when 'J' then 11
|
14
|
+
when 'Q' then 12
|
15
|
+
when 'K' then 13
|
16
|
+
when 'A' then 1
|
17
|
+
else Integer(self)
|
18
|
+
end
|
19
|
+
rescue ArgumentError
|
20
|
+
raise " unknown number: '#{self}'"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
20
24
|
def to_p
|
21
|
-
{'11' => 'J', '12' => 'Q', '13' => 'K'}.each {|
|
25
|
+
{'11' => 'J', '12' => 'Q', '13' => 'K'}.each {|number, poker| self.gsub!(number, poker)}
|
22
26
|
self
|
23
27
|
end
|
24
28
|
end
|
data/lib/calc24/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 24games
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-07 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: computes an expression to solve the 24 game if possible.
|
15
15
|
email:
|
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
53
|
rubyforge_project: 24games
|
54
|
-
rubygems_version: 1.
|
54
|
+
rubygems_version: 1.8.10
|
55
55
|
signing_key:
|
56
56
|
specification_version: 3
|
57
57
|
summary: 24 game/Solve
|