Skip to content

Instantly share code, notes, and snippets.

@tooky
Last active August 29, 2015 14:07
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 tooky/741dbf189b4914d4fa96 to your computer and use it in GitHub Desktop.
Save tooky/741dbf189b4914d4fa96 to your computer and use it in GitHub Desktop.
On The Beach Academy, October 2014 – Homework

Week 1 - Homework

  • Complete the remaining exercises (note: you can run each file individually using rspec <filename>)
  • Work through them in the following order:
    • spec/iteration_spec.rb
    • spec/blocks_spec.rb
    • spec/sandwich_code_spec.rb
    • spec/scoring_project_spec.rb
    • spec/classes_spec.rb
    • spec/open_classes_spec.rb
    • spec/dice_project_spec.rb
    • spec/inheritance_spec.rb
    • spec/modules_spec.rb
    • spec/scope_spec.rb
    • spec/class_methods_spec.rb
    • spec/message_passing_spec.rb
    • spec/proxy_object_project_spec.rb
    • spec/to_str_spec.rb
  • write a 10 minute presentation on your selected topic
  • Project:
    • Use RSpec to 'drive' a solution to either:
    • Create your project on github, and link it in the comments of this gist
    • You can use rspec --init to set up a project skeleton
    • Use small, frequent commits showing how you worked through the problem.
    • Write good commit messages

Week 1 - Presentations

  1. StandardError vs Exception - Phil
  2. Git rebase vs merge - Marc
  3. What is a git branch? - Mark
  4. What is an RSpec matcher? With examples. - Joe
  5. What are all different RSpec blocks, e.g. describe, it, let, before, subject - Purnima
  6. Ruby blocks, procs and lambdas - Asta
  7. Ruby's Enumerable module - Damien
  8. Inheritance vs Composition – with examples in Ruby - Craig

Week 2 Homework

  • If you haven't finished one of the katas from last week, please do!
  • Write up a blog post explaining Ruby Method lookup, reference include, extend and super.
    • BONUS: Newer versions of ruby also have prepend
  • Read [Think Like (a) Git] git and write a blog post about the thing you found most interesting, or something that suprised you.
  • Review another academy member's kata from last week using github. Try to make constructive comments about how they could improve the design of their code. Try to use the github interface to leave comments on specific commits, and lines of code.
    • BONUS: create a pull request instead of comment to show what you mean with code.
  • Watch Sandi Metz's Magic Tricks of Testing
<iframe width="560" height="315" src="http://www.youtube.com/embed/URSWYvyc42M" frameborder="0" allowfullscreen></iframe>

Notes

  • If you don't have a blog, either publish it as a gist, or try wordpress or tumblr
  • Please document your small commits using good commit messages
  • Publish all code on your github account, and let me know where it is. Simplest might be to add me as a collaborator, or tag me in a commit message or pull request (@tooky)
  • Please ask me questions [steve (at) boxjump.co.uk](mailto:steve@boxjump.co.uk] / twitter @tooky
  • Share your blog posts with the team!

Week 3 Homework

  • In pairs we discussed: build a web based hangman game.

    • This is a 1-player game.
    • Players choose to start a new game.
    • Players only guess 1 letter at a time, there is no need to support guessing the whole word.
    • Incorrect guesses should be shown in a "trash" area.
    • You don't need to display graphics, simply showing number of lives remaining is sufficient.
    • That's not to say you shouldn't try!
    • Use cucumber to drive the development from the outside, but... do most of the detailed testing using RSpec.
    • You do not need to worry about storing games beyond the life-time of the server
    • Extensions - if you get your game working choose one of these ways to extend your project - if you finish one, try the other....
      • Build a 2 player game, each player is asked to enter a word and the winner is the player who guesses the other's word in the least number of moves
        • Players cannot enter a non-dictionary word
      • Create a new interface for the game engine that allows you to play hangman in slack channel (take a look at their web hook integrations)
        • play should be confined to a single channel
        • any user can ask for a new game
        • any user can guess on the current game
        • you can't start a new game if a game is already in play
  • With another pair: Try a code kata from the list of exercises from cyber-dojo

    • For an example of shameless green look at this pull-request - this isn't an example of perfect code, just an approach. Please make comments :)
  • On your own: Join Exercism and give the ruby exercises a go...

The priority for you to work on here is the hangman game - the other ideas are there to give you chance to work with other people, or try things out on your own. Pairing is hard-work, especially if you are spending a lot of time pairing with one person. Take the oppurtunity to break your day up.

Create a program, which, given a valid sequence of rolls for one line of American Ten-Pin Bowling, produces the total score for the game. Here are some things that the program will not do:

  • We will not check for valid rolls.
  • We will not check for correct number of rolls and frames.
  • We will not provide scores for intermediate frames.
  • Depending on the application, this might or might not be a valid way to define a complete story, but we do it here for purposes of keeping the kata light. I think you'll see that improvements like those above would go in readily if they were needed for real.

We can briefly summarize the scoring for this form of bowling:

  • Each game, or "line" of bowling, includes ten turns, or "frames" for the bowler.
  • In each frame, the bowler gets up to two tries to knock down all the pins.
  • If in two tries, he fails to knock them all down, his score for that frame is the total number of pins knocked down in his two tries.
  • If in two tries he knocks them all down, this is called a "spare" and his score for the frame is ten plus the number of pins knocked down on his next throw (in his next turn).
  • If on his first try in the frame he knocks down all the pins, this is called a "strike". His turn is over, and his score for the frame is ten plus the simple total of the pins knocked down in his next two rolls.
  • If he gets a spare or strike in the last (tenth) frame, the bowler gets to throw one or two more bonus balls, respectively. These bonus throws are taken as part of the same turn. If the bonus throws knock down all the pins, the process does not repeat: the bonus throws are only used to calculate the score of the final frame.
  • The game score is the total of all frame scores.

More info on the rules at: www.topendsports.com/sport/tenpin/scoring.htm

Harry Potter Kata

To try and encourage more sales of the 5 different Harry Potter books they sell, a bookshop has decided to offer discounts of multiple-book purchases.

One copy of any of the five books costs 8 EUR.

If, however, you buy two different books, you get a 5% discount on those two books.

If you buy 3 different books, you get a 10% discount.

If you buy 4 different books, you get a 20% discount.

If you go the whole hog, and buy all 5, you get a huge 25% discount.

Note that if you buy, say, four books, of which 3 are different titles, you get a 10% discount on the 3 that form part of a set, but the fourth book still costs 8 EUR.

Your mission is to write a piece of code to calculate the price of any conceivable shopping basket (containing only Harry Potter books), giving as big a discount as possible.

For example, how much does this basket of books cost?

2 copies of the first book 2 copies of the second book 2 copies of the third book 1 copy of the fourth book 1 copy of the fifth book

Answer: 51.20 EUR

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