Skip to content

Commit 489f33b

Browse files
randdaneerocs
authored andcommitted
First challenge (YearOfProgramming#309)
* challenge_0 in python * challenge_1 in python * [Python] Challenge_2 * [Python] Challenge_3
1 parent a7aecce commit 489f33b

File tree

8 files changed

+70
-0
lines changed

8 files changed

+70
-0
lines changed

challenge_0/python/whiterd/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
5+
print('Hello World!')

challenge_1/python/whiterd/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Input: string
3+
4+
Output: a reversed string of the given input
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
5+
user_input = input('Enter text to be reversed: ')
6+
7+
print(user_input[::-1])

challenge_2/python/whiterd/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Input: a list of integers.
3+
4+
Output: the only non-repeated integer.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
Input: An array of random integers where every integer is repeated except
5+
for a single one.
6+
7+
Output: The single integer that does NOT repeat.
8+
'''
9+
10+
from __future__ import print_function
11+
12+
array_1 = [2,3,4,2,3,5,4,6,4,6,9,10,9,8,7,8,10,7]
13+
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]
14+
15+
def find_distinct(array):
16+
for i in array:
17+
if array.count(i) == 1:
18+
return i
19+
20+
21+
if __name__ == '__main__':
22+
print(find_distinct(array_1))
23+
print(find_distinct(array_2))

challenge_3/python/whiterd/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Find Majority Element
2+
---------------------
3+
4+
* Given an array of size n, find the majority element. The majority element is the element that appears more than n/2 times.
5+
6+
* Assume:
7+
* the array is non-empty.
8+
* the majority element always exist in the array.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
Input: An array of integers.
5+
6+
Output: The single integer that occurs most often.
7+
'''
8+
9+
from __future__ import print_function
10+
from collections import Counter
11+
12+
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]
13+
14+
def find_major(array):
15+
counted = Counter(array)
16+
return counted.most_common(1)[0][0]
17+
18+
19+
print(find_major(given_array))

0 commit comments

Comments
 (0)