Skip to content

Instantly share code, notes, and snippets.

@unfo
Forked from vuorejo1/gist:5922213
Last active December 19, 2015 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unfo/5922361 to your computer and use it in GitHub Desktop.
Save unfo/5922361 to your computer and use it in GitHub Desktop.
# Implement a DiceSet Class here:
class DiceSet
def initialize
@noppaluvut = []
end
def roll(montako)
@noppaluvut = []
# if montako.size == 0 || montako.size > 6
# raise error?
# arvo noppaluvut, parametri kertoo montako noppaa?
montako.times do
@noppaluvut << rand(6) + 1
end
@noppaluvut
end
def values
return @noppaluvut
end
end
@unfo
Copy link
Author

unfo commented Jul 3, 2013

ennen tota +1 randille :

irb(main):023:0> dc = DiceSet.new
=> #<DiceSet:0x7fb7c72a04f0 @noppaluvut=[]>
irb(main):024:0> dc.roll(2)
=> [3, 2]
irb(main):025:0> dc.values
=> [3, 2]
irb(main):026:0> dc.roll(5)
=> [4, 4, 2, 2, 0]

@unfo
Copy link
Author

unfo commented Jul 3, 2013

fiksin jälkeen:

irb(main):023:0> dc = DiceSet.new
=> #<DiceSet:0x7f83000fdd38 @noppaluvut=[]>
irb(main):024:0> dc.roll(10)
=> [3, 2, 3, 5, 6, 1, 1, 1, 6, 2]
irb(main):025:0> dc.roll(10)
=> [3, 1, 2, 6, 3, 2, 2, 3, 4, 6]
irb(main):026:0> dc.roll(10)
=> [6, 1, 4, 1, 5, 3, 5, 1, 4, 2]
irb(main):027:0> dc.roll(10)
=> [1, 6, 3, 1, 3, 6, 2, 6, 6, 5]
irb(main):028:0> dc.roll(10)
=> [2, 5, 5, 5, 1, 6, 4, 1, 1, 1]
irb(main):029:0> dc.roll(10)
=> [2, 6, 1, 5, 6, 1, 4, 5, 5, 5]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment