This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04ae8e6
commit d5e6f62
Showing
41 changed files
with
3,462 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 @@ | ||
0,5,6,6,6,7,7,8,9,9,11,11,12,13,13,13,14,15,17,17,18,18,18,19,19,20,20,21,21,21,22,22,22,23,26,27,27,28,31,31,31,33,34,34,34,35,36,37,37,38,39,40,41,41,41,41,42,43,45,49,49,49,50,50,58,59,62,67,69,70,74,78,78,78,77,78,83,90,93,93,94,97,97,97,97,97,98,98,99,100,104,105,105,106,106,106,107,108,109,110,113,113,113,113,115,115,115,116,117,120,121,121,121,124,125,126,127,128,131,131,133,142,142,143,148,152,155,155,155,155,155,156,156,157,160,160,153,154,154,154,154,154,161,161,161,169,170,176,177,179,179,180,182,182,184,192,193,193,194,194,195,201,203,203,204,206,207,208,211,216,222,223,223,228,228,229,230,231,236,236,237,237,237,236,236,236,236,237,237,239,240,240,241,242,242,243,244,246,247,250,255,255,256,259,260,261,262,262,263,264,265,267,277,277,278,280,281,281,281,205,93,95,100,178,180,78,180,77,77,77,77,74,67,67,67,67,68,68,114,114,120,66,146,146,49,49,49,60,247,255,261,254,141 |
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,191 @@ | ||
= Neo 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 by basing the koans on tests. | ||
Testing is not just something we pay lip service to, but something we | ||
live. Testing is essential in your quest to learn and do great things in Ruby. | ||
|
||
== 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+, <em>etc</em>. 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 the koans you need +ruby+ and | ||
+rake+ installed. To check your 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 <code>gem install rake</code> | ||
|
||
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 +ruby_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 <em>red, green, refactor</em>. | ||
Write a failing test and run it (<em>red</em>), make the test pass (<em>green</em>), | ||
then look at the code and consider if you can make it any better (<em>refactor</em>). | ||
|
||
While walking the path to Ruby enlightenment you will need to run the koan and | ||
see it fail (<em>red</em>), make the test pass (<em>green</em>), 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 (<em>refactor</em>). | ||
|
||
The very first time you run the koans you will see the following output: | ||
|
||
[ ruby_koans ] $ rake | ||
(in /Users/person/dev/ruby_koans) | ||
/usr/bin/ruby1.8 path_to_enlightenment.rb | ||
|
||
AboutAsserts#test_assert_truth has damaged your karma. | ||
|
||
The Master says: | ||
You have not yet reached enlightenment. | ||
|
||
The answers you seek... | ||
<false> is not true. | ||
|
||
Please meditate on the following code: | ||
./about_asserts.rb:10:in `test_assert_truth' | ||
path_to_enlightenment.rb:38:in `each_with_index' | ||
path_to_enlightenment.rb:38 | ||
|
||
mountains are merely mountains | ||
your path thus far [X_________________________________________________] 0/280 | ||
|
||
You have come to your first stage. 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:38:in `each_with_index' | ||
path_to_enlightenment.rb:38 | ||
|
||
Open 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 | ||
|
||
Change the +false+ to +true+ and re-run the test. 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 | ||
the statement is +false+. | ||
|
||
=== Running the Koans automatically | ||
|
||
<em>This section is optional.</em> | ||
|
||
Normally the path to enlightenment looks like this: | ||
|
||
cd ruby_koans | ||
rake | ||
# edit | ||
rake | ||
# edit | ||
rake | ||
# etc | ||
|
||
If you prefer, you can keep the koans running in the background so that after you | ||
make a change in your editor, the koans will immediately run again. This will | ||
hopefully keep your focus on learning Ruby instead of on the command line. | ||
|
||
Install the Ruby gem (library) called +watchr+ and then ask it to | ||
"watch" the koans for changes: | ||
|
||
cd ruby_koans | ||
rake | ||
# decide to run rake automatically from now on as you edit | ||
gem install watchr | ||
watchr ./koans/koans.watchr | ||
|
||
== 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 <[email protected]> | ||
Author :: Joe O'Brien <[email protected]> | ||
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,10 @@ | ||
# -*- 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,54 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/neo') | ||
# docs | ||
# :reek:IrresponsibleModule | ||
class AboutArrayAssignment < Neo::Koan | ||
def test_non_parallel_assignment | ||
names = %w[John Smith] | ||
assert_equal %w[John Smith], names | ||
end | ||
|
||
# rubocop:disable Style/ParallelAssignment | ||
def test_parallel_assignments | ||
first_name, last_name = %w[John Smith] | ||
assert_equal 'John', first_name | ||
assert_equal 'Smith', last_name | ||
end | ||
|
||
def test_parallel_assignments_with_extra_values | ||
first_name, last_name = %w[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 = %w[John Smith III] | ||
assert_equal 'John', first_name | ||
assert_equal %w[Smith III], last_name | ||
end | ||
|
||
def test_parallel_assignments_with_too_few_variables | ||
first_name, last_name = %w[Cher] | ||
assert_equal 'Cher', first_name | ||
assert_equal nil, last_name | ||
end | ||
|
||
def test_parallel_assignments_with_subarrays | ||
first_name, last_name = [%w[Willie Rae], 'Johnson'] | ||
assert_equal %w[Willie Rae], first_name | ||
assert_equal 'Johnson', last_name | ||
end | ||
# rubocop:enable Style/ParallelAssignment | ||
|
||
def test_parallel_assignment_with_one_variable | ||
first_name, = %w[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 |
Oops, something went wrong.