Coding Dojo

Edit on Github

KataBankInGroovyByNiravAssar

This was a solution I did in groovy. I have posted the entire package on google docs. The notable points to the solution are as follows: done in groovy done with object oriented principles and design uses recursion contains some high level documentation https://docs.google.com/leaf?id=0B62m4BA4zKvjMTdlZTNkNDktN2IyMS00YjcxLWJkN2ItZDc5MjNhMjYwOWE4&sort=name&layout=list&num=50 You can contact me with questions at

KataBowlingByAndreasLarsson

In CodersDojoSweden we have done the KataBowling quite a lot of times. Our test suite usually ends up like: Gutter game = all zeroes, (score = 0) One pin down in each roll, (score = 20) Spare in first roll, one pin down in each other roll, (score = 10 + 1 + 18 = 29) Spare in last roll, one pin down in each other roll, (score = 18 + 10 + 1 = 29) Strike in first roll, one pin down in each other roll, (score = 10 + 1 + 1 + 18 = 30) Strike in last roll, one pin down in each other roll, (score = 18 + 10 + 1 + 1 = 30) Golden game = all strikes (score = 300) The highligts of the BowlingGameKata is:

KataFizzBuzzSmalltalkSolution

fb := [:counter| |rules| rules := {15->‘FizzBuzz’. 5->‘Buzz’. 3->‘Fizz’. 1->counter}. rightRule := rules detect: [:aRule| counter \ aRule key == 0]. rightRule value]. self assert: (fb value: 7) == 7. self assert: (fb value: 3) == 'Fizz'. self assert: (fb value: 5) == 'Buzz'. self assert: (fb value: 15) == 'FizzBuzz'. 1 to: 100 do: [:counter | Transcript show: (fb value: counter) asString; cr]

KataFizzBuzzSolution

This my solution to the KataFizzBuzz , with the added twist of supplying the filtering from the outside of the ClassUnderTest . FizzBuzzTest.java: import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; public class FizzBuzzTest { private static final Object[] ARRAY_OF_2_FIZZ = {2, "Fizz"}; private static final Object[] ARRAY_OF_1_2 = {1, 2}; private static final Object[] ARRAY_OF_FIZZ_7_8_FIZZ = {"Fizz", 7, 8, "Fizz"}; private static final Object[] ARRAY_OF_BUZZ = {"Buzz"}; private static final Object[] ARRAY_OF_FIZZBUZZ = {"FizzBuzz"}; private static final Object[] ARRAY_OF_FIZZBUZZ_TO_FIZZ = {"FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz"}; FizzBuzz fizzBuzz = new FizzBuzz(); @Before public void addFilters() { fizzBuzz.

KataRomanNumeralsAsReadableAsWeCouldMakeIt

#!/usr/bin/env python # ## Roman Numerals Kata ## def number_to_numeral(number): """ >>> number_to_numeral(1) 'I' >>> number_to_numeral(2) 'II' >>> number_to_numeral(12) 'XII' >>> number_to_numeral(10) 'X' >>> number_to_numeral(20) 'XX' >>> number_to_numeral(99) 'XCIX' >>> number_to_numeral(100) 'C' >>> number_to_numeral(199) 'CXCIX' >>> number_to_numeral(2399) 'MMCCCXCIX' >>> number_to_numeral(4000) Traceback (most recent call last): ... IndexError: list index out of range """ numerals_dict = { 'ones': ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'], 'tens': ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'], 'hundreds': ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'], 'thousands': ['', 'M', 'MM', 'MMM'], } s = [] for index in ['ones', 'tens', 'hundreds', 'thousands']: number, remainder = divmod(number, 10) s.

KataRomanNumeralsYetAnotherOne

import doctest,pdb def roman_help(value, low, medium, high): """ >>> roman_help(1, "I", "V", "X") 'I' >>> roman_help(2, "I", "V", "X") 'II' >>> roman_help(3, "I", "V", "X") 'III' >>> roman_help(4, "I", "V", "X") 'IV' >>> roman_help(5, "I", "V", "X") 'V' >>> roman_help(6, "I", "V", "X") 'VI' >>> roman_help(7, "I", "V", "X") 'VII' >>> roman_help(8, "I", "V", "X") 'VIII' >>> roman_help(9, "I", "V", "X") 'IX' >>> roman_help(10, "I", "V", "X") 'X' >>> roman_help(11, "I", "V", "X") 'XI' >>> roman_help(12, "I", "V", "X") 'XII' >>> roman_help(13, "I", "V", "X") 'XIII' >>> roman_help(14, "I", "V", "X") 'XIV' >>> roman_help(15, "I", "V", "X") 'XV' >>> roman_help(16, "I", "V", "X") 'XVI' >>> roman_help(17, "I", "V", "X") 'XVII' >>> roman_help(18, "I", "V", "X") 'XVIII' >>> roman_help(19, "I", "V", "X") 'XIX' >>> roman_help(20, "I", "V", "X") 'XX' """ cases={1:low, 2:low*2, 3:low*3, 4:low+medium, 5: medium, 6:medium+low, 7:medium+low*2, 8: medium+low*3, 9: low+high,0:'' } return high*(value/10 )+cases[value%10] def roman(value):