-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished first step to ruby enlightenment
- Loading branch information
0 parents
commit c2f8a7f
Showing
45 changed files
with
3,981 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
= Playing Greed | ||
|
||
Greed is a dice game played among 2 or more players, using 5 | ||
six-sided dice. | ||
|
||
== Playing Greed | ||
|
||
Each player takes a turn consisting of one or more rolls of the dice. | ||
On the first roll of the game, a player rolls all five dice which are | ||
scored according to the following: | ||
|
||
Three 1's => 1000 points | ||
Three 6's => 600 points | ||
Three 5's => 500 points | ||
Three 4's => 400 points | ||
Three 3's => 300 points | ||
Three 2's => 200 points | ||
One 1 => 100 points | ||
One 5 => 50 points | ||
|
||
A single die can only be counted once in each roll. For example, | ||
a "5" can only count as part of a triplet (contributing to the 500 | ||
points) or as a single 50 points, but not both in the same roll. | ||
|
||
Example Scoring | ||
|
||
Throw Score | ||
--------- ------------------ | ||
5 1 3 4 1 50 + 2 * 100 = 250 | ||
1 1 1 3 1 1000 + 100 = 1100 | ||
2 4 4 5 4 400 + 50 = 450 | ||
|
||
The dice not contributing to the score are called the non-scoring | ||
dice. "3" and "4" are non-scoring dice in the first example. "3" is | ||
a non-scoring die in the second, and "2" is a non-score die in the | ||
final example. | ||
|
||
After a player rolls and the score is calculated, the scoring dice are | ||
removed and the player has the option of rolling again using only the | ||
non-scoring dice. If all of the thrown dice are scoring, then the | ||
player may roll all 5 dice in the next roll. | ||
|
||
The player may continue to roll as long as each roll scores points. If | ||
a roll has zero points, then the player loses not only their turn, but | ||
also accumulated score for that turn. If a player decides to stop | ||
rolling before rolling a zero-point roll, then the accumulated points | ||
for the turn is added to his total score. | ||
|
||
== Getting "In The Game" | ||
|
||
Before a player is allowed to accumulate points, they must get at | ||
least 300 points in a single turn. Once they have achieved 300 points | ||
in a single turn, the points earned in that turn and each following | ||
turn will be counted toward their total score. | ||
|
||
== End Game | ||
|
||
Once a player reaches 3000 (or more) points, the game enters the final | ||
round where each of the other players gets one more turn. The winner | ||
is the player with the highest score after the final round. | ||
|
||
== References | ||
|
||
Greed is described on Wikipedia at | ||
http://en.wikipedia.org/wiki/Greed_(dice_game), however the rules are | ||
a bit different from the rules given here. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
= EdgeCase Ruby Koans | ||
|
||
The Ruby Koans walk you along the path to enlightenment in order to learn Ruby. | ||
The goal is to learn the Ruby language, syntax, structure, and some common | ||
functions and libraries. We also teach you culture. Testing is not just something we | ||
pay lip service to, but something we live. It is essential in your quest to learn | ||
and do great things in the language. | ||
|
||
== The Structure | ||
|
||
The koans are broken out into areas by file, hashes are covered in about_hashes.rb, | ||
modules are introduced in about_modules.rb, etc. They are presented in order in the | ||
path_to_enlightenment.rb file. | ||
|
||
Each koan builds up your knowledge of Ruby and builds upon itself. It will stop at | ||
the first place you need to correct. | ||
|
||
Some koans simply need to have the correct answer substituted for an incorrect one. | ||
Some, however, require you to supply your own answer. If you see the method +__+ (a | ||
double underscore) listed, it is a hint to you to supply your own code in order to | ||
make it work correctly. | ||
|
||
== Installing Ruby | ||
|
||
If you do not have Ruby setup, please visit http://ruby-lang.org/en/downloads/ for | ||
operating specific instructions. In order to run this you need ruby and rake | ||
installed. To check the installations simply type: | ||
|
||
*nix platforms from any terminal window: | ||
|
||
[~] $ ruby --version | ||
[~] $ rake --version | ||
|
||
Windows from the command prompt (cmd.exe) | ||
|
||
c:\ruby --version | ||
c:\rake --version | ||
|
||
If you don't have rake installed, just run `gem install rake` | ||
|
||
Any response for Ruby with a version number greater than 1.8 is fine (should be | ||
around 1.8.6 or more). Any version of rake will do. | ||
|
||
== Generating the Koans | ||
|
||
A fresh checkout will not include the koans, you will need to generate | ||
them. | ||
|
||
[ruby_koans] $ rake gen # generates the koans directory | ||
|
||
If you need to regenerate the koans, thus wiping your current `koans`, | ||
|
||
[ruby_koans] $ rake regen # regenerates the koans directory, wiping the original | ||
|
||
== The Path To Enlightenment | ||
|
||
You can run the tests through rake or by calling the file itself (rake is the | ||
recommended way to run them as we might build more functionality into this task). | ||
|
||
*nix platforms, from the koans directory | ||
|
||
[ruby_koans] $ rake # runs the default target :walk_the_path | ||
[ruby_koans] $ ruby path_to_enlightenment.rb # simply call the file directly | ||
|
||
Windows is the same thing | ||
|
||
c:\ruby_koans\rake # runs the default target :walk_the_path | ||
c:\ruby_koans\ruby path_to_enlightenment.rb # simply call the file directly | ||
|
||
=== Red, Green, Refactor | ||
|
||
In test-driven development the mantra has always been, red, green, refactor. Write a | ||
failing test and run it (red), make the test pass (green), then refactor it (that is | ||
look at the code and see if you can make it any better. In this case you will need | ||
to run the koan and see it fail (red), make the test pass (green), then take a | ||
moment and reflect upon the test to see what it is teaching you and improve the | ||
code to better communicate its intent (refactor). | ||
|
||
The very first time you run it you will see the following output: | ||
|
||
[ ruby_koans ] $ rake | ||
(in /Users/person/dev/ruby_koans) | ||
cd koans | ||
|
||
Thinking AboutAsserts | ||
test_assert_truth has damaged your karma. | ||
|
||
You have not yet reached enlightenment ... | ||
<false> is not true. | ||
|
||
Please meditate on the following code: | ||
./about_asserts.rb:10:in `test_assert_truth' | ||
path_to_enlightenment.rb:27 | ||
|
||
mountains are merely mountains | ||
|
||
You have come to your first stage. If you notice it is telling you where to look for | ||
the first solution: | ||
|
||
Please meditate on the following code: | ||
./about_asserts.rb:10:in `test_assert_truth' | ||
path_to_enlightenment.rb:27 | ||
|
||
We then open up the about_asserts.rb file and look at the first test: | ||
|
||
# We shall contemplate truth by testing reality, via asserts. | ||
def test_assert_truth | ||
assert false # This should be true | ||
end | ||
|
||
We then change the +false+ to +true+ and run the test again. After you are | ||
done, think about what you are learning. In this case, ignore everything except | ||
the method name (+test_assert_truth+) and the parts inside the method (everything | ||
before the +end+). | ||
|
||
In this case the goal is for you to see that if you pass a value to the +assert+ | ||
method, it will either ensure it is +true+ and continue on, or fail if in fact | ||
the statement is +false+. | ||
|
||
== Inspiration | ||
|
||
A special thanks to Mike Clark and Ara Howard for inspiring this | ||
project. Mike Clark wrote an excellent blog post about learning Ruby | ||
through unit testing. This sparked an idea that has taken a bit to | ||
solidify, that of bringing new rubyists into the community through | ||
testing. Ara Howard then gave us the idea for the Koans in his ruby | ||
quiz entry on Meta Koans (a must for any rubyist wanting to improve | ||
their skills). Also, "The Little Lisper" taught us all the value of | ||
the short questions/simple answers style of learning. | ||
|
||
Mike Clark's post :: http://www.clarkware.com/cgi/blosxom/2005/03/18 | ||
Meta Koans :: http://rubyquiz.com/quiz67.html | ||
The Little Lisper :: http://www.amazon.com/Little-LISPer-Third-Daniel-Friedman/dp/0023397632 | ||
|
||
== Other Resources | ||
|
||
The Ruby Language :: http://ruby-lang.org | ||
Try Ruby in your browser :: http://tryruby.org | ||
|
||
Dave Thomas' introduction to Ruby Programming Ruby (the Pick Axe) :: http://pragprog.com/titles/ruby/programming-ruby | ||
|
||
Brian Marick's fantastic guide for beginners Everyday Scripting with Ruby :: http://pragprog.com/titles/bmsft/everyday-scripting-with-ruby | ||
|
||
= Other stuff | ||
|
||
Author :: Jim Weirich <jim@weirichhouse.org> | ||
Author :: Joe O'Brien <joe@edgecase.com> | ||
Issue Tracker :: http://www.pivotaltracker.com/projects/48111 | ||
Requires :: Ruby 1.8.x or later and Rake (any recent version) | ||
|
||
= License | ||
|
||
http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png | ||
|
||
RubyKoans is released under a Creative Commons, | ||
Attribution-NonCommercial-ShareAlike, Version 3.0 | ||
(http://creativecommons.org/licenses/by-nc-sa/3.0/) License. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env ruby | ||
# -*- ruby -*- | ||
|
||
require 'rake/clean' | ||
require 'rake/testtask' | ||
|
||
task :default => :test | ||
|
||
task :test do | ||
ruby 'path_to_enlightenment.rb' | ||
end | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/edgecase') | ||
|
||
class AboutArrayAssignment < EdgeCase::Koan | ||
def test_non_parallel_assignment | ||
names = ["John", "Smith"] | ||
assert_equal ["John", "Smith"], names | ||
end | ||
|
||
def test_parallel_assignments | ||
first_name, last_name = ["John", "Smith"] | ||
assert_equal "John", first_name | ||
assert_equal "Smith", last_name | ||
end | ||
|
||
def test_parallel_assignments_with_extra_values | ||
first_name, last_name = ["John", "Smith", "III"] | ||
assert_equal "John", first_name | ||
assert_equal "Smith", last_name | ||
end | ||
|
||
def test_parallel_assignments_with_splat_operator | ||
first_name, *last_name = ["John", "Smith", "III"] | ||
assert_equal "John", first_name | ||
assert_equal ["Smith","III"], last_name | ||
end | ||
|
||
def test_parallel_assignments_with_too_few_variables | ||
first_name, last_name = ["Cher"] | ||
assert_equal "Cher", first_name | ||
assert_equal nil, last_name | ||
end | ||
|
||
def test_parallel_assignments_with_subarrays | ||
first_name, last_name = [["Willie", "Rae"], "Johnson"] | ||
assert_equal ["Willie", "Rae"], first_name | ||
assert_equal "Johnson", last_name | ||
end | ||
|
||
def test_parallel_assignment_with_one_variable | ||
first_name, = ["John", "Smith"] | ||
assert_equal "John", first_name | ||
end | ||
|
||
def test_swapping_with_parallel_assignment | ||
first_name = "Roy" | ||
last_name = "Rob" | ||
first_name, last_name = last_name, first_name | ||
assert_equal "Rob", first_name | ||
assert_equal "Roy", last_name | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/edgecase') | ||
|
||
class AboutArrays < EdgeCase::Koan | ||
def test_creating_arrays | ||
empty_array = Array.new | ||
assert_equal Array, empty_array.class | ||
assert_equal 0, empty_array.size | ||
end | ||
|
||
def test_array_literals | ||
array = Array.new | ||
assert_equal [], array | ||
|
||
array[0] = 1 | ||
assert_equal [1], array | ||
|
||
array[1] = 2 | ||
assert_equal [1, 2], array | ||
|
||
array << 333 | ||
assert_equal [1,2,333], array | ||
end | ||
|
||
def test_accessing_array_elements | ||
array = [:peanut, :butter, :and, :jelly] | ||
|
||
assert_equal :peanut, array[0] | ||
assert_equal :peanut, array.first | ||
assert_equal :jelly, array[3] | ||
assert_equal :jelly, array.last | ||
assert_equal :jelly, array[-1] | ||
assert_equal :butter, array[-3] | ||
end | ||
|
||
def test_slicing_arrays | ||
array = [:peanut, :butter, :and, :jelly] | ||
|
||
assert_equal [:peanut], array[0,1] | ||
assert_equal [:peanut,:butter], array[0,2] | ||
assert_equal [:and,:jelly], array[2,2] | ||
assert_equal [:and,:jelly], array[2,20] | ||
assert_equal [], array[4,0] | ||
assert_equal [], array[4,100] | ||
assert_equal nil, array[5,0] | ||
end | ||
|
||
def test_arrays_and_ranges | ||
assert_equal Range, (1..5).class | ||
assert_not_equal [1,2,3,4,5], (1..5) | ||
assert_equal [1,2,3,4,5], (1..5).to_a | ||
assert_equal [1,2,3,4], (1...5).to_a | ||
end | ||
|
||
def test_slicing_with_ranges | ||
array = [:peanut, :butter, :and, :jelly] | ||
|
||
assert_equal [:peanut,:butter,:and], array[0..2] | ||
assert_equal [:peanut,:butter], array[0...2] | ||
assert_equal [:and,:jelly], array[2..-1] | ||
end | ||
|
||
def test_pushing_and_popping_arrays | ||
array = [1,2] | ||
array.push(:last) | ||
|
||
assert_equal [1,2,:last], array | ||
|
||
popped_value = array.pop | ||
assert_equal :last, popped_value | ||
assert_equal [1,2], array | ||
end | ||
|
||
def test_shifting_arrays | ||
array = [1,2] | ||
array.unshift(:first) | ||
|
||
assert_equal [:first,1,2], array | ||
|
||
shifted_value = array.shift | ||
assert_equal :first, shifted_value | ||
assert_equal [1,2], array | ||
end | ||
|
||
end |
Oops, something went wrong.