-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeprechaun.rb
1051 lines (878 loc) · 23 KB
/
Leprechaun.rb
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
ul = "_______________________________________________________________\n" # underline
print "\n"
5.times do
print "*"
sleep(0.05)
print "$"
sleep(0.05)
end
print " LEPRECHAUN "
sleep(0.05)
5.times do
print "*"
sleep(0.05)
print "$"
sleep(0.05)
end
print "\n version 0.5b
coded by Milo_Draco\n"
sleep(0.5)
loop do
print "
____________________________
SYSTEMS: |
1. SIMPLE |
2. DELTA |
3. SMART ANALYSIS |
4. BALANCED |
5. LEPRECHAUN |
============================|
TOOLS: |
6. CHECK RESULTS |
7. CHECK FILES |
8. DELETE SAVED GAMES |
9. INSTRUCTIONS |
============================'
Please, enter option: "
o = gets.chomp
if o == "1" # GENERATE NEW GAMES *****************************************************************
print "\nPlease, insert the lowest value: "
min = (gets.chomp).to_i
print "Please, insert the highest value: "
max = (gets.chomp).to_i
print "Please, insert and the total amount of sorted numbers: "
num = (gets.chomp).to_i
print "Please, insert and the total number of games: "
g = (gets.chomp).to_i
print "Please, insert and the numbers to avoid (separate by commas) or press ENTER: "
avoid = (gets.chomp).split(",")
for v in (0..avoid.length-1)
avoid[v] = avoid[v].to_i
end
print "Please, insert and the numbers to include (separate by commas) or press ENTER: "
include = (gets.chomp).split(",")
for v in (0..include.length-1)
include[v] = include[v].to_i
end
if File.file?('games.txt') # creating array of stored games
print "Avoid stored games (Y/N): "
cg = (gets.chomp).upcase
if cg == "Y"
games = []
File.readlines('games.txt').each do |line|
line = line[1..-2]
array = line.split(",")
(array.length).times do
array << array[0].to_i
array.shift
end
games << array
end
end
end
puts "\nMinimum = #{min}", "Maximum = #{max}", "Numbers = #{num}", "Avoid: #{avoid}", "Include: #{include}", "\n"
sleep(1)
pgames = [] # creating the array of avoided combinations from txt file:
if File.file?('avoid.txt')
File.readlines('avoid.txt').each do |line|
array = line.split(" ")
(array.length).times do
array << array[0].to_i
array.shift
end
pgames << array
end
end
file = File.new("games.txt", 'a') # creating file of sorted games
c = 1 # game counter
allgames = []
while allgames.length < g do
eq = false
prem = [] + include
x = prem.length # counter
while x < num
y = rand(min..max) # sorted value
if !prem.include?(y) && !avoid.include?(y)
prem << y
x += 1
end
end
prem.sort!
for z in (0..allgames.length-1) # checking if the game is duplicated
eq = true if prem == allgames[z]
break if eq == true
end
redo if eq == true
for a in (0..pgames.length-1) # checking avoid.txt duplicates
eq = true if prem == pgames[a]
break if eq == true
end
redo if eq == true
if games != nil
for a in (0..games.length-1) # checking games.txt duplicates
eq = true if prem == games[a]
break if eq == true
end
end
redo if eq == true
allgames << prem
puts "Game ##{c}"
print prem, "\n \n"
file.write(prem, "\n")
c += 1
end
file.close
puts "\nAll games created successfully and written to file <<games.txt>>\n\n"
gets
puts ul
elsif o == "6" # CHECK RESULTS *************************************************************************
print "\nPlease, insert the numbers (separate by commas): "
game = (gets.chomp).split(",")
(game.length).times do
game << game[0].to_i
game.shift
end
if File.file?('games.txt')
games = []
File.readlines('games.txt').each do |line|
line = line[1..-2]
array = line.split(",")
(array.length).times do
array << array[0].to_i
array.shift
end
games << array
end
else
print "\nERROR: there is no <<games.txt>> file!\n\n"
exit
end
win = [0, 0, 0, 0]
nwin = [[], [], [], []]
ng = 0
games.each do |gx| # comparing games
w = 0
ng += 1
game.each do |n|
w += 1 if gx.include?(n)
end
if w == game.length
win[0] += 1
nwin[0] << ng
elsif w == game.length-1
win[1] += 1
nwin[1] << ng
elsif w == game.length-2
win[2] += 1
nwin[2] << ng
elsif w == game.length-3
win[3] += 1
nwin[3] << ng
end
end
puts "\n#{win[0]} game(s) matching #{game.length} number(s): #{nwin[0]}
#{win[1]} game(s) matching #{game.length-1} number(s): #{nwin[1]}
#{win[2]} game(s) matching #{game.length-2} number(s): #{nwin[2]}
#{win[3]} game(s) matching #{game.length-3} number(s): #{nwin[3]}\n\n"
gets
puts ul
elsif o == "7" # CHECK FILES *********************************************************************
if File.file?('games.txt') # creating array of stored games
games = []
File.readlines('games.txt').each do |line|
line = line[1..-2]
array = line.split(",")
(array.length).times do
array << array[0].to_i
array.shift
end
games << array
end
end
if File.file?('avoid.txt') # creating the array of avoided combinations from txt file:
pgames = []
File.readlines('avoid.txt').each do |line|
array = line.split(" ")
(array.length).times do
array << array[0].to_i
array.shift
end
pgames << array
end
end
puts "\nStored games (<<games.txt>>) = #{games.length}" if games != nil
puts "\nAvoided or PD (<<avoid.txt>>) = #{pgames.length}" if pgames != nil
print "\n"
gets
puts ul
elsif o == "8" # DELETE GAMES *********************************************************************
if File.exists?('games.txt')
print "\nAre you sure? (Y/N) "
del = (gets.chomp).upcase
File.delete('games.txt') if del=="Y"
else
puts "\nERROR: there is no <<games.txt>> file."
exit
end
puts ul
elsif o == "9" # INSTRUCTIONS *******************************************************************************
puts "\nRandom numbers are between minimum and maximum values.
All the games are stored in a TXT file (<<games.txt>>).
You can insert avoided games in a TXT file, just insert one combination per
line and separate numbers using TAB. Name the file <<avoid.txt>>.
Check if you have won using option 2.
SIMPLE SYSTEM: no file required. All kind of games supported. You
can avoid or include specific numbers.
DELTA SYSTEM: no file required. Only games up to 8 numbers.
SMART ANALYSIS SYSTEM: 5 or more past drawings required (in the
<<avoid.txt>>). All kind of games supported.
BALANCED SYSTEM: no file required. All kind of games supported. You
can avoid or include specific numbers.
LEPRECHAUN SYSTEM: 5 or more past drawings required and only games
up to 8 numbers. It's the slowest system.
Files:
<<avoid.txt>> => list of combinations to avoid or past drawings (recent
drawings should be the last).
<<games.txt>> => list of saved games.\n\n"
gets
puts ul
elsif o == "3" # SMART ANALYSIS SYSTEM ******************************************************************
print "\nPlease, insert the lowest value: "
min = (gets.chomp).to_i
print "Please, insert the highest value: "
max = (gets.chomp).to_i
print "Please, insert and the total amount of sorted numbers: "
num = (gets.chomp).to_i
print "Please, insert and the total number of games: "
g = (gets.chomp).to_i
games = nil # creating array of stored games
if File.file?('games.txt')
print "Avoid stored games (Y/N): "
cg = (gets.chomp).upcase
if cg == "Y"
games = []
File.readlines('games.txt').each do |line|
line = line[1..-2]
array = line.split(",")
(array.length).times do
array << array[0].to_i
array.shift
end
games << array
end
end
end
pgames = [] # creating the array of avoided combinations from txt file:
if File.file?('avoid.txt')
File.readlines('avoid.txt').each do |line|
array = line.split(" ")
(array.length).times do
array << array[0].to_i
array.shift
end
pgames << array
end
else
puts "\nERROR: past drawings required!\n"
exit
end
if pgames.length < 5
puts "\nERROR: at least 5 past drawings required!\n"
exit
end
puts "\nMinimum = #{min}", "Maximum = #{max}", "Numbers = #{num}", "Past drawings = #{pgames.length}"
chances = {} # counting times of each number
chances.default = 0
for x in (min..max)
pgames.each do |y|
chances[x] += 1 if y.include?(x)
end
end
puts "PD range = #{chances.keys[0]} - #{chances.keys[-1]}", "\n"
if chances.length < max
puts "ERROR: past drawings must include wider range of values!\n\n"
exit
end
sleep(1)
mod = [10, 20, 30, 40, 50] # modifiers
(chances.keys).each do |mx| # aplying chances according to the last 5 games
mult = 100.0 # multiplier
if pgames[-5].include?(mx)
mult -= mod[0]
else
mult += mod[0]
end
if pgames[-4].include?(mx)
mult -= mod[1]
else
mult += mod[1]
end
if pgames[-3].include?(mx)
mult -= mod[2]
else
mult += mod[2]
end
if pgames[-2].include?(mx)
mult -= mod[3]
else
mult += mod[3]
end
if pgames[-1].include?(mx) # most recent result/game
mult -= mod[4]
else
mult += mod[4]
end
chances[mx] = (chances[mx] * (mult/100)).round(0)
chances[mx] = 1 if chances[mx] < 1
end
total = 0 # total numbers in avoid.txt file
(chances.values).each do |z|
total = total + z
end
startx = 0 # starting point for each value in dice
dice = {} # dice for random number
for n in (min..max)
dice[n] = [startx, startx + chances[n]] # starting point and last point for each number between min and max
startx += chances[n]
end
c = 1 # game counter
rn = nil # random number
file = File.new("games.txt", 'a') # creating file of sorted games
allgames = []
while allgames.length < g do
eq = false
prem = []
num.times do
rn = rand(1..dice.values[-1][1])
rnf=nil # random number final
(dice.keys).each do |xxx|
rnf = xxx if rn > dice[xxx][0] && rn <= dice[xxx][1]
break if rnf != nil
end
redo if prem.include?(rnf)
prem << rnf
end
prem.sort!
for z in (0..allgames.length-1) # checking if the game is duplicated
eq = true if prem == allgames[z]
break if eq == true
end
redo if eq == true
for a in (0..pgames.length-1) # checking avoid.txt duplicates
eq = true if prem == pgames[a]
break if eq == true
end
redo if eq == true
if games != nil
for a in (0..games.length-1) # checking games.txt duplicates
eq = true if prem == games[a]
break if eq == true
end
end
redo if eq == true
allgames << prem
puts "Game ##{c}"
print prem, "\n \n"
file.write(prem, "\n")
c += 1
end
file.close
puts "\nAll games created successfully and written to file <<games.txt>>\n\n"
#print "__________________________________________
#
#values = ", chances.keys, "\n\n", "chances = ", chances, "\n\n", "sum = ", total, "\n\n", "table = ", dice, "\n\n"
gets
puts ul
elsif o == "2" # DELTA SYSTEM *********************************************************************************
print "\nPlease, insert the lowest value: "
min = (gets.chomp).to_i
print "Please, insert the highest value: "
max = (gets.chomp).to_i
print "Please, insert and the total amount of sorted numbers: "
num = (gets.chomp).to_i
if num > 8
puts "\nERROR: maximum value is 8!\n"
exit
end
print "Please, insert and the total number of games: "
g = (gets.chomp).to_i
games = nil # creating array of stored games
if File.file?('games.txt')
print "Avoid stored games (Y/N): "
cg = (gets.chomp).upcase
print "\n"
if cg == "Y"
games = []
File.readlines('games.txt').each do |line|
line = line[1..-2]
array = line.split(",")
(array.length).times do
array << array[0].to_i
array.shift
end
games << array
end
end
end
pgames = [] # creating the array of avoided combinations from txt file:
File.readlines('avoid.txt').each do |line|
array = line.split(" ")
(array.length).times do
array << array[0].to_i
array.shift
end
pgames << array
end
puts "\nMinimum = #{min}", "Maximum = #{max}", "Numbers = #{num}", "\n"
sleep(1)
file = File.new("games.txt", 'a') # creating file of sorted games
c = 1 # game counter
allgames = []
tsd = (max/6).round(0) # threshold
while allgames.length < g do
eq = false
delta = []
delta << rand(min..(max/10.0).round(0))
delta << rand(tsd-1..tsd+1) if num > 1
rest = num - delta.length
(rest/2).times do
if min > 0
delta << rand(min..tsd)
else
delta << rand(1..tsd)
end
end
(rest/2).times do
delta << rand(tsd..((max/10.0).round(0))*3)
end
sum = 0
delta.each do |dx|
sum += dx
end
(rest%2).times do
if min > 0
vy = rand(min..max-sum)
vy = min if vy == nil || vy < min
else
vy = rand(1..max-sum)
vy = 1 if vy == nil || vy < min
end
delta << vy
end
sum = 0
delta.each do |dx|
sum += dx
end
if sum > max
delta << delta.max - (sum - max) - rand(0..max/10)
delta.delete(delta.max)
end
redo if delta.min < min || delta.count(0) > 1 || delta.length != num # redo if minimum is below MIN or if there is more than one 0
delta.shuffle!
if delta.include?(0)
delta.delete(0)
delta.unshift(0)
end
prem = []
sum = 0
delta.each do |dx|
sum += dx
prem << sum
end
prem.sort!
for z in (0..allgames.length-1) # checking if the game is duplicated
eq = true if prem == allgames[z]
break if eq == true
end
redo if eq == true
for a in (0..pgames.length-1) # checking avoid.txt duplicates
eq = true if prem == pgames[a]
break if eq == true
end
redo if eq == true
if games != nil
for a in (0..games.length-1) # checking games.txt duplicates
eq = true if prem == games[a]
break if eq == true
end
end
redo if eq == true
allgames << prem
puts "Game ##{c}"
print prem, "\n \n"
file.write(prem, "\n")
c += 1
end
file.close
puts "\nAll games created successfully and written to file <<games.txt>>\n\n"
gets
puts ul
elsif o.upcase == "EXIT" # EXIT **************************************************************
exit
elsif o == "5" # LEPRECHAUN SYSTEM **************************************************************
print "\nPlease, insert the lowest value: "
min = (gets.chomp).to_i
print "Please, insert the highest value: "
max = (gets.chomp).to_i
print "Please, insert and the total amount of sorted numbers: "
num = (gets.chomp).to_i
if num > 8
puts "\nERROR: maximum value is 8!\n"
exit
end
print "Please, insert and the total number of games: "
g = (gets.chomp).to_i
games = nil # creating array of stored games
if File.file?('games.txt')
print "Avoid stored games (Y/N): "
cg = (gets.chomp).upcase
if cg == "Y"
games = []
File.readlines('games.txt').each do |line|
line = line[1..-2]
array = line.split(",")
(array.length).times do
array << array[0].to_i
array.shift
end
games << array
end
end
end
if g > 3000
print "Enable temperature cooldown (Y/N): "
cd = (gets.chomp).upcase
end
pgames = [] # creating the array of avoided combinations from txt file:
if File.file?('avoid.txt')
File.readlines('avoid.txt').each do |line|
array = line.split(" ")
(array.length).times do
array << array[0].to_i
array.shift
end
pgames << array
end
else
puts "\nERROR: past drawings required!\n"
exit
end
if pgames.length < 5
puts "\nERROR: at least 5 past drawings required!\n"
exit
end
puts "\nMinimum = #{min}", "Maximum = #{max}", "Numbers = #{num}", "Past drawings = #{pgames.length}"
chances = {} # counting times of each number
chances.default = 0
for x in (min..max)
pgames.each do |y|
chances[x] += 1 if y.include?(x)
end
end
puts "PD range = #{chances.keys[0]} - #{chances.keys[-1]}", "\n"
if chances.length < max
puts "ERROR: past drawings must include wider range of values!\n\n"
exit
end
sleep(1)
mod = [10, 20, 30, 40, 50] # modifiers
(chances.keys).each do |mx| # aplying chances according to the last 5 games
mult = 100.0 # multiplier
if pgames[-5].include?(mx)
mult -= mod[0]
else
mult += mod[0]
end
if pgames[-4].include?(mx)
mult -= mod[1]
else
mult += mod[1]
end
if pgames[-3].include?(mx)
mult -= mod[2]
else
mult += mod[2]
end
if pgames[-2].include?(mx)
mult -= mod[3]
else
mult += mod[3]
end
if pgames[-1].include?(mx) # most recent result/game
mult -= mod[4]
else
mult += mod[4]
end
chances[mx] = (chances[mx] * (mult/100))
end
puts "Please, wait. This can take several minutes."
t = Time.now if cd == "Y" # initial time
scores = {} # summing scores of each game
tsd = (max/6).round(0) # threshold
slp = 20 # time of cooling down
len = 0 # counter
while scores.length < g*2 do # creating the double of needed games
eq = false
delta = []
delta << rand(min..(max/10.0).round(0)) # drawing 1st number
delta << rand(tsd-1..tsd+1) if num > 1 # drawing 2nd number
rest = num - delta.length # calculating left numbers
(rest/2).times do # drawing half of left numbers (below threshold)
if min > 0
delta << rand(min..tsd)
else
delta << rand(1..tsd)
end
end
(rest/2).times do # drawing half of left numbers (above threshold)
delta << rand(tsd..((max/10.0).round(0))*3)
end
sum = 0
delta.each do |dx| # summing all numbers
sum += dx
end
(rest%2).times do # drawing last number if NUM is odd
if min > 0
vy = rand(min..max-sum)
vy = min if vy == nil || vy < min
else
vy = rand(1..max-sum)
vy = 1 if vy == nil || vy < min
end
delta << vy
end
sum = 0
delta.each do |dx|
sum += dx
end
if sum > max # sum must be less or equal to maximum number
delta << delta.max - (sum - max) - rand(0..max/10)
delta.delete(delta.max)
end
redo if delta.min < min || delta.count(0) > 1 || delta.length != num # redo if minimum is below MIN or if there is more than one 0
delta.shuffle!
if delta.include?(0) # 0 must be the first
delta.delete(0)
delta.unshift(0)
end
prem = []
sum = 0
delta.each do |dx|
sum += dx
prem << sum
end
prem.sort!
for z in (0..(scores.values).length-1) # checking if the game is duplicated
eq = true if prem == scores.values[z]
break if eq == true
end
redo if eq == true
for a in (0..pgames.length-1) # checking avoid.txt duplicates
eq = true if prem == pgames[a]
break if eq == true
end
redo if eq == true
if games != nil
for a in (0..games.length-1) # checking games.txt duplicates
eq = true if prem == games[a]
break if eq == true
end
end
redo if eq == true
even = 0
odd = 0
lo = 0
hi = 0
prem.each do |e| # calculating even, odd, low and high numbers
if e % 2 == 0
even += 1
else
odd += 1
end
if e <= (max - min)/2.0
lo += 1
else
hi += 1
end
end
scr = 0
prem.each do |e| # calculating score of drawing
scr += chances[e]
end
if even - odd <= 1 && even - odd >= -1
scr *= 1.2
elsif even == num || odd == num
scr *= 0.5
end
if lo - hi <= 1 && lo - hi >= -1
scr *= 1.2
elsif lo == num || hi == num
scr *= 0.5
end
scores[scr] = prem
if scores.length/2 > len
print scores.length/2, "."
len = scores.length/2
end
if cd == "Y" # cooldown
if Time.now >= t + 500
print "COOLING DOWN."
sleep(slp)
t = Time.now
slp += 1
end
end
end
scores = scores.sort
scores.shift(scores.length/2)
c = 1 # game counter
allgames = []
file = File.new("games.txt", 'a') # creating file of sorted games
puts "\n\n"
scores.each do |gm|
allgames << gm[1]
puts "Game ##{c}"
print gm[1], "\n \n"
file.write(gm[1], "\n")
c += 1
end
file.close
puts "\nAll games created successfully and written to file <<games.txt>>\n\n"
gets
puts ul
elsif o == "4" # BALANCED SYSTEM *************************************************************
print "\nPlease, insert the lowest value: "
min = (gets.chomp).to_i
print "Please, insert the highest value: "
max = (gets.chomp).to_i
print "Please, insert and the total amount of sorted numbers: "
num = (gets.chomp).to_i
print "Please, insert and the total number of games: "
g = (gets.chomp).to_i
print "Please, insert and the numbers to avoid (separate by commas) or press ENTER: "
avoid = (gets.chomp).split(",")
for v in (0..avoid.length-1)
avoid[v] = avoid[v].to_i
end
print "Please, insert and the numbers to include (separate by commas) or press ENTER: "
include = (gets.chomp).split(",")
for v in (0..include.length-1)
include[v] = include[v].to_i
end
if File.file?('games.txt') # creating array of stored games
print "Avoid stored games (Y/N): "
cg = (gets.chomp).upcase
if cg == "Y"
games = []
File.readlines('games.txt').each do |line|
line = line[1..-2]
array = line.split(",")
(array.length).times do
array << array[0].to_i
array.shift
end
games << array
end
end
end
puts "\nMinimum = #{min}", "Maximum = #{max}", "Numbers = #{num}", "Avoid: #{avoid}", "Include: #{include}", "\n"
sleep(1)
pgames = [] # creating the array of avoided combinations from txt file:
if File.file?('avoid.txt')
File.readlines('avoid.txt').each do |line|
array = line.split(" ")
(array.length).times do
array << array[0].to_i
array.shift
end
pgames << array
end
end
file = File.new("games.txt", 'a') # creating file of sorted games
c = 1 # game counter
allgames = []
evenl = []
oddl = []
evenh = []
oddh = []
for y in (min..max)
if y <= (max - min)/2.0
if y % 2 == 0
evenl << y
else
oddl << y
end
else
if y % 2 == 0
evenh << y
else
oddh << y
end
end
end
evenl -= avoid + include
oddl -= avoid + include
evenh -= avoid + include
oddh -= avoid + include
while allgames.length < g do
eq = false
prem = [] + include
while prem.length < num
((num - prem.length)/4).times do
if evenl.length > 0
prem << evenl[rand(0..evenl.length - 1)]
evenl -= prem
end
if oddl.length > 0
prem << oddl[rand(0..oddl.length - 1)]
oddl -= prem
end
if evenh.length > 0
prem << evenh[rand(0..evenh.length - 1)]
evenh -= prem
end
if oddh.length > 0
prem << oddh[rand(0..oddh.length - 1)]
oddh -= prem
end
end