From 0b7c79c4bcc9072e23e4fb9aa9a94d96c02bb648 Mon Sep 17 00:00:00 2001 From: whiterd Date: Sun, 8 Jan 2017 22:30:54 -0600 Subject: [PATCH 1/8] challenge_0 in python --- challenge_0/python/whiterd/README.md | 0 challenge_0/python/whiterd/src/hello_world.py | 5 +++++ 2 files changed, 5 insertions(+) create mode 100644 challenge_0/python/whiterd/README.md create mode 100644 challenge_0/python/whiterd/src/hello_world.py diff --git a/challenge_0/python/whiterd/README.md b/challenge_0/python/whiterd/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/challenge_0/python/whiterd/src/hello_world.py b/challenge_0/python/whiterd/src/hello_world.py new file mode 100644 index 000000000..b11ed0060 --- /dev/null +++ b/challenge_0/python/whiterd/src/hello_world.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +from __future__ import print_function + +print('Hello World!') From 62caeb7472a1b7413d192466f9822f02bea15943 Mon Sep 17 00:00:00 2001 From: whiterd Date: Mon, 9 Jan 2017 12:36:21 -0600 Subject: [PATCH 2/8] challenge_1 in python --- challenge_1/python/whiterd/README.md | 4 ++++ challenge_1/python/whiterd/src/reverse_me.py | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 challenge_1/python/whiterd/README.md create mode 100644 challenge_1/python/whiterd/src/reverse_me.py diff --git a/challenge_1/python/whiterd/README.md b/challenge_1/python/whiterd/README.md new file mode 100644 index 000000000..cbb35a8d0 --- /dev/null +++ b/challenge_1/python/whiterd/README.md @@ -0,0 +1,4 @@ + +Input: string + +Output: a reversed string of the given input \ No newline at end of file diff --git a/challenge_1/python/whiterd/src/reverse_me.py b/challenge_1/python/whiterd/src/reverse_me.py new file mode 100644 index 000000000..506121778 --- /dev/null +++ b/challenge_1/python/whiterd/src/reverse_me.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +from __future__ import print_function + +user_input = input('Enter text to be reversed: ') + +print(user_input[::-1]) From f4664fe47c03100c60c767b105681c0c2a9d715c Mon Sep 17 00:00:00 2001 From: whiterd Date: Mon, 9 Jan 2017 19:26:14 -0600 Subject: [PATCH 3/8] [Python] Challenge_2 --- challenge_2/python/whiterd/README.md | 4 ++++ .../python/whiterd/src/find_distinct.py | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 challenge_2/python/whiterd/README.md create mode 100644 challenge_2/python/whiterd/src/find_distinct.py diff --git a/challenge_2/python/whiterd/README.md b/challenge_2/python/whiterd/README.md new file mode 100644 index 000000000..4a3e4601b --- /dev/null +++ b/challenge_2/python/whiterd/README.md @@ -0,0 +1,4 @@ + +Input: a list of integers. + +Output: the only non-repeated integer. \ No newline at end of file diff --git a/challenge_2/python/whiterd/src/find_distinct.py b/challenge_2/python/whiterd/src/find_distinct.py new file mode 100644 index 000000000..a0a44bc76 --- /dev/null +++ b/challenge_2/python/whiterd/src/find_distinct.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +''' + Input: An array of random integers where every integer is repeated except + for a single one. + + Output: The single integer that does NOT repeat. +''' + +from __future__ import print_function + +array_1 = [2,3,4,2,3,5,4,6,4,6,9,10,9,8,7,8,10,7] +array_2 = [2,'a','l',3,'l',4,'k',2,3,4,'a',6,'c',4,'m',6,'m','k',9,10,9,8,7,8,10,7] + +def find_distinct(array): + for i in array: + if array.count(i) == 1: + return i + + +if __name__ == '__main__': + print(find_distinct(array_1)) + print(find_distinct(array_2)) From 0bc2f1f3e71559e5d1ad008d07c9927427844e0e Mon Sep 17 00:00:00 2001 From: whiterd Date: Mon, 9 Jan 2017 22:01:45 -0600 Subject: [PATCH 4/8] [Python] Challenge_3 --- challenge_3/python/whiterd/README.md | 8 ++++++++ challenge_3/python/whiterd/src/find_major.py | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 challenge_3/python/whiterd/README.md create mode 100644 challenge_3/python/whiterd/src/find_major.py diff --git a/challenge_3/python/whiterd/README.md b/challenge_3/python/whiterd/README.md new file mode 100644 index 000000000..c90d61dbf --- /dev/null +++ b/challenge_3/python/whiterd/README.md @@ -0,0 +1,8 @@ +Find Majority Element +--------------------- + +* Given an array of size n, find the majority element. The majority element is the element that appears more than n/2 times. + +* Assume: + * the array is non-empty. + * the majority element always exist in the array. \ No newline at end of file diff --git a/challenge_3/python/whiterd/src/find_major.py b/challenge_3/python/whiterd/src/find_major.py new file mode 100644 index 000000000..f712576fd --- /dev/null +++ b/challenge_3/python/whiterd/src/find_major.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +''' + Input: An array of integers. + + Output: The single integer that occurs most often. +''' + +from __future__ import print_function +from collections import Counter + +given_array = [2,2,3,7,5,7,7,7,4,7,2,7,4,5,6,7,7,8,6,7,7,8,10,12,29,30,19,10,7,7,7,7,7,7,7,7,7] + +def find_major(array): + counted = Counter(array) + return counted.most_common(1)[0][0] + + +print(find_major(given_array)) From d81c93bc033e6a102ad6cc116a28475473fc6d2a Mon Sep 17 00:00:00 2001 From: whiterd Date: Tue, 10 Jan 2017 21:53:45 -0600 Subject: [PATCH 5/8] [Python] Challenge 4 (Unreviewed) --- challenge_4/python/whiterd/README.md | 7 +++++++ challenge_4/python/whiterd/src/invert_bin.py | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 challenge_4/python/whiterd/README.md create mode 100644 challenge_4/python/whiterd/src/invert_bin.py diff --git a/challenge_4/python/whiterd/README.md b/challenge_4/python/whiterd/README.md new file mode 100644 index 000000000..90a661a0e --- /dev/null +++ b/challenge_4/python/whiterd/README.md @@ -0,0 +1,7 @@ +# Invert Binary Tree + +* Take in a binary tree as a nested list. + +* For each level in the tree, reverse the order of the items in that level. + +* Output the resulting binary tree. \ 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..96cee1a5e --- /dev/null +++ b/challenge_4/python/whiterd/src/invert_bin.py @@ -0,0 +1,13 @@ +#!/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 From c11515ba70832d3b2f0ea18e7c808caa1efe4f44 Mon Sep 17 00:00:00 2001 From: whiterd Date: Wed, 11 Jan 2017 08:49:03 -0600 Subject: [PATCH 6/8] [Python] Challenge 4 (Unreviewed) --- challenge_4/python/whiterd/README.md | 6 +++--- challenge_4/python/whiterd/src/invert_bin.py | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/challenge_4/python/whiterd/README.md b/challenge_4/python/whiterd/README.md index 90a661a0e..da7eb3581 100644 --- a/challenge_4/python/whiterd/README.md +++ b/challenge_4/python/whiterd/README.md @@ -1,7 +1,7 @@ # Invert Binary Tree -* Take in a binary tree as a nested list. +* Take in a binary tree object. -* For each level in the tree, reverse the order of the items in that level. +* For each level in the tree, reverse the order of the items in that level (mirror). -* Output the resulting binary tree. \ No newline at end of file +* 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 index 96cee1a5e..194128418 100644 --- a/challenge_4/python/whiterd/src/invert_bin.py +++ b/challenge_4/python/whiterd/src/invert_bin.py @@ -11,3 +11,5 @@ def mirror(node): mirror(node.left) mirror(node.right) node.left, node.right = node.right, node.left + + return node From 575f1b45c2693f6e9f8c7189b6acebfebcf05d36 Mon Sep 17 00:00:00 2001 From: whiterd Date: Wed, 11 Jan 2017 16:09:29 -0600 Subject: [PATCH 7/8] [Python] Challenge 6 (Unreviewed) --- challenge_6/python/whiterd/src/id_ranges.py | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 challenge_6/python/whiterd/src/id_ranges.py 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)) From b7c91f8938e50c9694c557349cf8883c2ad3e195 Mon Sep 17 00:00:00 2001 From: whiterd Date: Wed, 11 Jan 2017 16:11:45 -0600 Subject: [PATCH 8/8] [Python] Challenge 6 (Unreviewed) --- challenge_6/python/whiterd/README.md | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 challenge_6/python/whiterd/README.md 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'] +``` + +