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

2000 katas later @CAS15

2000 katas later @CAS15

Talk about what I learned after implementing 2000 thousand katas, deliberate practice and how to receive impersonal feedback

CAS 2016 at Vitoria

Javier Gamarra

December 02, 2016
Tweet

More Decks by Javier Gamarra

Other Decks in Technology

Transcript

  1. “the practise of kata without learning to apply them in

    live situations is useless” --Gichin Funakoshi
  2. def apply_discount(item) @count[item] += 1 if (details = DISCOUNT[item]) if

    @count[item] % details[:quantity] == 0 @total -= details[:discount] end end end PRICE = { 'A' => 50, 'B' => 30, 'C' => 20, 'D' => 15 } DISCOUNT = { 'A' => {:quantity => 3, :discount => 20 }, 'B' => { :quantity => 2, :discount => 15 } }
  3. def create_array(n): res=[] i=1 while i<=n: res+=[i] return res def

    create_array(n): res=[] i=1 while i<=n: res+=[i] i+= 1 return res Fix this infinite loop
  4. def playerRankUp(pts): if pts >= 100: return ("Win!") else: return

    False def playerRankUp(pts): return "Win!" if pts >=100 else False How do you write conditionals?
  5. function loop_size(node){ var nodes = []; while(nodes.indexOf(node) == -1) {

    nodes.push(node); node = node.getNext(); } return nodes.length - (nodes.indexOf(node)); }
  6. How many ways can you make the sum of a

    number? function sum(n, m = n) { if (n == 0) return 1; if (n < 0 || m == 0) return 0; let total = sum(n, m - 1) + sum(n - m, m); return total; }
  7. // solution based on Euler decomposition with pentagonal numbers function

    sum(num) { var p = new Array p[0] = 1 var j = 0 var k = 0 var s = 0 if (num<=0){return 0} for (var i = 1; i<num+1;i++) { j=1 k=1 s=0 while (j>0){ j = i-(3*k*k+k)/2 if (j>=0) {s -= Math.pow(-1,k)*p[j]} j = i-(3*k*k-k)/2 if (j>=0) {s -= Math.pow(-1,k)*p[j]} k = k+1 } p[i] = s } return p[num] }
  8. How many ways can you make the sum of a

    number? function sum(n, m = n) { if (n == 0) return 1; if (n < 0 || m == 0) return 0; let total = sum(n, m - 1) + sum(n - m, m); return total; }
  9. How many ways can you make the sum of a

    number? var memo = []; function sum(n, m = n) { if (n == 0) return 1; if (n < 0 || m == 0) return 0; if (memo[n] && memo[n][m]) return memo[n][m]; let total = sum(n, m - 1) + sum(n - m, m); if (!memo[n]) { memo[n] = []; } memo[n][m] = total; return total; }
  10. read someone else's code learn your favorite programming tools ask

    programming questions read about pioneers
  11. references • Kata is more than Karate • Benefits of

    code katas • Life code katas • "Old" Code Katas (codekatas.org) • Solid Gear (github.com/solidgear)