Skip to content

Commit b44005b

Browse files
committed
more 6kyu problems
1 parent 0a3496c commit b44005b

6 files changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# The parameter of the function find_nb will be an integer m and you have to
2+
# return the integer n such as n^3 + (n-1)^3 + ... + 1^3 = m if such a n exists
3+
# or -1 if there is no such n.
4+
5+
def find_nb(m):
6+
i = 0
7+
while m > 0:
8+
m -= (i + 1)**3
9+
i += 1
10+
return i if m == 0 else -1

CodeWars/6kyu/build_tower.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Build a pyramid-shaped tower given a positive integer number of floors.
2+
# A tower block is represented with "*" character.
3+
4+
def tower_builder(n_floors):
5+
return [('*' * (f * 2 - 1)).center(n_floors * 2 - 1) for f in range(1, n_floors + 1)]

CodeWars/6kyu/detect_pangram.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# A pangram is a sentence that contains every single letter of the alphabet at
2+
# least once. For example, the sentence "The quick brown fox jumps over
3+
# the lazy dog" is a pangram, because it uses the letters A-Z at least once
4+
# (case is irrelevant).
5+
# Given a string, detect whether or not it is a pangram. Return True if it is,
6+
# False if not. Ignore numbers and punctuation.
7+
8+
def is_pangram(s):
9+
return len([c for c in list(set(s.lower())) if c.isalpha()]) == 26
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# You live in the city of Cartesia where all roads are laid out in a perfect
2+
# grid. You arrived ten minutes too early to an appointment, so you decided to
3+
# take the opportunity to go for a short walk. The city provides its citizens
4+
# with a Walk Generating App on their phones -- everytime you press the button
5+
# it sends you an array of one-letter strings representing directions to walk
6+
# (eg. ['n', 's', 'w', 'e']). You always walk only a single block for each
7+
# letter (direction) and you know it takes you one minute to traverse one city
8+
# block, so create a function that will return true if the walk the app gives
9+
# you will take you exactly ten minutes (you don't want to be early or late!)
10+
# and will, of course, return you to your starting point. Return false
11+
# otherwise.
12+
13+
def is_valid_walk(walk):
14+
return len(walk) == 10 and walk.count('n') == walk.count('s') and walk.count('w') == walk.count('e')
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# There is a queue for the self-checkout tills at the supermarket. Your task is
2+
# write a function to calculate the total time required for all the customers
3+
# to check out!
4+
5+
def queue_time(customers, n):
6+
7+
ans = []
8+
9+
if n == 1:
10+
return sum(customers)
11+
else:
12+
till = []
13+
14+
for i in range(n):
15+
try:
16+
till.append((customers.pop(0), 0))
17+
except IndexError:
18+
break
19+
20+
while till:
21+
tmp = []
22+
for (c, t) in till:
23+
if c > 0:
24+
c -= 1
25+
t += 1
26+
tmp.append((c, t))
27+
else:
28+
try:
29+
tmp.append((customers.pop(0), t))
30+
except IndexError:
31+
ans.append((c,t))
32+
till = tmp
33+
34+
_, time = max(ans)
35+
return time
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# You will be given a number and you will need to return it as a string in Expanded Form.
2+
# NOTE: All numbers will be whole numbers greater than 0.
3+
4+
def expanded_form(num):
5+
i = 1
6+
res = []
7+
s = str(num)
8+
for c in s:
9+
n = c + '0' * (len(s) - i)
10+
if int(n) > 0: res.append(n)
11+
i += 1
12+
return ' + '.join(res)

0 commit comments

Comments
 (0)