diff --git a/challenge_4/python/whiterd/README.md b/challenge_4/python/whiterd/README.md new file mode 100644 index 000000000..da7eb3581 --- /dev/null +++ b/challenge_4/python/whiterd/README.md @@ -0,0 +1,7 @@ +# Invert Binary Tree + +* Take in a binary tree object. + +* For each level in the tree, reverse the order of the items in that level (mirror). + +* Return the node object. \ No newline at end of file diff --git a/challenge_4/python/whiterd/src/invert_bin.py b/challenge_4/python/whiterd/src/invert_bin.py new file mode 100644 index 000000000..194128418 --- /dev/null +++ b/challenge_4/python/whiterd/src/invert_bin.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +''' + Input: An object consisting of a binary tree. + + Output: The same tree with values mirrored. +''' + +def mirror(node): + if node: + mirror(node.left) + mirror(node.right) + node.left, node.right = node.right, node.left + + return node diff --git a/challenge_6/python/whiterd/README.md b/challenge_6/python/whiterd/README.md new file mode 100644 index 000000000..5c30d4aa3 --- /dev/null +++ b/challenge_6/python/whiterd/README.md @@ -0,0 +1,30 @@ +# Range Finder-er :tm: +###### Tested using Python 3.5.2 -- run using ```$ python src/id_ranges.py``` + +### Purpose: + +* Identify the ranges that exist for a given input. + +### Assuptions: + +* Input is a non-empty list of ordered integers. + +### Example 1: + +Launch scipt and input a sequence of numbers separated by commas. + +``` +>>> Input a list of integers: [1,2,3,4,8,9,10,12,13,14] +['1->4', '8->10', '12->14'] +``` + +### Example 2: + +Given the input [1,2,3,4,9,10,15], your output should be: + +``` +>>> Input a list of integers: [1,2,3,4,9,10,15] +['1->4', '9->10'] +``` + + diff --git a/challenge_6/python/whiterd/src/id_ranges.py b/challenge_6/python/whiterd/src/id_ranges.py new file mode 100644 index 000000000..c08d3f857 --- /dev/null +++ b/challenge_6/python/whiterd/src/id_ranges.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +""" + Identify the ranges that exist for a given input. + + Assume: input is a non-empty list of ordered integers. +""" +from __future__ import print_function + +def range_finderer(new_list): + result = [] + temp = [] + for i in new_list: + if not temp: + temp.append(i) + continue + elif(i - 1 == temp[-1]): + temp.append(i) + continue + else: + result.append(str(temp[0]) + '->' + str(temp[-1])) + temp = [i] + result.append(str(temp[0]) + '->' + str(temp[-1])) + return result + + +if __name__ == '__main__': + + x = [int(x) for x in input('Input a list of integers: ')[1:-1].split(',')] + print(range_finderer(x))