Skip to content

[Python] Challenge 5 (Unreviewed) #369

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions challenge_4/python/whiterd/README.md
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 15 additions & 0 deletions challenge_4/python/whiterd/src/invert_bin.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions challenge_5/python/whiterd/README.md
Original file line number Diff line number Diff line change
@@ -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".
42 changes: 42 additions & 0 deletions challenge_5/python/whiterd/src/find_diff.py
Original file line number Diff line number Diff line change
@@ -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))