Skip to content

Instantly share code, notes, and snippets.

@thunklife
Last active August 23, 2018 23:07
Show Gist options
  • Save thunklife/11323515e8e7b351b9f3c994f64b958c to your computer and use it in GitHub Desktop.
Save thunklife/11323515e8e7b351b9f3c994f64b958c to your computer and use it in GitHub Desktop.
August Katas

August Katas

Recursive Functions

Write a function that recursively sums all numbers from 1 to n, n being the argument. So that if n was 5, you’d add 1+2+3+4+5 to get 15.

Write a recusive version of map and filter. Try, if your language of choice has a way, to make it as polymorphic as possible. Ideally, the functions so know as little as possible about their arguments.

The definitions of map and filter should reveal a pattern. Define a function based on that pattern, and see if you can redefine map and filter in terms of it, again trying to be as polymorphic as possible. Bonus points if you can redefine the adding function above.

Write a recursive binary search function that takes a sorted list/array of integers, and an integer to attempt to lookup. If the integer is found, return its index. If the integer is not found, return -1, false, anything really as long as it denotes that the integer was not found.

The Towers of Hanoi is mathematical puzzle in which there are 3 pegs (A, B, C) and n discs. Assuming that all the pegs begin on A, stacked largest to smallest, move the discs, one at a time, to peg C such that the discs are still stacked with the largest on the bottom and the smallest on top.

Recursive Data Structure

A binary tree is a tree data structure in which each node has at most two children.

            1
           / \ 
          3   2
             / \
            5   4

Create a recursive definition of a binary tree.

With the binary tree defined, write recursive versions of a few operations for binary trees:

  • insert - Add an element to the tree.
  • delete - Remove an element from the tree.
  • size - Get the size of a tree.
  • search - Determine if an element is in the tree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment