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_5/python/whiterd/README.md b/challenge_5/python/whiterd/README.md new file mode 100644 index 000000000..7125304d5 --- /dev/null +++ b/challenge_5/python/whiterd/README.md @@ -0,0 +1,7 @@ +# Find the Difference + +* Assume: two given strings ("s" and "t") of lowercase letters + * "s" is a series of letters (e.g. s = "abcd") + * "t" is an unknow ordering of "s", plus one extra character + +* Output: the added character present in "t" that is not in "s". \ No newline at end of file diff --git a/challenge_5/python/whiterd/src/find_diff.py b/challenge_5/python/whiterd/src/find_diff.py new file mode 100644 index 000000000..494e6332b --- /dev/null +++ b/challenge_5/python/whiterd/src/find_diff.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +''' + Input: string (series of characters) + + Process: string input is randomly sorted and and additional character + is added. + + Output: the additional character that is not present in the input. +''' + +from __future__ import print_function +from random import shuffle, choice +from string import ascii_lowercase + +def get_input(): + """Asks user for input and returns a string.""" + return str(input('Enter a series of unique characters: ')) + +def add_char(s): + """Takes a string as input, adds a char, shuffles it, and returns + the new string.""" + t = list(s) + other_letters = set(ascii_lowercase) - set(t) + t.append(choice(list(other_letters))) + shuffle(t) + return ''.join(t) + +def find_diff(s, t): + """Takes two strings as input and returns the differing character.""" + for i in t: + if i not in s: + return i + + +if __name__ == '__main__': + + s = get_input() + print('You entered: ' + s) + t = add_char(s) + print('The newly generated string is: ' + t) + print('The different character generated is: ' + find_diff(s, t))