Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

LIEK MY DIE?

Name: Anonymous 2012-01-10 21:42


#!/usr/bin/ruby
module Game
        class Die
                class << self
                        def roll num, val, drop = 0
                                sto = Array.new num
                                0.upto(num - 1){ |a| sto[a] = rand(1 .. val) }
                                sum = 0
                                unless drop > 0
                                        sto.each { |b| sum += b }
                                else
                                        sto.sort!
                                        0.upto(num - 1 - drop) { |b| sum += b }
                                end
                                sum
                        end
                end
        end
end

Name: Anonymous 2012-01-11 9:13

>>19
Most people would declare the variable that receives the Die.Roll() value as an int, so this solution is good. But uint is required in constructor to avoid retards using negative numbers, and you don't have to check if the number is less than 0. So my solution is elegant, precise, and fast.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List