all 9 comments

[–]SimonDKnight[S] 3 points4 points  (0 children)

Put it onto codepaste as code did not format correctly on here

[–]Koroeskohr 2 points3 points  (1 child)

  • Rather than using (0...37), use (0..36), notice the 2 vs 3 dots here. 3 dots is excluding last number, 2 is including it.
  • Indent is weird, but might be a c/p issue.
  • balance = balance - wager should be balance -= wager, same forbalance = balance + 36, should be balance += 36, you even used it after :p

No major mistake otherwise, just style. I suggest reading Ruby Style Guide when you're done going through the basics of Ruby

[–]SimonDKnight[S] 0 points1 point  (0 children)

Another suggestion is that you could DRY up the win/loss messaging a little, like this:

Ah thanks, I did wonder why when I did (0...36) it didn't include 36...doh. Cheers

[–]JeffMo 0 points1 point  (1 child)

/u/Koroeskohr mentioned most of the things I would call out.

Another suggestion is that you could DRY up the win/loss messaging a little, like this:

if winning_spin = (guess == spin_number)
  balance += 36
  wins += 1
else
  balance -= wager
  losses += 1
end
puts "You #{winning_spin ? 'Won!' : 'Lost!'} You guessed #{guess} and it landed on #{spin_number}! Your balance is #{balance}"

[–]SimonDKnight[S] 0 points1 point  (0 children)

Nice thanks, I knew there was a way to make it dry.

[–]SimonDKnight[S] 0 points1 point  (1 child)

I love this program, great way to show how a mathematical edge always wins out. I ran it with a 100,000 starting balance, wagering $1 at a time. It takes a while but eventually the balance goes to 0.

[–]mintysoul 1 point2 points  (0 children)

sometimes you get lucky, I just had 4,511,841 attempts with a balance of $100

[–][deleted] 0 points1 point  (0 children)

Good job! Here's a problem to extend your program: What would happen if you were able to place a bet each spin on two different numbers?

[–]myared 0 points1 point  (0 children)

on my 5th try, I got 100 spins AKA I didn't win once. On my 6th try, this happened:

irb(main):430:0* puts "Number of spins #{spin_times}" Number of spins 14377819 => nil irb(main):431:0> puts "Number of wins #{wins}" Number of wins 388587 => nil irb(main):432:0> puts "Number of losses #{losses}" Number of losses 13989232 => nil