Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Perth Code Dojo 1

Perth Code Dojo 1

Karate Chop Kata - Binary Chop

William Webster

July 28, 2014
Tweet

More Decks by William Webster

Other Decks in Programming

Transcript

  1. Check-In ➔ Your name ➔ What you do (at work)

    ➔ A random fact about yourself
  2. Code Dojo Format A Coding Dojo is a coding session

    centered around a programming challenge. The dojo provides a safe place to learn and experiment away from the pressures of business delivery. All programmers of varying skill levels meet as equals to learn and share.
  3. Software Craftsmanship “Deliberate practice is closely related to the attained

    level of performance of many types of experts” - Dr. K. Anders Ericsson 10,000 hrs rule - Malcolm Gladwell
  4. Pomodoro ➔ Pomodoro Technique ◆ 25 mins on, 5 mins

    off ◆ http://tomatoi.st/perthcodedojo ➔ Four iterations
  5. Retro & Pizza Closing with Pizza and a mini retrospective

    ➔ Share solutions on the big screen ➔ Discuss challenge / approach ➔ Feedback on the dojo
  6. Karate Chop Write a program performs a binary chop (search)

    to find an index in a sorted array of values. It achieves some efficiency by halving the number of items under consideration each time it probes the values: in the first pass it determines whether the required value is in the top or the bottom half of the list of values. In the second pass in considers only this half, again dividing it into two. It stops when it finds the value it is looking for, or when it runs out of array to search.
  7. Interface & Tests chop(int, array_of_int) -> int assert_equal(-1, chop(3, [1]))

    assert_equal(0, chop(1, [1])) assert_equal(0, chop(1, [1, 3, 5])) assert_equal(2, chop(5, [1, 3, 5, 7])
  8. Reimplement Challenge: think of another way to implement the binary

    chop Review your tests. Are all the edge cases covered?
  9. Reimplement Challenge: can you come up with a third way

    to implement the search Refactor: is there anything to clean up?
  10. Thank You! @sleepyfox who runs the London Code Dojo for

    inspiration and advice Dave Thomas for Kata ideas - http://codekata.com http://creativecommons.org/licenses/by-nc-sa/4.0/ @willwebst