Last active
August 29, 2015 14:04
-
-
Save jeremyjs/0f91ca4db760deb22747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Thing | |
| def initialize | |
| @phase = 1 | |
| @values = [7, 11] | |
| @other_values = [2, 3, 12] | |
| end | |
| def do_it | |
| going = true | |
| while going | |
| set_last | |
| if done | |
| puts message | |
| return true | |
| elsif also_done | |
| puts alt_message | |
| return false | |
| end | |
| staticize | |
| end | |
| end | |
| def set_last | |
| @last = do_a_thing(2, 6) | |
| puts "The value is revealed: #{@last}" | |
| end | |
| def do_a_thing(n, k) | |
| (1..n).inject(0) { |a, b| a += result(k) } | |
| end | |
| def result(k) | |
| rand(k) + 1 | |
| end | |
| def done | |
| if @phase == 1 | |
| @values.include? @last | |
| elsif @phase == 2 | |
| @last == @static | |
| end | |
| end | |
| def also_done | |
| if @phase == 1 | |
| @other_values.include? @last | |
| elsif @phase == 2 | |
| @last == 7 | |
| end | |
| end | |
| def staticize | |
| return if @static | |
| @phase = 2 | |
| @static = @last | |
| end | |
| def message | |
| "Pass" | |
| end | |
| def alt_message | |
| "Don't Pass" | |
| end | |
| end | |
| t = Thing.new | |
| t.do_it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment