I've played a little more with your code.

https://github.com/abinoam/reralottery/blob/master/lottery.rb

I'll touch it again when I have more free time.

You can see the commits individually at
https://github.com/abinoam/reralottery/commits/master

Abinoam Jr.

On Mon, Dec 2, 2013 at 3:58 PM, Abinoam Jr. <abinoam / gmail.com> wrote:
> Hi Re Ra,
>
> I understand your anxiety to see the result you're searching for.
> But, your code is not well structured (IMHO).
> This makes it difficult to "evolute" to what you want.
>
> For satisfying your needs you can ("uglyly") do like bellow.
> I tried to touch your code the less I could, so I tried to preserve
> all the variable names, and add only the necessary lines to make it
> work.
>
> But... there's much room for improvement.
>
> Basically I added....
>
> tkt_amount =3D rand(10) + 1 # (1..10)
>
> tkt_amount.times do
>
>   ticket1 =3D rand(99999)+1
>   quantity1 =3D rand(10)+1
>
> The complete code is bellow.
> Is that what you wanted to do?
>
> #!/usr/bin/env ruby
> #coding: utf-8
>
> #ticket database
> ticket1 =3D 23453 #ticket number
> quantity1 =3D 3  #quantity bought
>
> puts "\n" #break
>
> #lottery draw
> list =3D []
> (list << '%05i' % (rand(99999)+1)).uniq! while list.length < 5
> number1, number2, number3, number4, number5 =3D list
> serie1, serie2, serie3, serie4, serie5 =3D Array.new(5) { rand(180)+1 }
> number6 =3D number1.to_i - 1
> number7 =3D number1.to_i + 1
> number8 =3D number2.to_i - 1
> number9 =3D number2.to_i + 1
> number10 =3D number3.to_i - 1
> number11 =3D number3.to_i + 1
> number12 =3D number1.to_i / 100
> number13 =3D number2.to_i / 100
> number14 =3D number3.to_i / 100
> number15 =3D number4.to_i / 100
> number16 =3D number5.to_i / 100
> number17 =3D number1.to_i % 10
> puts list
>
> puts "\n" #break
>
>
> #winnings
> def show_results(a, b)
>   puts "Ticket ##{a.to_s.rjust(5, '0')} won =80#{b}."
> end
>
> tkt_amount =3D rand(10) + 1 # (1..10)
>
> tkt_amount.times do
>
>   ticket1 =3D rand(99999)+1
>   quantity1 =3D rand(10)+1
>
>   #prizes
>   prize1 =3D 400000 * quantity1 #1st
>   prize2 =3D 125000 * quantity1 #2n
>   prize3 =3D 50000 * quantity1 #3rd
>   prize4 =3D 20000 * quantity1 #4th
>   prize5 =3D 2000 * quantity1 #Consolation1
>   prize6 =3D 1250 * quantity1 #Consolation2
>   prize7 =3D 960 * quantity1 #Consolation3
>   prize8 =3D 100 * quantity1 #Cantena
>   prize9 =3D 20 * quantity1 #Reintegro
>
>   if ticket1 =3D=3D number1.to_i
>     show_results(ticket1, prize1)
>   end
>
>   if ticket1 =3D=3D number2.to_i
>     show_results(ticket1, prize2)
>   end
>
>   if ticket1 =3D=3D number3.to_i
>     show_results(ticket1, prize3)
>   end
>
>   if ticket1 =3D=3D number4.to_i or
>     ticket1 =3D=3D number5.to_i
>     show_results(ticket1, prize4)
>   end
>
>   if ticket1 =3D=3D number6.to_i or
>     ticket1 =3D=3D number7.to_i
>     show_results(ticket1, prize5)
>   end
>
>   if ticket1 =3D=3D number8.to_i or
>     ticket1 =3D=3D number9.to_i
>     show_results(ticket1, prize6)
>   end
>
>   if ticket1 =3D=3D number10.to_i or
>     ticket1 =3D=3D number11.to_i
>     show_results(ticket1, prize7)
>   end
>
>   if ticket1.to_i / 100 =3D=3D number12.to_i or
>     ticket1.to_i / 100 =3D=3D number13.to_i or
>     ticket1.to_i / 100 =3D=3D number14.to_i or
>     ticket1.to_i / 100 =3D=3D number15.to_i or
>     ticket1.to_i / 100 =3D=3D number16.to_i
>     show_results(ticket1, prize8)
>   end
>
>   if ticket1.to_i % 10 =3D=3D number17.to_i
>     show_results(ticket1, prize9)
>   end
> end
>
> Was this what you wanted?
>
> Abinoam Jr.
>
> On Mon, Dec 2, 2013 at 9:48 AM, Re Ra <lists / ruby-forum.com> wrote:
>> So, I updated the coda a bit -
>> #ticket database
>> ticket1 =3D 23453 #ticket number
>> quantity1 =3D 3  #quantity bought
>>
>> puts "\n" #break
>>
>> #lottery draw
>> list =3D []
>> (list << '%05i' % (rand(99999)+1)).uniq! while list.length < 5
>> number1, number2, number3, number4, number5 =3D list
>> serie1, serie2, serie3, serie4, serie5 =3D Array.new(5) { rand(180)+1 }
>> number6 =3D number1.to_i - 1
>> number7 =3D number1.to_i + 1
>> number8 =3D number2.to_i - 1
>> number9 =3D number2.to_i + 1
>> number10 =3D number3.to_i - 1
>> number11 =3D number3.to_i + 1
>> number12 =3D number1.to_i / 100
>> number13 =3D number2.to_i / 100
>> number14 =3D number3.to_i / 100
>> number15 =3D number4.to_i / 100
>> number16 =3D number5.to_i / 100
>> number17 =3D number1.to_i % 10
>> puts list
>>
>> puts "\n" #break
>>
>> #prizes
>> prize1 =3D 400000 * quantity1 #1st
>> prize2 =3D 125000 * quantity1 #2n
>> prize3 =3D 50000 * quantity1 #3rd
>> prize4 =3D 20000 * quantity1 #4th
>> prize5 =3D 2000 * quantity1 #Consolation1
>> prize6 =3D 1250 * quantity1 #Consolation2
>> prize7 =3D 960 * quantity1 #Consolation3
>> prize8 =3D 100 * quantity1 #Cantena
>> prize9 =3D 20 * quantity1 #Reintegro
>>
>> #winnings
>> def show_results(a, b)
>>   puts "Ticket ##{a.to_s.rjust(5, '0')} won =80#{b}."
>> end
>>
>> if ticket1 =3D=3D number1.to_i
>>   show_results(ticket1, prize1)
>> end
>>
>> if ticket1 =3D=3D number2.to_i
>>   show_results(ticket1, prize2)
>> end
>>
>> if ticket1 =3D=3D number3.to_i
>>   show_results(ticket1, prize3)
>> end
>>
>> if ticket1 =3D=3D number4.to_i or
>>   ticket1 =3D=3D number5.to_i
>>   show_results(ticket1, prize4)
>> end
>>
>> if ticket1 =3D=3D number6.to_i or
>>   ticket1 =3D=3D number7.to_i
>>   show_results(ticket1, prize5)
>> end
>>
>> if ticket1 =3D=3D number8.to_i or
>>   ticket1 =3D=3D number9.to_i
>>   show_results(ticket1, prize6)
>> end
>>
>> if ticket1 =3D=3D number10.to_i or
>>   ticket1 =3D=3D number11.to_i
>>   show_results(ticket1, prize7)
>> end
>>
>> if ticket1.to_i / 100 =3D=3D number12.to_i or
>>   ticket1.to_i / 100 =3D=3D number13.to_i or
>>   ticket1.to_i / 100 =3D=3D number14.to_i or
>>   ticket1.to_i / 100 =3D=3D number15.to_i or
>>   ticket1.to_i / 100 =3D=3D number16.to_i
>>   show_results(ticket1, prize8)
>> end
>>
>> if ticket1.to_i % 10 =3D=3D number17.to_i
>>   show_results(ticket1, prize9)
>> end
>>
>>
>> But the suggestion I really need is -
>> How to get it work with 10 (or 20, 50, 99999 randomly generated tickets
>> with random quantities each)?
>>
>> --
>> Posted via http://www.ruby-forum.com/.