Skip to content

Commit 0a3496c

Browse files
committed
6kyu problems
1 parent 2cf9a5e commit 0a3496c

4 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎CodeWars/6kyu/bouncing_balls.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# A child is playing with a ball on the nth floor of a tall building.
2+
# The height of this floor, h, is known.
3+
4+
def bouncing_ball(h, bounce, window):
5+
if h > 0 and bounce > 0 and bounce < 1 and window < h:
6+
n = 0
7+
jump = False
8+
while h > window:
9+
h = bounce * h
10+
n += 1
11+
if jump:
12+
n += 1
13+
jump = True
14+
return n
15+
else:
16+
return - 1

‎CodeWars/6kyu/duplicate_encoder.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# The goal of this exercise is to convert a string to a new string where each
2+
# character in the new string is "(" if that character appears only once in the
3+
# original string, or ")" if that character appears more than once in the
4+
# original string. Ignore capitalization when determining if a character is a
5+
# duplicate.
6+
7+
def duplicate_encode(word):
8+
s = ''
9+
word = word.lower()
10+
for c in word:
11+
if word.count(c) > 1:
12+
s += ')'
13+
else:
14+
s += '('
15+
return s
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Given a string of words, you need to find the highest scoring word.
2+
# Each letter of a word scores points according to its position in the
3+
# alphabet: a = 1, b = 2, c = 3 etc.
4+
# You need to return the highest scoring word as a string.
5+
# If two words score the same, return the word that appears earliest in the
6+
# original string.
7+
# All letters will be lowercase and all inputs will be valid.
8+
9+
def high(x):
10+
s_word = ''
11+
s_score = 0
12+
for word in x.split(' '):
13+
score = 0
14+
for c in word:
15+
score += (ord(c) - 96) # ACII order
16+
if score > s_score:
17+
s_score = score
18+
s_word = word
19+
return s_word

‎CodeWars/6kyu/persistent_bugger.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Write a function, persistence, that takes in a positive parameter num and
2+
# returns its multiplicative persistence, which is the number of times you
3+
# must multiply the digits in num until you reach a single digit.
4+
5+
# (because 3*9 = 27, 2*7 = 14, 1*4 = 4 and 4 has only one digit)
6+
7+
def persistence(n):
8+
result = 0
9+
while n > 9:
10+
tmp = 1
11+
for i in str(n):
12+
tmp *= int(i)
13+
n = tmp
14+
result += 1
15+
return result

0 commit comments

Comments
 (0)