numeron 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +83 -10
- data/lib/numeron/calculator.rb +143 -49
- data/lib/numeron/solver.rb +132 -29
- data/lib/numeron/version.rb +1 -1
- data/numeron.gemspec +2 -2
- data/spec/lib/numeron/calculator_spec.rb +150 -0
- metadata +5 -4
data/README.md
CHANGED
@@ -3,14 +3,10 @@
|
|
3
3
|
ヌメロンの解の探索プログラム (Ruby版, 3桁Only)
|
4
4
|
|
5
5
|
1. 解として可能性のある数値を自動計算
|
6
|
-
2.
|
6
|
+
2. ダブル(されたあとの開放されたカード番号指定), ターゲット, チェンジ, ハイアンドロー, スラッシュ, シャッフルに対応
|
7
7
|
3. 次に出すべき1手を計算してくれるAnalyzer
|
8
8
|
4. シミュレーター付き(要実装)
|
9
9
|
|
10
|
-
Androidアプリ ... https://play.google.com/store/apps/details?id=com.jpn.gemstone.numer0n.android
|
11
|
-
|
12
|
-
iPhoneアプリ ... https://itunes.apple.com/jp/app/numer0n-numeron/id512484171?mt=8
|
13
|
-
|
14
10
|
## インストール
|
15
11
|
|
16
12
|
ruby 1.9以上が必要です
|
@@ -25,15 +21,92 @@ irbで実行します
|
|
25
21
|
> require 'numeron'
|
26
22
|
true
|
27
23
|
> Numeron::Solver.new.run
|
24
|
+
action (item|question|think|finish|help):
|
25
|
+
```
|
26
|
+
|
27
|
+
### actionの説明
|
28
|
+
|
29
|
+
```
|
30
|
+
item ... アイテムを使う、使われた場合はこれを入力。0 または i をいれてもアイテム利用コンソールが起動する
|
31
|
+
question ... 相手に対して、3桁の数値をコールする。
|
32
|
+
think ... 答えを計算します。
|
33
|
+
finish ... 終了
|
34
|
+
```
|
35
|
+
|
36
|
+
### itemの説明
|
37
|
+
|
38
|
+
ダブルから順番に使用するアイテムを聞かれますので、使用する箇所でyes or yを入力します。
|
39
|
+
|
40
|
+
```
|
41
|
+
Using double ? [yes]:
|
42
|
+
Using shuffle ? [yes]:
|
43
|
+
Using change ? [yes]:
|
44
|
+
Using target ? [yes]:
|
45
|
+
Using high_and_low ? [yes]:
|
46
|
+
Using slash ? [yes]:
|
47
|
+
```
|
48
|
+
|
49
|
+
#### double
|
50
|
+
|
51
|
+
```
|
52
|
+
Input open number: # <= 相手が開けた数値を入力します。(0 から 9)
|
53
|
+
Input open position [0, 1, 2]: # <= 開けた数値の位置を入力します。(0が一番左側)
|
54
|
+
```
|
55
|
+
|
56
|
+
#### shuffle
|
57
|
+
|
58
|
+
特に入力は求められません
|
59
|
+
|
60
|
+
#### change
|
61
|
+
|
62
|
+
```
|
63
|
+
Input change position: # <= 相手がチェンジした位置を入力します。(0が一番左側)
|
64
|
+
Input high or low: # <= チェンジした数値がhigh なのか low なのかを入力します
|
65
|
+
```
|
66
|
+
|
67
|
+
#### target
|
68
|
+
|
69
|
+
```
|
70
|
+
Input open number: # <= ターゲットで指定した番号を入力します。(0から9)
|
71
|
+
Input open position.
|
72
|
+
If the enemy does not open card position, don't put anything
|
73
|
+
Input [0, 1, 2, or empty]: # <= その番号が存在した場合はその位置を入力します(0が一番左側), 存在しなかった場合は何も入力しません。
|
74
|
+
```
|
75
|
+
|
76
|
+
#### high_and_low
|
77
|
+
|
78
|
+
```
|
79
|
+
position 0 is high? [yes|no]: # <= 左側がhighの場合は yes or y, lowの場合はno or nを入力
|
80
|
+
position 1 is high? [yes|no]: # <= 真ん中がhighの場合は yes or y, lowの場合はno or nを入力
|
81
|
+
position 2 is high? [yes|no]: # <= 右側がhighの場合は yes or y, lowの場合はno or nを入力
|
82
|
+
```
|
83
|
+
|
84
|
+
#### slash
|
85
|
+
|
86
|
+
```
|
87
|
+
Input slash number: # <= slashナンバーを入力
|
88
|
+
```
|
89
|
+
|
90
|
+
### questionの説明
|
91
|
+
|
92
|
+
コールした数値とその解答を入力するメイン部分です。
|
93
|
+
|
94
|
+
```
|
28
95
|
Attack number: 123 # <= callした数値を入力
|
29
96
|
Eat number: 0 # <= callした結果 eatの数を入力
|
30
97
|
Bite number: 0 # <= callした結果 biteの数を入力
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
98
|
+
```
|
99
|
+
|
100
|
+
### thinkの説明
|
101
|
+
|
102
|
+
PCが計算した答えを表示してくれます。
|
103
|
+
結構適当です。
|
35
104
|
|
36
|
-
|
105
|
+
```
|
106
|
+
... thinking
|
107
|
+
possibilities: 48 # <= 答えの可能性として考えられる個数
|
108
|
+
Analyzer Answer: 789 # <= アナライザーが出した答え
|
109
|
+
Possibilitiy list random: 345 # <= 答えの候補からランダムで取り出した数値
|
37
110
|
```
|
38
111
|
|
39
112
|
## Simulatorの使い方
|
data/lib/numeron/calculator.rb
CHANGED
@@ -18,6 +18,7 @@ module Numeron
|
|
18
18
|
@possibilities = nil
|
19
19
|
@mays = [(0..9).to_a, (0..9).to_a, (0..9).to_a]
|
20
20
|
@answer_size = answer_size
|
21
|
+
@slash_number = nil
|
21
22
|
end
|
22
23
|
|
23
24
|
# コールした数値とその結果を設定
|
@@ -60,11 +61,15 @@ module Numeron
|
|
60
61
|
return true
|
61
62
|
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
|
65
|
+
# シャッフル
|
66
|
+
def shuffle
|
67
|
+
# 使用確定数字を計算(候補数が1つの場合)
|
68
|
+
fixed = @mays.select{|f| f.size == 1}.flatten
|
69
|
+
|
70
|
+
@mays[0] = @mays[0] | @mays[1] | @mays[2]
|
71
|
+
@mays[1] = @mays[0] | @mays[1] | @mays[2]
|
72
|
+
@mays[2] = @mays[0] | @mays[1] | @mays[2]
|
68
73
|
|
69
74
|
list = []
|
70
75
|
@mays[0].each do |i|
|
@@ -72,11 +77,129 @@ module Numeron
|
|
72
77
|
next if i == j
|
73
78
|
@mays[2].each do |k|
|
74
79
|
next if i == k || j == k
|
75
|
-
|
80
|
+
if fixed.size == 0
|
81
|
+
list << validation(i, j, k)
|
82
|
+
else
|
83
|
+
fixed.each do |f| # ちょっと計算量がおおいか。。。
|
84
|
+
list << validation(f, j, k)
|
85
|
+
list << validation(i, f, k)
|
86
|
+
list << validation(i, j, f)
|
87
|
+
end
|
88
|
+
end
|
76
89
|
end
|
77
90
|
end
|
78
91
|
end
|
79
|
-
|
92
|
+
|
93
|
+
@possibilities = list.compact.uniq
|
94
|
+
@histories.each do |history|
|
95
|
+
eat_and_bite = history[:eat] + history[:bite]
|
96
|
+
if eat_and_bite == 1
|
97
|
+
one_eat_or_one_bite(history[:attack])
|
98
|
+
elsif eat_and_bite == 2
|
99
|
+
two_eat_or_two_bite(history[:attack])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
calc_slash
|
103
|
+
end
|
104
|
+
|
105
|
+
# スラッシュ
|
106
|
+
# @param [Integer] number スラッシュナンバー
|
107
|
+
def slash(number)
|
108
|
+
@slash_number = number
|
109
|
+
calc_slash
|
110
|
+
end
|
111
|
+
|
112
|
+
# チェンジ
|
113
|
+
# チェンジする桁数の指定とその数値がhigh or lowどちらなのかを宣言する
|
114
|
+
# @param [Integer] position チェンジを実行した位置。 0 - 2の範囲
|
115
|
+
# @param [Boolean] is_high チェンジしたカードがhighかどうか
|
116
|
+
def change(position, is_high)
|
117
|
+
raise ArgumentError, 'Invalid argument. position is 0 to 3' if position < 0 && position > 2
|
118
|
+
|
119
|
+
_possibilities = is_high ? [5, 6, 7, 8, 9] : [0, 1, 2, 3, 4]
|
120
|
+
@mays.each_with_index do |may, i|
|
121
|
+
_possibilities -= may if may.size == 1
|
122
|
+
if i != position
|
123
|
+
tmp = may.select {|f| is_high ? f > 4 : f <= 4 }
|
124
|
+
next if tmp.size != 1
|
125
|
+
@mays[i] -= tmp
|
126
|
+
end
|
127
|
+
end
|
128
|
+
# 3種類に絞りこまれていたら、残りの種類であることが確定
|
129
|
+
x = (@mays[0] + @mays[1] + @mays[2]).uniq
|
130
|
+
_possibilities -= x if x.size == 3
|
131
|
+
@mays[position] = _possibilities
|
132
|
+
|
133
|
+
# 可能性の再計算
|
134
|
+
@possibilities = recalculate
|
135
|
+
end
|
136
|
+
|
137
|
+
# ダブル
|
138
|
+
# 相手がダブルを使用し、カードの数値を公開した場合
|
139
|
+
def double(number, position)
|
140
|
+
target(number, position)
|
141
|
+
end
|
142
|
+
|
143
|
+
# ハイ&ロー
|
144
|
+
# @param [Array] result [true, false, true] で high, low, high を示す
|
145
|
+
def high_and_low(result = [])
|
146
|
+
raise ArgumentError, 'Invalid argument.' if result.size != 3
|
147
|
+
|
148
|
+
result.each_with_index do |f, i|
|
149
|
+
@mays[i] = @mays[i] & (f ? [5, 6, 7, 8, 9] : [0, 1, 2, 3, 4])
|
150
|
+
end
|
151
|
+
update_possibilities(recalculate)
|
152
|
+
end
|
153
|
+
|
154
|
+
# ターゲット
|
155
|
+
# @param [Integer] number 0 から 9までの数値
|
156
|
+
# @param [Integer] position 指定した番号がヒットだった場合の、桁。ヒットでなければnilを指定
|
157
|
+
def target(number, position = nil)
|
158
|
+
raise ArgumentError, 'Invalid argumet. number is 0 to 9' if number < 0 && number > 9
|
159
|
+
raise ArgumentError, 'Invalid argument. position is nil or 0 to 3' if !position.nil? && position < 0 && position > 2
|
160
|
+
if position.nil?
|
161
|
+
3.times {|i| @mays[i] = @mays[i] - [number]}
|
162
|
+
else
|
163
|
+
@mays[position] = [number]
|
164
|
+
end
|
165
|
+
update_possibilities(recalculate)
|
166
|
+
end
|
167
|
+
|
168
|
+
protected
|
169
|
+
|
170
|
+
# 各桁の可能性を元に再度可能性リストを作り直す
|
171
|
+
def recalculate
|
172
|
+
reject
|
173
|
+
[].tap do |list|
|
174
|
+
@mays[0].each do |i|
|
175
|
+
@mays[1].each do |j|
|
176
|
+
next if i == j
|
177
|
+
@mays[2].each do |k|
|
178
|
+
next if i == k || j == k
|
179
|
+
list << validation(i, j, k)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end.compact.uniq
|
184
|
+
end
|
185
|
+
|
186
|
+
# 確定数値が存在する場合その数値を除外する
|
187
|
+
def reject
|
188
|
+
@mays.each_with_index do |may, i|
|
189
|
+
next if may.size != 1
|
190
|
+
@mays.each_with_index do |f, j|
|
191
|
+
next if i == j
|
192
|
+
@mays[j] = @mays[j] - may
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
# 0 Eat 0 Bite の時の可能性計算
|
198
|
+
def zero_eat_zero_bite(attack)
|
199
|
+
@mays[0] = @mays[0] - attack
|
200
|
+
@mays[1] = @mays[1] - attack
|
201
|
+
@mays[2] = @mays[2] - attack
|
202
|
+
update_possibilities(recalculate)
|
80
203
|
end
|
81
204
|
|
82
205
|
# 0 Eat 1 Bite の時の可能性計算
|
@@ -90,24 +213,24 @@ module Numeron
|
|
90
213
|
(@mays[0] - attack).each do |i|
|
91
214
|
(@mays[1] - attack).each do |j|
|
92
215
|
next if i == j
|
93
|
-
list << validation(i, j, attack[0])
|
94
|
-
list << validation(i, j, attack[1])
|
216
|
+
list << validation(i, j, attack[0])
|
217
|
+
list << validation(i, j, attack[1])
|
95
218
|
end
|
96
219
|
end
|
97
220
|
|
98
221
|
(@mays[0] - attack).each do |i|
|
99
222
|
(@mays[2] - attack).each do |k|
|
100
223
|
next if i == k
|
101
|
-
list << validation(i, attack[0], k)
|
102
|
-
list << validation(i, attack[2], k)
|
224
|
+
list << validation(i, attack[0], k)
|
225
|
+
list << validation(i, attack[2], k)
|
103
226
|
end
|
104
227
|
end
|
105
228
|
|
106
229
|
(@mays[1] - attack).each do |j|
|
107
230
|
(@mays[2] - attack).each do |k|
|
108
231
|
next if j == k
|
109
|
-
list << validation(attack[1], j, k)
|
110
|
-
list << validation(attack[2], j, k)
|
232
|
+
list << validation(attack[1], j, k)
|
233
|
+
list << validation(attack[2], j, k)
|
111
234
|
end
|
112
235
|
end
|
113
236
|
update_possibilities(list)
|
@@ -255,32 +378,6 @@ module Numeron
|
|
255
378
|
end
|
256
379
|
end
|
257
380
|
|
258
|
-
# シャッフル
|
259
|
-
def shuffle
|
260
|
-
@mays[0] = @mays[0] | @mays[1] | @mays[2]
|
261
|
-
@mays[1] = @mays[0] | @mays[1] | @mays[2]
|
262
|
-
@mays[2] = @mays[0] | @mays[1] | @mays[2]
|
263
|
-
list = []
|
264
|
-
@mays[0].each do |i|
|
265
|
-
@mays[1].each do |j|
|
266
|
-
next if i == j
|
267
|
-
@mays[2].each do |k|
|
268
|
-
next if i == k || j == k
|
269
|
-
list << validation(i, j, k)
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
@possibilities = list.compact
|
274
|
-
@histories.each do |history|
|
275
|
-
eat_and_bite = history[:eat] + history[:bite]
|
276
|
-
if eat_and_bite == 1
|
277
|
-
one_eat_or_one_bite(history[:attack])
|
278
|
-
elsif eat_and_bite == 2
|
279
|
-
two_eat_or_two_bite(history[:attack])
|
280
|
-
end
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
381
|
# シャッフル時の再計算
|
285
382
|
# 1 Eat 0 Bite または 0 Eat 1 Biteの場合
|
286
383
|
def one_eat_or_one_bite(attack)
|
@@ -349,13 +446,10 @@ module Numeron
|
|
349
446
|
update_possibilities(list)
|
350
447
|
end
|
351
448
|
|
352
|
-
def
|
353
|
-
|
354
|
-
|
355
|
-
# 9
|
356
|
-
# [0, 9]
|
449
|
+
def calc_slash
|
450
|
+
return if @slash_number.nil?
|
357
451
|
list = []
|
358
|
-
slash_number.upto(9){|i|
|
452
|
+
@slash_number.upto(9){|i|
|
359
453
|
min = i - slash_number
|
360
454
|
from = min + 1
|
361
455
|
to = i - 1
|
@@ -373,10 +467,10 @@ module Numeron
|
|
373
467
|
|
374
468
|
# 可能性リストの更新
|
375
469
|
# 現在設定されている可能性リストと引数で渡された可能性リストの論理積をとる
|
376
|
-
# @param [Array]
|
377
|
-
def update_possibilities(
|
378
|
-
|
379
|
-
@possibilities = @possibilities.nil? ?
|
470
|
+
# @param [Array] list 可能性としてありえる数値リスト
|
471
|
+
def update_possibilities(list)
|
472
|
+
list.compact!
|
473
|
+
@possibilities = @possibilities.nil? ? list : list & @possibilities
|
380
474
|
end
|
381
475
|
end
|
382
476
|
end
|
data/lib/numeron/solver.rb
CHANGED
@@ -6,28 +6,150 @@ module Numeron
|
|
6
6
|
def initialize
|
7
7
|
@calc = Numeron::Calculator.new
|
8
8
|
@card_size = 3
|
9
|
-
@used_items = {
|
9
|
+
@used_items = {double: false, shuffle: false, change: false, target: false, high_and_low: false, slash: false}
|
10
10
|
end
|
11
11
|
|
12
12
|
def run
|
13
13
|
while 1
|
14
|
-
item
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
print "action (item|question|think|finish|help): "
|
15
|
+
input = STDIN.gets.chomp.downcase
|
16
|
+
if %w(0 i item).include?(input)
|
17
|
+
item
|
18
|
+
elsif %w(1 q question).include?(input)
|
19
|
+
question
|
20
|
+
elsif %w(2 t think).include?(input)
|
21
|
+
think
|
22
|
+
elsif %w(3 f finish).include?(input)
|
23
|
+
break
|
24
|
+
else
|
25
|
+
help
|
26
|
+
end
|
18
27
|
end
|
19
28
|
end
|
20
29
|
|
30
|
+
def help
|
31
|
+
puts "----- help messege -----"
|
32
|
+
puts "item ... using item, shortcut 0 or i"
|
33
|
+
puts "question ... call 3 digits numbers, shortcut 1 or q"
|
34
|
+
puts "think ... thinking answer, shortcut 2 or t"
|
35
|
+
puts "finish ... exit this console, shortcut 3 or f"
|
36
|
+
end
|
37
|
+
|
21
38
|
# アイテムの使用
|
22
39
|
def item
|
23
|
-
|
24
|
-
|
40
|
+
@used_items.each do |f|
|
41
|
+
next if f[1] == true
|
42
|
+
print "Using " + f[0].to_s + " ? [yes]: "
|
43
|
+
input = STDIN.gets.chomp.downcase
|
44
|
+
next if input != 'yes' && input != 'y'
|
45
|
+
send(f[0])
|
46
|
+
@used_items[f[0]] = true
|
47
|
+
break
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def double
|
52
|
+
position = nil
|
53
|
+
number = nil
|
54
|
+
|
55
|
+
while 1
|
56
|
+
print "Input open number: "
|
57
|
+
f = STDIN.gets.chomp.to_i
|
58
|
+
if f >= 0 && f <= 9
|
59
|
+
number = f
|
60
|
+
break
|
61
|
+
else
|
62
|
+
puts "Input error. Please input 0 to 9 number."
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
while 1
|
67
|
+
print "Input open position [0, 1, 2]: "
|
68
|
+
f = STDIN.gets.chomp.to_i
|
69
|
+
if f >= 0 && f <= 2
|
70
|
+
position = f
|
71
|
+
break
|
72
|
+
else
|
73
|
+
puts "Input error. Please input 0 or 1 or 2."
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
@calc.double(number, position)
|
78
|
+
end
|
79
|
+
|
80
|
+
def target
|
81
|
+
position = nil
|
82
|
+
number = nil
|
83
|
+
|
84
|
+
while 1
|
85
|
+
print "Input open number: "
|
86
|
+
f = STDIN.gets.chomp.to_i
|
87
|
+
if f >= 0 && f <= 9
|
88
|
+
number = f
|
89
|
+
break
|
90
|
+
else
|
91
|
+
puts "Input error. Please input 0 to 9 number."
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
while 1
|
96
|
+
puts "Input open position."
|
97
|
+
puts "If the enemy does not open card position, don't put anything"
|
98
|
+
print "Input [0, 1, 2, or empty]: "
|
99
|
+
f = STDIN.gets.chomp.to_i
|
100
|
+
position = f if f >= 0 && f <= 2
|
101
|
+
break
|
102
|
+
end
|
103
|
+
|
104
|
+
@calc.target(number, position)
|
105
|
+
end
|
106
|
+
|
107
|
+
def change
|
108
|
+
position = nil
|
109
|
+
is_high = nil
|
110
|
+
while 1
|
111
|
+
print "Input change position: "
|
112
|
+
f = STDIN.gets.chomp.to_i
|
113
|
+
if f >= 0 && f <= 2
|
114
|
+
position = f
|
115
|
+
break
|
116
|
+
else
|
117
|
+
puts "Input error. Please input 0 to 2 number."
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
while 1
|
122
|
+
print "Input high or low: "
|
123
|
+
f = STDIN.gets.chomp.downcase
|
124
|
+
if f == 'high' || f == 'low'
|
125
|
+
is_high = f == 'high'
|
126
|
+
break
|
127
|
+
else
|
128
|
+
puts "Input error. Please input high or low."
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
@calc.change(position, is_high)
|
133
|
+
end
|
134
|
+
|
135
|
+
def high_and_low
|
136
|
+
result = []
|
137
|
+
3.times do |i|
|
138
|
+
while 1
|
139
|
+
print "position " + i.to_s + " is high? [yes|no]: "
|
140
|
+
input = STDIN.gets.chomp.downcase
|
141
|
+
if ['yes', 'y', 'no', 'n'].include?(input)
|
142
|
+
result[i] = (input == 'yes' || input == 'y')
|
143
|
+
break
|
144
|
+
else
|
145
|
+
puts "Input error. Please input yes or no."
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
@calc.high_and_low(result)
|
25
150
|
end
|
26
151
|
|
27
152
|
def slash
|
28
|
-
print "\nUsing slash? [yes]"
|
29
|
-
f = STDIN.gets.chomp
|
30
|
-
return if f != 'yes' && f != 'y'
|
31
153
|
while 1
|
32
154
|
print "Input slash number: "
|
33
155
|
f =STDIN.gets.chomp.to_i
|
@@ -35,17 +157,10 @@ module Numeron
|
|
35
157
|
puts "Invalid slash number."
|
36
158
|
end
|
37
159
|
@calc.slash(f)
|
38
|
-
@used_items[:slash] = true
|
39
|
-
think
|
40
160
|
end
|
41
161
|
|
42
162
|
def shuffle
|
43
|
-
print "\nUsing shuffle? [yes]"
|
44
|
-
f = STDIN.gets.chomp
|
45
|
-
return if f != 'yes' && f != 'y'
|
46
163
|
@calc.shuffle
|
47
|
-
@used_items[:shuffle] = true
|
48
|
-
think
|
49
164
|
end
|
50
165
|
|
51
166
|
def question
|
@@ -121,17 +236,5 @@ module Numeron
|
|
121
236
|
end
|
122
237
|
puts "Possibilitiy list random: " + @calc.possibilities.sample.to_s
|
123
238
|
end
|
124
|
-
|
125
|
-
def finish
|
126
|
-
while 1
|
127
|
-
print "\nfinish? [yes] "
|
128
|
-
f = STDIN.gets.chomp
|
129
|
-
if(f == 'yes' || f == 'y')
|
130
|
-
exit
|
131
|
-
else
|
132
|
-
break
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
239
|
end
|
137
240
|
end
|
data/lib/numeron/version.rb
CHANGED
data/numeron.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Numeron::VERSION
|
9
9
|
gem.authors = ["kengos"]
|
10
10
|
gem.email = ["kengo@kengos.jp"]
|
11
|
-
gem.description = %q{numer0n
|
12
|
-
gem.summary = %q{numer0n solver}
|
11
|
+
gem.description = %q{numer0nの解を計算します。すべてのアイテム(ダブル, チェンジ, スラッシュ, シャッフル, ターゲット, ハイアンドロー)に対応。シミュレーター付き, Analyzerは適当)}
|
12
|
+
gem.summary = %q{numer0n solver.}
|
13
13
|
gem.homepage = "https://github.com/kengos/numeron"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
@@ -76,6 +76,36 @@ describe Numeron::Calculator do
|
|
76
76
|
calc.shuffle
|
77
77
|
calc.possibilities.should have(378).items
|
78
78
|
end
|
79
|
+
|
80
|
+
it "mays[0] is 3 and shuffle" do
|
81
|
+
calc.mays[0] = [3]
|
82
|
+
calc.shuffle
|
83
|
+
# 3が利用されているのは確定
|
84
|
+
calc.mays[0].should =~ (0..9).to_a
|
85
|
+
calc.mays[1].should =~ (0..9).to_a
|
86
|
+
calc.mays[2].should =~ (0..9).to_a
|
87
|
+
|
88
|
+
calc.possibilities.should have(216).items
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'using slash' do
|
92
|
+
it 'slash 2' do
|
93
|
+
calc.slash(2)
|
94
|
+
calc.possibilities.should have(48).items
|
95
|
+
calc.shuffle
|
96
|
+
calc.possibilities.should have(48).items
|
97
|
+
end
|
98
|
+
|
99
|
+
it '1e1b, slash 2, shuffle' do
|
100
|
+
calc.input('123', 1, 1)
|
101
|
+
calc.possibilities.should have(42).items
|
102
|
+
calc.slash(2)
|
103
|
+
calc.possibilities.should =~ %w(021 102 243 324)
|
104
|
+
calc.shuffle
|
105
|
+
# 数字の組み合わせは 012 or 234のみなので、 (3 * 2 * 1) * 2 = 12パターン
|
106
|
+
calc.possibilities.should =~ %W(021 012 201 210 102 120 243 234 342 324 432 423)
|
107
|
+
end
|
108
|
+
end
|
79
109
|
end
|
80
110
|
|
81
111
|
describe '#slash' do
|
@@ -122,6 +152,126 @@ describe Numeron::Calculator do
|
|
122
152
|
end
|
123
153
|
end
|
124
154
|
|
155
|
+
describe '#change' do
|
156
|
+
it '0, true' do
|
157
|
+
calc.change(0, true)
|
158
|
+
calc.mays[0].should == (5..9).to_a
|
159
|
+
end
|
160
|
+
|
161
|
+
it '1, false' do
|
162
|
+
calc.change(1, false)
|
163
|
+
calc.mays[1].should == (0..4).to_a
|
164
|
+
end
|
165
|
+
|
166
|
+
it '234(0e3b), change(0, false)' do
|
167
|
+
calc.input('234', 0, 3) # answer 342
|
168
|
+
calc.change(0, false) # answer 142
|
169
|
+
calc.mays[0].should =~ [0, 1]
|
170
|
+
calc.mays[1].should =~ [2, 4]
|
171
|
+
calc.mays[2].should =~ [2, 3]
|
172
|
+
calc.possibilities.should =~ %w(023 042 043 123 142 143)
|
173
|
+
end
|
174
|
+
|
175
|
+
it '345(0e3b), change(0, false), shuffle' do
|
176
|
+
calc.input('345', 0, 3) # answer 453
|
177
|
+
calc.change(0, false) # 253
|
178
|
+
calc.mays[0].should == [0, 1, 2]
|
179
|
+
calc.mays[1].should == [5]
|
180
|
+
calc.mays[2].should == [3, 4]
|
181
|
+
calc.possibilities.should =~ %w(054 053 153 154 253 254)
|
182
|
+
calc.shuffle
|
183
|
+
calc.mays[0].should =~ [0, 1, 2, 3, 4, 5]
|
184
|
+
calc.mays[1].should =~ [0, 1, 2, 3, 4, 5]
|
185
|
+
calc.mays[2].should =~ [0, 1, 2, 3, 4, 5]
|
186
|
+
# 5確定なので、 3 * 5 * 4 = 60 (5の位置3箇所) * (5を除く可能性数) * (5を除く可能性数 - 1つ前の数値)
|
187
|
+
calc.possibilities.should have(60).items
|
188
|
+
end
|
189
|
+
|
190
|
+
it '456(0e3b), change(0, false)' do
|
191
|
+
calc.input('456', 0, 3) # answer 564
|
192
|
+
calc.change(2, false)
|
193
|
+
calc.mays[0].should == [5]
|
194
|
+
calc.mays[1].should == [6]
|
195
|
+
calc.mays[2].should == [0, 1, 2, 3]
|
196
|
+
calc.possibilities.should =~ %w(560 561 562 563)
|
197
|
+
end
|
198
|
+
|
199
|
+
it '1e2b, 0, false' do
|
200
|
+
calc.input('123', 1, 2) # 132
|
201
|
+
calc.change(0, false) # 432
|
202
|
+
calc.mays[0].should == [0, 4]
|
203
|
+
calc.mays[1].should == [1, 2, 3]
|
204
|
+
calc.mays[2].should == [1, 2, 3]
|
205
|
+
calc.possibilities.should =~ %w(012 013 021 023 031 032 412 413 421 423 431 432)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe '#high_and_low' do
|
210
|
+
it 'simple' do
|
211
|
+
calc.high_and_low([true, false, true])
|
212
|
+
calc.mays[0].should =~ [5, 6, 7, 8, 9]
|
213
|
+
calc.mays[1].should =~ [0, 1, 2, 3, 4]
|
214
|
+
calc.mays[2].should =~ [5, 6, 7, 8, 9]
|
215
|
+
calc.possibilities.should have(100).items
|
216
|
+
end
|
217
|
+
|
218
|
+
it '345(0e3b), high_and_low' do
|
219
|
+
calc.input('345', 0, 3) # 4 5 3
|
220
|
+
calc.high_and_low([false, true, false])
|
221
|
+
calc.mays[0].should =~ [4]
|
222
|
+
calc.mays[1].should =~ [5]
|
223
|
+
calc.mays[2].should =~ [3]
|
224
|
+
calc.possibilities.should == %w(453)
|
225
|
+
end
|
226
|
+
|
227
|
+
it '345(1e2b), high_and_low' do
|
228
|
+
calc.input('354', 1, 2) # 4 5 3
|
229
|
+
calc.high_and_low([false, true, false])
|
230
|
+
calc.mays[0].should =~ [3, 4]
|
231
|
+
calc.mays[1].should =~ [5]
|
232
|
+
calc.mays[2].should =~ [3, 4]
|
233
|
+
calc.possibilities.should == %w(453)
|
234
|
+
end
|
235
|
+
|
236
|
+
it '345(0e1b), high_and_low' do
|
237
|
+
calc.input('354', 0, 1) # 4 6 2
|
238
|
+
calc.high_and_low([false, true, false])
|
239
|
+
calc.mays[0].should =~ [0, 1, 2, 4]
|
240
|
+
calc.mays[1].should =~ [6, 7, 8, 9]
|
241
|
+
calc.mays[2].should =~ [0, 1, 2, 3]
|
242
|
+
|
243
|
+
# [4] * [6, 7, 8, 9] * [0, 1, 2] + [0, 1, 2] * [6, 7, 8, 9] * [3] = 4 * 3 * 2 = 24
|
244
|
+
calc.possibilities.should have(24).items
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe '#target' do
|
249
|
+
it 'simple' do
|
250
|
+
calc.target(0, 0)
|
251
|
+
calc.mays[0].should =~ [0]
|
252
|
+
calc.mays[1].should =~ (1..9).to_a
|
253
|
+
calc.mays[2].should =~ (1..9).to_a
|
254
|
+
calc.possibilities.should have(72).items
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'target(0, nil)' do
|
258
|
+
calc.target(0)
|
259
|
+
calc.mays[0].should =~ (1..9).to_a
|
260
|
+
calc.mays[1].should =~ (1..9).to_a
|
261
|
+
calc.mays[2].should =~ (1..9).to_a
|
262
|
+
calc.possibilities.should have(504).items
|
263
|
+
end
|
264
|
+
|
265
|
+
it '123(0e3b), target(1, 1)' do
|
266
|
+
calc.input('123', 0, 3)
|
267
|
+
calc.target(1, 1)
|
268
|
+
calc.mays[0].should =~ [3]
|
269
|
+
calc.mays[1].should =~ [1]
|
270
|
+
calc.mays[2].should =~ [2]
|
271
|
+
calc.possibilities.should =~ %w(312)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
125
275
|
describe "scenario" do
|
126
276
|
it "1e0b, 1e2b" do
|
127
277
|
calc.input('348', 1, 0)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numeron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: numer0n
|
14
|
+
description: numer0nの解を計算します。すべてのアイテム(ダブル, チェンジ, スラッシュ, シャッフル, ターゲット, ハイアンドロー)に対応。シミュレーター付き,
|
15
|
+
Analyzerは適当)
|
15
16
|
email:
|
16
17
|
- kengo@kengos.jp
|
17
18
|
executables: []
|
@@ -60,7 +61,7 @@ rubyforge_project:
|
|
60
61
|
rubygems_version: 1.8.24
|
61
62
|
signing_key:
|
62
63
|
specification_version: 3
|
63
|
-
summary: numer0n solver
|
64
|
+
summary: numer0n solver.
|
64
65
|
test_files:
|
65
66
|
- spec/lib/numeron/analyzer_spec.rb
|
66
67
|
- spec/lib/numeron/calculator_spec.rb
|