description stringlengths 38 154k | category stringclasses 5
values | solutions stringlengths 13 289k | name stringlengths 3 179 | id stringlengths 24 24 | tags listlengths 0 13 | url stringlengths 54 54 | rank_name stringclasses 8
values |
|---|---|---|---|---|---|---|---|
Bob needs a fast way to calculate the volume of a cuboid with three values: the `length`, `width` and `height` of the cuboid. Write a function to help Bob with this calculation.
```if:shell
In bash the script is ran with the following 3 arguments:
`length` `width` `height`
```
| reference | def get_volume_of_cuboid(length, width, height):
return length * width * height
# PEP8: kata function name should use snake_case not mixedCase
getVolumeOfCubiod = get_volume_of_cuboid
| Volume of a Cuboid | 58261acb22be6e2ed800003a | [
"Geometry",
"Fundamentals",
"Mathematics"
] | https://www.codewars.com/kata/58261acb22be6e2ed800003a | 8 kyu |
A child is playing with a ball on the nth floor of a tall building.
The height of this floor above ground level, *h*, is known.
He drops the ball out of the window. The ball bounces (for example), to two-thirds of its height (a bounce of 0.66).
His mother looks out of a window 1.5 meters from the ground.
How many ... | reference | def bouncingBall(h, bounce, window):
if not 0 < bounce < 1:
return - 1
count = 0
while h > window:
count += 1
h *= bounce
if h > window:
count += 1
return count or - 1
| Bouncing Balls | 5544c7a5cb454edb3c000047 | [
"Puzzles",
"Algorithms",
"Mathematics"
] | https://www.codewars.com/kata/5544c7a5cb454edb3c000047 | 6 kyu |
Create a function that takes a positive integer and returns the next bigger number that can be formed by rearranging its digits. For example:
```
12 ==> 21
513 ==> 531
2017 ==> 2071
```
If the digits can't be rearranged to form a bigger number, return `-1` (or `nil` in Swift, `None` in Rust):
```
9 ==> -1
111 =... | refactoring | import itertools
def next_bigger(n):
s = list(str(n))
for i in range(len(s) - 2, - 1, - 1):
if s[i] < s[i + 1]:
t = s[i:]
m = min(filter(lambda x: x > t[0], t))
t . remove(m)
t . sort()
s[i:] = [m] + t
return int("" . join(s))
return - 1
| Next bigger number with the same digits | 55983863da40caa2c900004e | [
"Strings",
"Refactoring"
] | https://www.codewars.com/kata/55983863da40caa2c900004e | 4 kyu |
The year is 1214. One night, Pope Innocent III awakens to find the the archangel Gabriel floating before him. Gabriel thunders to the pope:
> Gather all of the learned men in Pisa, especially Leonardo Fibonacci. In order for the crusades in the holy lands to be successful, these men must calculate the *millionth* nu... | algorithms | def fib(n):
if n < 0:
return (- 1) * * (n % 2 + 1) * fib(- n)
a = b = x = 1
c = y = 0
while n:
if n % 2 == 0:
(a, b, c) = (a * a + b * b,
a * b + b * c,
b * b + c * c)
n /= 2
else:
(x, y) = (a * x + b * y,
b * x + c... | The Millionth Fibonacci Kata | 53d40c1e2f13e331fc000c26 | [
"Mathematics",
"Algorithms"
] | https://www.codewars.com/kata/53d40c1e2f13e331fc000c26 | 3 kyu |
### Task
You've just moved into a perfectly straight street with exactly ```n``` identical houses on either side of the road. Naturally, you would like to find out the house number of the people on the other side of the street. The street looks something like this:
--------------------
### Street
```
1| |6
3| |4
... | reference | def over_the_road(address, n):
'''
Input: address (int, your house number), n (int, length of road in houses)
Returns: int, number of the house across from your house.
'''
# this is as much a math problem as a coding one
# if your house is [even/odd], the opposite house will be [odd/even]
... | Over The Road | 5f0ed36164f2bc00283aed07 | [
"Fundamentals",
"Mathematics",
"Performance"
] | https://www.codewars.com/kata/5f0ed36164f2bc00283aed07 | 7 kyu |
There is an array with some numbers. All numbers are equal except for one. Try to find it!
```javascript
findUniq([ 1, 1, 1, 2, 1, 1 ]) === 2
findUniq([ 0, 0, 0.55, 0, 0 ]) === 0.55
```
```swift
findUniq([ 1, 1, 1, 2, 1, 1 ]) == 2
findUniq([ 0, 0, 0.55, 0, 0 ]) == 0.55
```
```ruby
find_uniq([ 1, 1, 1, 2, 1, 1 ]) == ... | reference | def find_uniq(arr):
a, b = set(arr)
return a if arr . count(a) == 1 else b
| Find the unique number | 585d7d5adb20cf33cb000235 | [
"Fundamentals",
"Algorithms",
"Arrays"
] | https://www.codewars.com/kata/585d7d5adb20cf33cb000235 | 6 kyu |
Your task is to construct a building which will be a pile of n cubes.
The cube at the bottom will have a volume of `$ n^3 $`, the cube above
will have volume of `$ (n-1)^3 $` and so on until the top which will have a volume of `$ 1^3 $`.
You are given the total volume m of the building.
Being given m can you find th... | reference | def find_nb(m):
n = 1
volume = 0
while volume < m:
volume += n * * 3
if volume == m:
return n
n += 1
return - 1
| Build a pile of Cubes | 5592e3bd57b64d00f3000047 | [
"Mathematics",
"Algorithms"
] | https://www.codewars.com/kata/5592e3bd57b64d00f3000047 | 6 kyu |
Write a function, `persistence`, that takes in a positive parameter `num` and returns its multiplicative persistence, which is the number of times you must multiply the digits in `num` until you reach a single digit.
For example **(Input --> Output)**:
```
39 --> 3 (because 3*9 = 27, 2*7 = 14, 1*4 = 4 and 4 has only ... | reference | def persistence(n):
n = str(n)
count = 0
while len(n) > 1:
p = 1
for i in n:
p *= int(i)
n = str(p)
count += 1
return count
# your code
| Persistent Bugger. | 55bf01e5a717a0d57e0000ec | [
"Fundamentals",
"Mathematics"
] | https://www.codewars.com/kata/55bf01e5a717a0d57e0000ec | 6 kyu |
The cockroach is one of the fastest insects. Write a function which takes its speed in km per hour and returns it in cm per second, rounded down to the integer (= floored).
For example:
```
1.08 --> 30
```
Note! The input is a Real number (actual type is language dependent) and is >= 0. The result should be an Integ... | reference | def cockroach_speed(s):
return s / / 0.036
| Beginner Series #4 Cockroach | 55fab1ffda3e2e44f00000c6 | [
"Fundamentals"
] | https://www.codewars.com/kata/55fab1ffda3e2e44f00000c6 | 8 kyu |
# Don't give me five!
In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive!
**Examples:**
```
1,9 -> 1,2,3,4,6,7,8,9 -> Result 8
4,17 -> 4,6,7,8,9,10,11,12,13,14,16,17 -> Result 1... | algorithms | def dont_give_me_five(start, end):
return sum('5' not in str(i) for i in range(start, end + 1))
| Don't give me five! | 5813d19765d81c592200001a | [
"Mathematics",
"Arrays",
"Algorithms"
] | https://www.codewars.com/kata/5813d19765d81c592200001a | 7 kyu |
Create a function `close_compare` that accepts 3 parameters: `a`, `b`, and an optional `margin`. The function should return whether `a` is lower than, close to, or higher than `b`.
Please note the following:
- When `a` is close to `b`, return `0`.
- For this challenge, `a` is considered "close to" `b` if `margin` ... | reference | def close_compare(a, b, margin=0):
return 0 if abs(a - b) <= margin else - 1 if b > a else 1
| Compare within margin | 56453a12fcee9a6c4700009c | [
"Fundamentals",
"Logic"
] | https://www.codewars.com/kata/56453a12fcee9a6c4700009c | 8 kyu |
```if-not:swift
Create a function that accepts a list/array and a number **n**, and returns a list/array of the first **n** elements from the list/array.
If you need help, here's a reference:
```
```if:swift
Create a function *take* that takes an `Array<Int>` and an `Int`, *n*, and returns an `Array<Int>` containing t... | reference | def take(arr, n):
return arr[: n]
| Enumerable Magic #25 - Take the First N Elements | 545afd0761aa4c3055001386 | [
"Fundamentals"
] | https://www.codewars.com/kata/545afd0761aa4c3055001386 | 8 kyu |
Removed due to copyright infringement.
<!---
 Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting of uppercase and lowercase Latin letters, it:
* deletes all the vowels,
* ins... | reference | def string_task(s):
return '' . join(f'. { a } ' for a in s . lower() if a not in 'aoyeui')
| String Task | 598ab63c7367483c890000f4 | [
"Fundamentals",
"Strings",
"Data Types",
"Regular Expressions",
"Declarative Programming",
"Advanced Language Features",
"Programming Paradigms"
] | https://www.codewars.com/kata/598ab63c7367483c890000f4 | 7 kyu |
You will be given an array `a` and a value `x`. All you need to do is check whether the provided array contains the value.
~~~if:swift
The type of `a` and `x` can be `String` or `Int`.
~~~
~~~if-not:swift
Array can contain numbers or strings. X can be either.
~~~
~~~if:racket
In racket, you'll be given a list instead ... | reference | def check(seq, elem):
return elem in seq
| You only need one - Beginner | 57cc975ed542d3148f00015b | [
"Fundamentals",
"Strings",
"Arrays"
] | https://www.codewars.com/kata/57cc975ed542d3148f00015b | 8 kyu |
I love Fibonacci numbers in general, but I must admit I love some more than others.
I would like for you to write me a function that, when given a number `n` (`n >= 1` ), returns the n<sup>th</sup> number in the Fibonacci Sequence.
For example:
```javascript
nthFibo(4) == 2
```
```coffeescript
nthFibo(4) == 2... | algorithms | def nth_fib(n):
a, b = 0, 1
for i in range(n - 1):
a, b = b, a + b
return a
| N-th Fibonacci | 522551eee9abb932420004a0 | [
"Algorithms"
] | https://www.codewars.com/kata/522551eee9abb932420004a0 | 6 kyu |
Jenny has written a function that returns a greeting for a user. However, she's in love with Johnny, and would like to greet him slightly different. She added a special case to her function, but she made a mistake.
Can you help her? | bug_fixes | def greet(name):
if name == "Johnny":
return "Hello, my love!"
return "Hello, {name}!" . format(name=name)
| Jenny's secret message | 55225023e1be1ec8bc000390 | [
"Debugging"
] | https://www.codewars.com/kata/55225023e1be1ec8bc000390 | 8 kyu |
Your task is to make two functions ( `max` and `min`, or `maximum` and `minimum`, etc., depending on the language ) that receive a list of integers as input, and return the largest and lowest number in that list, respectively.
### Examples (Input -> Output)
```
* [4,6,2,1,9,63,-134,566] -> max = 566, min = -1... | reference | def minimum(arr):
return min(arr)
def maximum(arr):
return max(arr)
| Find Maximum and Minimum Values of a List | 577a98a6ae28071780000989 | [
"Fundamentals"
] | https://www.codewars.com/kata/577a98a6ae28071780000989 | 8 kyu |
I would like to be able to pass an array with two elements to my swapValues function to swap the values. However it appears that the values aren't changing.
Can you figure out what's wrong here? | bug_fixes | def swap_values(args):
args[0], args[1] = args[1], args[0]
return args
| Swap Values | 5388f0e00b24c5635e000fc6 | [
"Debugging",
"Arrays",
"Fundamentals"
] | https://www.codewars.com/kata/5388f0e00b24c5635e000fc6 | 8 kyu |
A natural number is called **k-prime** if it has exactly `k` prime factors, counted with multiplicity. For example:
```
k = 2 --> 4, 6, 9, 10, 14, 15, 21, 22, ...
k = 3 --> 8, 12, 18, 20, 27, 28, 30, ...
k = 5 --> 32, 48, 72, 80, 108, 112, ...
```
A natural number is thus prime if and only if it is 1-prime.
####... | reference | def count_Kprimes(k, start, end):
return [n for n in range(start, end + 1) if find_k(n) == k]
def puzzle(s):
a = count_Kprimes(1, 0, s)
b = count_Kprimes(3, 0, s)
c = count_Kprimes(7, 0, s)
return sum(1 for x in a for y in b for z in c if x + y + z == s)
def find_k(n):
res ... | k-Primes | 5726f813c8dcebf5ed000a6b | [
"Number Theory",
"Mathematics",
"Algorithms"
] | https://www.codewars.com/kata/5726f813c8dcebf5ed000a6b | 5 kyu |
~~~if:sql
Write a select statement that takes `name` from `person` table and return `"Hello, <name> how are you doing today?"` results in a column named `greeting`
~~~
~~~if-not:sql
Make a function that will return a greeting statement that uses an input; your program should return, `"Hello, <name> how are you doing to... | reference | def greet(name):
return f'Hello, { name } how are you doing today?'
| Returning Strings | 55a70521798b14d4750000a4 | [
"Strings",
"Fundamentals"
] | https://www.codewars.com/kata/55a70521798b14d4750000a4 | 8 kyu |
## Your Job
Find the sum of all multiples of `n` below `m`
## Keep in Mind
* `n` and `m` are natural numbers (positive integers)
* `m` is **excluded** from the multiples
## Examples
```javascript
sumMul(2, 9) ==> 2 + 4 + 6 + 8 = 20
sumMul(3, 13) ==> 3 + 6 + 9 + 12 = 30
sumMul(4, 123) ==> 4 + 8 ... | reference | def sum_mul(n, m):
if m > 0 and n > 0:
return sum(range(n, m, n))
else:
return 'INVALID'
| Sum of Multiples | 57241e0f440cd279b5000829 | [
"Fundamentals"
] | https://www.codewars.com/kata/57241e0f440cd279b5000829 | 8 kyu |
## Objective
Given a number `n` we will define it's sXORe to be `0 XOR 1 XOR 2 ... XOR n` where `XOR` is the [bitwise XOR operator](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Write a function that takes `n` and returns it's sXORe.
## Examples
| n | sXORe n
|---------|--------
| 0 | 0
... | algorithms | def sxore(n):
return [n, 1, n + 1, 0][n % 4]
| Binary sXORe | 56d3e702fc231fdf72001779 | [
"Binary",
"Algorithms"
] | https://www.codewars.com/kata/56d3e702fc231fdf72001779 | 7 kyu |
Given an array of integers, find the one that appears an odd number of times.
There will always be only one integer that appears an odd number of times.
### Examples
`[7]` should return `7`, because it occurs 1 time (which is odd).
`[0]` should return `0`, because it occurs 1 time (which is odd).
`[1,1,2]` shou... | reference | def find_it(seq):
for i in seq:
if seq . count(i) % 2 != 0:
return i
| Find the odd int | 54da5a58ea159efa38000836 | [
"Fundamentals"
] | https://www.codewars.com/kata/54da5a58ea159efa38000836 | 6 kyu |
Take the following IPv4 address: `128.32.10.1`
This address has 4 octets where each octet is a single byte (or 8 bits).
* 1st octet `128` has the binary representation: `10000000`
* 2nd octet `32` has the binary representation: `00100000`
* 3rd octet `10` has the binary representation: `00001010`
* 4th octet `1` has ... | algorithms | from ipaddress import IPv4Address
def int32_to_ip(int32):
return str(IPv4Address(int32))
| int32 to IPv4 | 52e88b39ffb6ac53a400022e | [
"Networks",
"Bits",
"Algorithms"
] | https://www.codewars.com/kata/52e88b39ffb6ac53a400022e | 5 kyu |
Determine the total number of digits in the integer (`n>=0`) given as input to the function. For example, 9 is a single digit, 66 has 2 digits and 128685 has 6 digits. Be careful to avoid overflows/underflows.
All inputs will be valid. | reference | def digits(n):
return len(str(n))
| Number of Decimal Digits | 58fa273ca6d84c158e000052 | [
"Strings",
"Fundamentals"
] | https://www.codewars.com/kata/58fa273ca6d84c158e000052 | 7 kyu |
Your job is to create a calculator which evaluates expressions in [Reverse Polish notation](http://en.wikipedia.org/wiki/Reverse_Polish_notation).
For example expression `5 1 2 + 4 * + 3 -` (which is equivalent to `5 + ((1 + 2) * 4) - 3` in normal notation) should evaluate to `14`.
For your convenience, the input is ... | algorithms | import operator
def calc(expr):
OPERATORS = {'+': operator . add, '-': operator . sub,
'*': operator . mul, '/': operator . truediv}
stack = [0]
for token in expr . split(" "):
if token in OPERATORS:
op2, op1 = stack . pop(), stack . pop()
stack . append(OPERATORS[to... | Reverse polish notation calculator | 52f78966747862fc9a0009ae | [
"Algorithms",
"Mathematics",
"Interpreters",
"Parsing",
"Strings"
] | https://www.codewars.com/kata/52f78966747862fc9a0009ae | 6 kyu |
You were camping with your friends far away from home, but when it's time to go back, you realize that your fuel is running out and the nearest pump is `50` miles away! You know that on average, your car runs on about `25` miles per gallon. There are `2` gallons left.
Considering these factors, write a function that ... | reference | def zeroFuel(distance_to_pump, mpg, fuel_left):
return distance_to_pump <= mpg * fuel_left
| Will you make it? | 5861d28f124b35723e00005e | [
"Mathematics",
"Fundamentals"
] | https://www.codewars.com/kata/5861d28f124b35723e00005e | 8 kyu |
You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return `-1`.
### For example:
Let's say you are given the array `{1... | reference | def find_even_index(arr):
for i in range(len(arr)):
if sum(arr[: i]) == sum(arr[i + 1:]):
return i
return - 1
| Equal Sides Of An Array | 5679aa472b8f57fb8c000047 | [
"Algorithms",
"Arrays",
"Fundamentals"
] | https://www.codewars.com/kata/5679aa472b8f57fb8c000047 | 6 kyu |
Given an array of integers as strings and numbers, return the sum of the array values as if all were numbers.
Return your answer as a number. | reference | def sum_mix(arr):
return sum(map(int, arr))
| Sum Mixed Array | 57eaeb9578748ff92a000009 | [
"Fundamentals",
"Strings",
"Arrays"
] | https://www.codewars.com/kata/57eaeb9578748ff92a000009 | 8 kyu |
Given a number, write a function to output its reverse digits. (e.g. given 123 the answer is 321)
Numbers should preserve their sign; i.e. a negative number should still be negative when reversed.
### Examples
```
123 -> 321
-456 -> -654
1000 -> 1
``` | games | def reverseNumber(n):
if n < 0:
return - reverseNumber(- n)
return int(str(n)[:: - 1])
| Reverse a Number | 555bfd6f9f9f52680f0000c5 | [
"Algorithms",
"Fundamentals"
] | https://www.codewars.com/kata/555bfd6f9f9f52680f0000c5 | 7 kyu |
Return the Nth Even Number
Example(**Input** --> **Output**)
```
1 --> 0 (the first even number is 0)
3 --> 4 (the 3rd even number is 4 (0, 2, 4))
100 --> 198
1298734 --> 2597466
```
The input will not be 0. | games | def nth_even(n):
return 2 * (n - 1)
| Get Nth Even Number | 5933a1f8552bc2750a0000ed | [
"Mathematics",
"Puzzles",
"Algorithms"
] | https://www.codewars.com/kata/5933a1f8552bc2750a0000ed | 8 kyu |
Create function fib that returns n'th element of Fibonacci sequence (classic programming task).
~~~if:lambdacalc
#### Encodings
`numEncoding: Scott`
~~~ | reference | def fibonacci(n: int) - > int:
"""Given a positive argument n, returns the nth term of the Fibonacci Sequence.
"""
x, y = 0, 1
for i in range(n):
x, y = y, y + x
return x
| Fibonacci | 57a1d5ef7cb1f3db590002af | [
"Fundamentals",
"Algorithms"
] | https://www.codewars.com/kata/57a1d5ef7cb1f3db590002af | 7 kyu |
A stream of data is received and needs to be reversed.
Each segment is 8 bits long, meaning the order of these segments needs to be reversed, for example:
```
11111111 00000000 00001111 10101010
(byte1) (byte2) (byte3) (byte4)
```
should become:
```
10101010 00001111 00000000 11111111
(byte4) (byte3... | reference | def data_reverse(data):
res = []
for i in range(len(data) - 8, - 1, - 8):
res . extend(data[i: i + 8])
return res
| Data Reverse | 569d488d61b812a0f7000015 | [
"Arrays",
"Fundamentals"
] | https://www.codewars.com/kata/569d488d61b812a0f7000015 | 6 kyu |
## Task
You will be given an array of numbers. You have to sort the odd numbers in ascending order while leaving the even numbers at their original positions.
### Examples
```
[7, 1] => [1, 7]
[5, 8, 6, 3, 4] => [3, 8, 6, 5, 4]
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0] => [1, 8, 3, 6, 5, 4, 7, 2, 9, 0]
```
~~~if:lambdac... | reference | def sort_array(arr):
odds = sorted((x for x in arr if x % 2 != 0), reverse=True)
return [x if x % 2 == 0 else odds . pop() for x in arr]
| Sort the odd | 578aa45ee9fd15ff4600090d | [
"Fundamentals",
"Arrays",
"Sorting"
] | https://www.codewars.com/kata/578aa45ee9fd15ff4600090d | 6 kyu |
My friend John and I are members of the "Fat to Fit Club (FFC)". John is worried because
each month a list with the weights of members is published and each month he is the last on the list
which means he is the heaviest.
I am the one who establishes the list so I told him:
"Don't worry any more, I will modify the or... | algorithms | def order_weight(_str):
return ' ' . join(sorted(sorted(_str . split(' ')), key=lambda x: sum(int(c) for c in x)))
| Weight for weight | 55c6126177c9441a570000cc | [
"Algorithms"
] | https://www.codewars.com/kata/55c6126177c9441a570000cc | 5 kyu |
Take 2 strings `s1` and `s2` including only letters from `a` to `z`.
Return a new **sorted** string, the longest possible, containing distinct letters - each taken only once - coming from s1 or s2.
#### Examples:
```
a = "xyaabbbccccdefww"
b = "xxxxyyyyabklmopq"
longest(a, b) -> "abcdefklmopqwxy"
a = "abcdefghijklmno... | reference | def longest(a1, a2):
return "" . join(sorted(set(a1 + a2)))
| Two to One | 5656b6906de340bd1b0000ac | [
"Fundamentals"
] | https://www.codewars.com/kata/5656b6906de340bd1b0000ac | 7 kyu |
### Lyrics...
Pyramids are amazing! Both in architectural and mathematical sense. If you have a computer, you can mess with pyramids even if you are not in Egypt at the time. For example, let's consider the following problem. Imagine that you have a pyramid built of numbers, like this one here:
```
/3/
\7\ 4
2... | algorithms | def longest_slide_down(p):
res = p . pop()
while p:
tmp = p . pop()
res = [tmp[i] + max(res[i], res[i + 1]) for i in range(len(tmp))]
return res . pop()
| Pyramid Slide Down | 551f23362ff852e2ab000037 | [
"Algorithms",
"Dynamic Programming"
] | https://www.codewars.com/kata/551f23362ff852e2ab000037 | 4 kyu |
A `Nice array` is defined to be an array where for every value `n` in the array, there is also an element `n - 1` or `n + 1` in the array.
examples:
```
[2, 10, 9, 3] is a nice array because
2 = 3 - 1
10 = 9 + 1
3 = 2 + 1
9 = 10 - 1
[4, 2, 3] is a nice array because
4 = 3 + 1
2 = 3 - 1
3 = 2 + 1 (or 3 = 4 - ... | reference | def is_nice(arr):
s = set(arr)
return bool(arr) and all(n + 1 in s or n - 1 in s for n in s)
| Nice Array | 59b844528bcb7735560000a0 | [
"Arrays",
"Mathematics",
"Fundamentals"
] | https://www.codewars.com/kata/59b844528bcb7735560000a0 | 7 kyu |
This time no story, no theory. The examples below show you how to write function `accum`:
#### Examples:
```
accum("abcd") -> "A-Bb-Ccc-Dddd"
accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
accum("cwAt") -> "C-Ww-Aaa-Tttt"
```
The parameter of accum is a string which includes only letters from `a..z` and `A.... | reference | def accum(s):
return '-' . join(c . upper() + c . lower() * i for i, c in enumerate(s))
| Mumbling | 5667e8f4e3f572a8f2000039 | [
"Fundamentals",
"Strings",
"Puzzles"
] | https://www.codewars.com/kata/5667e8f4e3f572a8f2000039 | 7 kyu |
As you probably know, Fibonacci sequence are the numbers in the following integer sequence:
1, 1, 2, 3, 5, 8, 13...
Write a method that takes the index as an argument and returns last digit from fibonacci number. Example:
getLastDigit(15) - 610. Your method must return 0 because the last digit of 610 is 0.
Fibonacci ... | algorithms | def get_last_digit(index):
a, b = 0, 1
for _ in range(index):
a, b = b, (a + b) % 10
return a
| Find Fibonacci last digit | 56b7251b81290caf76000978 | [
"Algorithms"
] | https://www.codewars.com/kata/56b7251b81290caf76000978 | 7 kyu |
Given two arrays of strings `a1` and `a2` return a sorted array `r` in lexicographical order of the strings of `a1` which are substrings of strings of `a2`.
#### Example 1:
`a1 = ["arp", "live", "strong"]`
`a2 = ["lively", "alive", "harp", "sharp", "armstrong"]`
returns `["arp", "live", "strong"]`
#### Example 2:
`... | refactoring | def in_array(array1, array2):
# your code
res = []
for a1 in array1:
for a2 in array2:
if a1 in a2 and not a1 in res:
res . append(a1)
res . sort()
return res
| Which are in? | 550554fd08b86f84fe000a58 | [
"Arrays",
"Lists",
"Strings",
"Refactoring"
] | https://www.codewars.com/kata/550554fd08b86f84fe000a58 | 6 kyu |
Given two integers `a` and `b`, which can be positive or negative, find the sum of all the integers between and including them and return it. If the two numbers are equal return `a` or `b`.
**Note:** `a` and `b` are not ordered!
## Examples (a, b) --> output (explanation)
```
(1, 0) --> 1 (1 + 0 = 1)
(1, 2) --> 3 (1... | reference | def get_sum(a, b):
return sum(range(min(a, b), max(a, b) + 1))
| Beginner Series #3 Sum of Numbers | 55f2b110f61eb01779000053 | [
"Fundamentals",
"Algorithms"
] | https://www.codewars.com/kata/55f2b110f61eb01779000053 | 7 kyu |
Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements.
```php
moveZeros([false,1,0,1,2,0,1,3,"a"]) // returns[false,1,1,2,1,3,"a",0,0]
```
```javascript
moveZeros([false,1,0,1,2,0,1,3,"a"]) // returns[false,1,1,2,1,3,"a",0,0]
```
```python
move_zeros([... | algorithms | def move_zeros(array):
for i in array:
if i == 0:
array . remove(i) # Remove the element from the array
array . append(i) # Append the element to the end
return array
| Moving Zeros To The End | 52597aa56021e91c93000cb0 | [
"Arrays",
"Sorting",
"Algorithms"
] | https://www.codewars.com/kata/52597aa56021e91c93000cb0 | 5 kyu |
Your goal is to return multiplication table for ```number``` that is always an integer from 1 to 10.
For example, a multiplication table (string) for ```number == 5``` looks like below:
```
1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50
```
```if-not:pow... | reference | def multi_table(number):
return '\n' . join(f' { i } * { number } = { i * number } ' for i in range(1, 11))
| Multiplication table for number | 5a2fd38b55519ed98f0000ce | [
"Fundamentals",
"Strings"
] | https://www.codewars.com/kata/5a2fd38b55519ed98f0000ce | 8 kyu |
Give the summation of all even numbers in a Fibonacci sequence up to, but not including, the number passed to your function. Or, in other words, sum all the even Fibonacci numbers that are lower than the given number n (n is not the nth element of Fibonacci sequence) without including n.
The Fibonacci sequence is a se... | algorithms | def even_fib(m):
x, y = 0, 1
counter = 0
while y < m:
if y % 2 == 0:
counter += y
x, y = y, x + y
return counter
| Even Fibonacci Sum | 55688b4e725f41d1e9000065 | [
"Algorithms"
] | https://www.codewars.com/kata/55688b4e725f41d1e9000065 | 6 kyu |
Character recognition software is widely used to digitise printed texts. Thus the texts can be edited, searched and stored on a computer.
When documents (especially pretty old ones written with a typewriter), are digitised character recognition softwares often make mistakes.
Your task is correct the errors in the dig... | reference | def correct(string):
return string . translate(str . maketrans("501", "SOI"))
| Correct the mistakes of the character recognition software | 577bd026df78c19bca0002c0 | [
"Fundamentals",
"Strings"
] | https://www.codewars.com/kata/577bd026df78c19bca0002c0 | 8 kyu |
## Task
Sum all the numbers of a given array ( cq. list ), except the highest and the lowest element ( by value, not by index! ).
The highest or lowest element respectively is a single element at each edge, even if there are more than one with the same value.
Mind the input validation.
## Example
{ 6, 2, 1, 8,... | reference | def sum_array(arr):
if arr == None or len(arr) < 3:
return 0
return sum(arr) - max(arr) - min(arr)
| Sum without highest and lowest number | 576b93db1129fcf2200001e6 | [
"Fundamentals"
] | https://www.codewars.com/kata/576b93db1129fcf2200001e6 | 8 kyu |
# Messi goals function
[Messi](https://en.wikipedia.org/wiki/Lionel_Messi) is a soccer player with goals in three leagues:
- LaLiga
- Copa del Rey
- Champions
Complete the function to return his total number of goals in all three leagues.
Note: the input will always be valid.
For example:
```
5, 10, 2 --> 17
`... | reference | def goals(* a):
return sum(a)
| Grasshopper - Messi goals function | 55f73be6e12baaa5900000d4 | [
"Fundamentals"
] | https://www.codewars.com/kata/55f73be6e12baaa5900000d4 | 8 kyu |
Write a function which takes a number and returns the corresponding ASCII char for that value.
Example:
```
65 --> 'A'
97 --> 'a'
48 --> '0
```
For ASCII table, you can refer to http://www.asciitable.com/
| reference | def get_char(c):
return chr(c)
| get character from ASCII Value | 55ad04714f0b468e8200001c | [
"Fundamentals"
] | https://www.codewars.com/kata/55ad04714f0b468e8200001c | 8 kyu |
Numbers ending with zeros are boring.
They might be fun in your world, but not here.
Get rid of them. Only the ending ones.
1450 -> 145
960000 -> 96
1050 -> 105
-1050 -> -105
Zero alone is fine, don't worry about it. Poor guy anyway | reference | def no_boring_zeros(n):
try:
return int(str(n). rstrip('0'))
except ValueError:
return 0
| No zeros for heros | 570a6a46455d08ff8d001002 | [
"Fundamentals"
] | https://www.codewars.com/kata/570a6a46455d08ff8d001002 | 8 kyu |
<img src="https://i.imgur.com/ta6gv1i.png?1" />
<!-- Featured 30/6/2021 -->
# Kata Task
I have a cat and a dog.
I got them at the same time as kitten/puppy. That was `humanYears` years ago.
Return their respective ages now as [`humanYears`,`catYears`,`dogYears`]
NOTES:
* `humanYears` >= 1
* `humanYears` are whole ... | reference | def human_years_cat_years_dog_years(human_years):
catYears = 0
dogYears = 0
if human_years == 1:
catYears += 15
dogYears += 15
return [human_years, catYears, dogYears]
elif human_years == 2:
catYears += 24
dogYears += 24
return [human_years, catYears, dogYears]
elif human_yea... | Cat years, Dog years | 5a6663e9fd56cb5ab800008b | [
"Fundamentals"
] | https://www.codewars.com/kata/5a6663e9fd56cb5ab800008b | 8 kyu |
HELP! Jason can't find his textbook! It is two days before the test date, and Jason's textbooks are all out of order! Help him sort a list (ArrayList in java) full of textbooks by subject, so he can study before the test.
The sorting should **NOT** be case sensitive | reference | def sorter(textbooks):
return sorted(textbooks, key=str . lower)
| Sort My Textbooks | 5a07e5b7ffe75fd049000051 | [
"Lists",
"Sorting",
"Fundamentals",
"Arrays"
] | https://www.codewars.com/kata/5a07e5b7ffe75fd049000051 | 8 kyu |
Write a function that rotates a two-dimensional array (a matrix) either clockwise or anti-clockwise by 90 degrees, and returns the rotated array.
The function accepts two parameters: a matrix, and a string specifying the direction or rotation. The direction will be either `"clockwise"` or `"counter-clockwise"`.
## ... | algorithms | import numpy as np
d = {"clockwise": 3, "counter-clockwise": 1}
def rotate(matrix, direction):
return np . rot90(matrix, d[direction]). tolist()
| Rotate an array matrix | 525a566985a9a47bc8000670 | [
"Matrix",
"Arrays",
"Algorithms"
] | https://www.codewars.com/kata/525a566985a9a47bc8000670 | 5 kyu |
For every good kata idea there seem to be quite a few bad ones!
In this kata you need to check the provided array (x) for good ideas 'good' and bad ideas 'bad'. If there are one or two good ideas, return 'Publish!', if there are more than 2 return 'I smell a series!'. If there are no good ideas, as is often the case, ... | refactoring | def well(x):
c = x . count('good')
return 'I smell a series!' if c > 2 else 'Publish!' if c else 'Fail!'
| Well of Ideas - Easy Version | 57f222ce69e09c3630000212 | [
"Fundamentals",
"Arrays",
"Strings",
"Refactoring"
] | https://www.codewars.com/kata/57f222ce69e09c3630000212 | 8 kyu |
Welcome. In this kata, you are asked to square every digit of a number and concatenate them.
For example, if we run 9119 through the function, 811181 will come out, because 9<sup>2</sup> is 81 and 1<sup>2</sup> is 1. (81-1-1-81)
Example #2: An input of 765 will/should return 493625 because 7<sup>2</sup> is 49, 6<sup>... | reference | def square_digits(num):
ret = ""
for x in str(num):
ret += str(int(x) * * 2)
return int(ret)
| Square Every Digit | 546e2562b03326a88e000020 | [
"Mathematics",
"Fundamentals"
] | https://www.codewars.com/kata/546e2562b03326a88e000020 | 7 kyu |
Write a function that merges two sorted arrays into a single one. The arrays only contain integers. Also, the final outcome must be sorted and not have any duplicate.
| reference | def merge_arrays(a, b):
return sorted(set(a + b))
| Merging sorted integer arrays (without duplicates) | 573f5c61e7752709df0005d2 | [
"Arrays",
"Fundamentals"
] | https://www.codewars.com/kata/573f5c61e7752709df0005d2 | 8 kyu |
The code provided is supposed replace all the dots `.` in the specified String `str` with dashes `-`
But it's not working properly.
# Task
Fix the bug so we can all go home early.
# Notes
String `str` will never be null. | bug_fixes | def replace_dots(string):
return string . replace('.', '-')
| FIXME: Replace all dots | 596c6eb85b0f515834000049 | [
"Debugging"
] | https://www.codewars.com/kata/596c6eb85b0f515834000049 | 8 kyu |
This function should test if the `factor` is a factor of `base`.
Return `true` if it is a factor or `false` if it is not.
## About factors
Factors are numbers you can multiply together to get another number.
2 and 3 are factors of 6 because: `2 * 3 = 6`
- You can find a factor by dividing numbers. If the remainder ... | reference | def check_for_factor(base, factor):
return base % factor == 0
| Grasshopper - Check for factor | 55cbc3586671f6aa070000fb | [
"Mathematics",
"Fundamentals"
] | https://www.codewars.com/kata/55cbc3586671f6aa070000fb | 8 kyu |
This kata is about multiplying a given number by eight if it is an even number and by nine otherwise. | reference | def simple_multiplication(number):
return number * 9 if number % 2 else number * 8
| Simple multiplication | 583710ccaa6717322c000105 | [
"Fundamentals"
] | https://www.codewars.com/kata/583710ccaa6717322c000105 | 8 kyu |
# Convert number to reversed array of digits
Given a random non-negative number, you have to return the digits of this number within an array in reverse order.
## Example(Input => Output):
```
35231 => [1,3,2,5,3]
0 => [0]
```
| reference | def digitize(n):
return [int(x) for x in str(n)[:: - 1]]
| Convert number to reversed array of digits | 5583090cbe83f4fd8c000051 | [
"Arrays",
"Fundamentals"
] | https://www.codewars.com/kata/5583090cbe83f4fd8c000051 | 8 kyu |
## Longest Common Subsequence (Performance version)
from [Wikipedia](http://en.wikipedia.org/wiki/Longest_common_subsequence_problem):
The longest common subsequence (LCS) problem is the problem of finding the longest subsequence common to all sequences in a set of sequences.
It differs from problems of finding co... | algorithms | from functools import lru_cache
@ lru_cache(None)
def lcs(x, y):
if not (x and y):
return ''
if x[0] == y[0]:
return x[0] + lcs(x[1:], y[1:])
return max(lcs(x, y[1:]), lcs(x[1:], y), key=len)
| Longest Common Subsequence (Performance version) | 593ff8b39e1cc4bae9000070 | [
"Performance",
"Strings",
"Dynamic Programming",
"Memoization",
"Algorithms"
] | https://www.codewars.com/kata/593ff8b39e1cc4bae9000070 | 4 kyu |
The code gives an error!
```clojure
(def a (123 toString))
```
```haskell
a = 123 . toString
```
```ruby
a = some_number.toString
```
```crystal
a = A.toString
```
```python
a = 123.toString()
```
```java
public static final String a = 123.toString();
```
```javascript
a = 123.toString
```
```coffeescript
a = 123.toSt... | bug_fixes | a = str(123)
| Number toString | 53934feec44762736c00044b | [
"Bugs",
"Strings",
"Data Types"
] | https://www.codewars.com/kata/53934feec44762736c00044b | 8 kyu |
A pangram is a sentence that contains every single letter of the alphabet at least once. For example, the sentence "The quick brown fox jumps over the lazy dog" is a pangram, because it uses the letters A-Z at least once (case is irrelevant).
Given a string, detect whether or not it is a pangram. Return True if it is... | reference | import string
def is_pangram(s):
s = s . lower()
for char in 'abcdefghijklmnopqrstuvwxyz':
if char not in s:
return False
return True
| Detect Pangram | 545cedaa9943f7fe7b000048 | [
"Strings",
"Data Structures",
"Fundamentals"
] | https://www.codewars.com/kata/545cedaa9943f7fe7b000048 | 6 kyu |
Our football team has finished the championship.
Our team's match results are recorded in a collection of strings. Each match is represented by a string in the format `"x:y"`, where `x` is our team's score and `y` is our opponents score.
For example:
```["3:1", "2:2", "0:1", ...]```
Points are awarded for each match... | reference | def points(games):
count = 0
for score in games:
res = score . split(':')
if res[0] > res[1]:
count += 3
elif res[0] == res[1]:
count += 1
return count
| Total amount of points | 5bb904724c47249b10000131 | [
"Fundamentals",
"Arrays",
"Strings"
] | https://www.codewars.com/kata/5bb904724c47249b10000131 | 8 kyu |
# Ten-Pin Bowling
In the game of ten-pin bowling, a player rolls a bowling ball down a lane to knock over pins. There are ten pins set at the end of the bowling lane. Each player has 10 frames to roll a bowling ball down a lane and knock over as many pins as possible. The first nine frames are ended after two rolls or... | algorithms | def bowling_score(frames):
rolls = list(frames . replace(' ', ''))
for i, hit in enumerate(rolls):
if hit == 'X':
rolls[i] = 10
elif hit == '/':
rolls[i] = 10 - rolls[i - 1]
else:
rolls[i] = int(hit)
score = 0
for i in range(10):
frame = rolls . pop(0)
if fram... | Ten-Pin Bowling | 5531abe4855bcc8d1f00004c | [
"Algorithms",
"Puzzles"
] | https://www.codewars.com/kata/5531abe4855bcc8d1f00004c | 4 kyu |
# Sentence Smash
Write a function that takes an array of words and smashes them together into a sentence and returns the sentence. You can ignore any need to sanitize words or add punctuation, but you should add spaces between each word. **Be careful, there shouldn't be a space at the beginning or the end of the sente... | reference | def smash(words):
return " " . join(words)
| Sentence Smash | 53dc23c68a0c93699800041d | [
"Strings",
"Arrays",
"Fundamentals"
] | https://www.codewars.com/kata/53dc23c68a0c93699800041d | 8 kyu |
Given two arrays `a` and `b` write a function `comp(a, b)` (or`compSame(a, b)`) that checks whether the two arrays have the "same" elements, with the same *multiplicities* (the multiplicity of a member is the number of times it appears). "Same" means, here, that the elements in `b` are the elements in `a` squared, rega... | reference | def comp(array1, array2):
try:
return sorted([i * * 2 for i in array1]) == sorted(array2)
except:
return False
| Are they the "same"? | 550498447451fbbd7600041c | [
"Fundamentals"
] | https://www.codewars.com/kata/550498447451fbbd7600041c | 6 kyu |
Complete the solution so that it strips all text that follows any of a set of comment markers passed in. Any whitespace at the end of the line should also be stripped out.
**Example:**
Given an input string of:
```
apples, pears # and bananas
grapes
bananas !apples
```
The output expected would be:
```
apples, pear... | algorithms | def solution(string, markers):
parts = string . split('\n')
for s in markers:
parts = [v . split(s)[0]. rstrip() for v in parts]
return '\n' . join(parts)
| Strip Comments | 51c8e37cee245da6b40000bd | [
"Strings",
"Algorithms"
] | https://www.codewars.com/kata/51c8e37cee245da6b40000bd | 4 kyu |
Return a new array consisting of elements which are multiple of their own index in input array (length > 1).
## Some cases:
````if-not:julia
```javascript
[22, -6, 32, 82, 9, 25] => [-6, 32, 25]
[68, -1, 1, -7, 10, 10] => [-1, 10]
[-56,-85,72,-26,-14,76,-27,72,35,-21,-67,87,0,21,59,27,-92,68] => [-85, 72, 0, 68]
... | reference | def multiple_of_index(arr):
return [j for i, j in enumerate(arr) if (j == 0 and i == 0) or (i != 0 and j % i == 0)]
| Multiple of index | 5a34b80155519e1a00000009 | [
"Fundamentals",
"Arrays"
] | https://www.codewars.com/kata/5a34b80155519e1a00000009 | 8 kyu |
### Issue
Looks like some hoodlum plumber and his brother has been running around and damaging your stages again.
The `pipes` connecting your level's stages together need to be fixed before you receive any more complaints.
The `pipes` are correct when each `pipe` after the first is `1` more than the previous one.
#... | reference | def pipe_fix(nums):
return list(range(nums[0], nums[- 1] + 1))
| Lario and Muigi Pipe Problem | 56b29582461215098d00000f | [
"Lists",
"Fundamentals"
] | https://www.codewars.com/kata/56b29582461215098d00000f | 8 kyu |
Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love.
Write a function that will take the number of petals of each flower and return tru... | reference | def lovefunc(flower1, flower2):
return (flower1 + flower2) % 2
| Opposites Attract | 555086d53eac039a2a000083 | [
"Fundamentals"
] | https://www.codewars.com/kata/555086d53eac039a2a000083 | 8 kyu |
In a small town the population is `p0 = 1000` at the beginning of a year. The population
regularly increases by `2 percent` per year and moreover `50` new inhabitants per year come to live in the town.
How many years does the town need to see its population
greater than or equal to `p = 1200` inhabitants?
```
At the ... | reference | def nb_year(p0, percent, aug, p):
t = 0
while p0 < p:
# my mathematical brain hates that I need to round this
p0 = int(p0 * (1 + percent / 100)) + aug
t += 1
return t
| Growth of a Population | 563b662a59afc2b5120000c6 | [
"Fundamentals"
] | https://www.codewars.com/kata/563b662a59afc2b5120000c6 | 7 kyu |
It's the academic year's end, fateful moment of your school report.
The averages must be calculated. All the students come to you and entreat you to calculate their average for them.
Easy ! You just need to write a script.
Return the average of the given array rounded **down** to its nearest integer.
The array will n... | algorithms | def get_average(marks):
return sum(marks) / / len(marks)
| Get the mean of an array | 563e320cee5dddcf77000158 | [
"Arrays",
"Algorithms"
] | https://www.codewars.com/kata/563e320cee5dddcf77000158 | 8 kyu |
Write function RemoveExclamationMarks which removes all exclamation marks from a given string.
| reference | def remove_exclamation_marks(s):
return s . replace('!', '')
| Remove exclamation marks | 57a0885cbb9944e24c00008e | [
"Fundamentals",
"Strings"
] | https://www.codewars.com/kata/57a0885cbb9944e24c00008e | 8 kyu |
Given an array of integers.
Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers. 0 is neither positive nor negative.
If the input is an empty array or is null, return an empty array.
# Example
For input `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -1... | reference | def count_positives_sum_negatives(arr):
if not arr:
return []
pos = 0
neg = 0
for x in arr:
if x > 0:
pos += 1
if x < 0:
neg += x
return [pos, neg]
| Count of positives / sum of negatives | 576bb71bbbcf0951d5000044 | [
"Fundamentals",
"Arrays",
"Lists"
] | https://www.codewars.com/kata/576bb71bbbcf0951d5000044 | 8 kyu |
In this simple exercise, you will create a program that will take two lists of integers, `a` and `b`. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids `a` and `b`. You must find the difference of the cuboids' volumes regardless of which is bigger.
For example, if the parame... | reference | from numpy import prod
def find_difference(a, b):
return abs(prod(a) - prod(b))
| Difference of Volumes of Cuboids | 58cb43f4256836ed95000f97 | [
"Fundamentals"
] | https://www.codewars.com/kata/58cb43f4256836ed95000f97 | 8 kyu |
Removed due to copyright infringement.
<!--
This kata is from check py.checkio.org
You are given an array with positive numbers and a non-negative number N. You should find the N-th power of the element in the array with the index N. If N is outside of the array, then return -1. Don't forget that the first element h... | reference | def index(array, n):
try:
return array[n] * * n
except:
return - 1
| N-th Power | 57d814e4950d8489720008db | [
"Fundamentals",
"Arrays"
] | https://www.codewars.com/kata/57d814e4950d8489720008db | 8 kyu |
You're going to provide a needy programmer a utility method that generates an infinite amount of sequential fibonacci numbers.
~~~if:java
to do this return an `IntStream` starting with 1
~~~
~~~if:typescript
to do this return an `Iterator<BigInt> ` starting with 1
~~~
~~~if:javascript
to do this return an `Iterator<Bi... | algorithms | def all_fibonacci_numbers(a=0, b=1):
while 1:
yield b
a, b = b, a + b
| Fibonacci Streaming | 55695bc4f75bbaea5100016b | [
"Algorithms"
] | https://www.codewars.com/kata/55695bc4f75bbaea5100016b | 5 kyu |
Complete the method/function so that it converts dash/underscore delimited words into [camel casing](https://en.wikipedia.org/wiki/Camel_case). The first word within the output should be capitalized **only** if the original word was capitalized (known as Upper Camel Case, also often referred to as Pascal case). The nex... | algorithms | def to_camel_case(text):
removed = text . replace('-', ' '). replace('_', ' '). split()
if len(removed) == 0:
return ''
return removed[0] + '' . join([x . capitalize() for x in removed[1:]])
| Convert string to camel case | 517abf86da9663f1d2000003 | [
"Regular Expressions",
"Algorithms",
"Strings"
] | https://www.codewars.com/kata/517abf86da9663f1d2000003 | 6 kyu |
```if-not:perl
You will be given an `array` and a `limit` value. You must check that all values in the array are below or equal to the limit value. If they are, return `true`. Else, return `false`.
```
```if:perl
You will be given an `array` and a `limit` value. You must check that all values in the array are below or... | reference | def small_enough(array, limit):
return max(array) <= limit
| Small enough? - Beginner | 57cc981a58da9e302a000214 | [
"Fundamentals",
"Arrays"
] | https://www.codewars.com/kata/57cc981a58da9e302a000214 | 7 kyu |
Given a number `n`, return the number of positive odd numbers below `n`, EASY!
### Examples (Input -> Output)
```
7 -> 3 (because odd numbers below 7 are [1, 3, 5])
15 -> 7 (because odd numbers below 15 are [1, 3, 5, 7, 9, 11, 13])
```
Expect large Inputs!
~~~if:lambdacalc
Use `numEncoding BinaryScott`
~~~
~~~if:bf... | games | def oddCount(n):
return n / / 2
| Count Odd Numbers below n | 59342039eb450e39970000a6 | [
"Performance",
"Mathematics"
] | https://www.codewars.com/kata/59342039eb450e39970000a6 | 8 kyu |
# Triple Trouble
Create a function that will return a string that combines all of the letters of the three inputed strings in groups. Taking the first letter of all of the inputs and grouping them next to each other. Do this for every letter, see example below!
**E.g. Input: "aa", "bb" , "cc" => Output: "abcabc"** ... | games | def triple_trouble(one, two, three):
return '' . join('' . join(a) for a in zip(one, two, three))
| Triple Trouble | 5704aea738428f4d30000914 | [
"Puzzles"
] | https://www.codewars.com/kata/5704aea738428f4d30000914 | 8 kyu |
# Disclaimer
This Kata is an insane step-up from [Avanta's Kata](https://www.codewars.com/kata/coloured-triangles),
so I recommend to solve it first before trying this one.
# Problem Description
A coloured triangle is created from a row of colours, each of which is red, green or blue. Successive rows, each containin... | games | def triangle(row):
def reduce(a, b):
return a if a == b else (set('RGB') - {a, b}). pop()
def walk(offset, root, depth):
return row[root] if not depth else curry(offset, root, * divmod(depth, 3))
def curry(offset, root, depth, degree):
return walk(3 * offset, root, depth) if not degr... | Insane Coloured Triangles | 5a331ea7ee1aae8f24000175 | [
"Puzzles",
"Performance",
"Mathematics"
] | https://www.codewars.com/kata/5a331ea7ee1aae8f24000175 | 2 kyu |
In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out.
### Example
```python
filter_list([1,2,'a','b']) == [1,2]
filter_list([1,'a','b',0,15]) == [1,0,15]
filter_list([1,2,'aasf','1','123',123]) == [1,2,123]
```
```csharp
Li... | reference | def filter_list(l):
'return a new list with the strings filtered out'
return [i for i in l if not isinstance(i, str)]
| List Filtering | 53dbd5315a3c69eed20002dd | [
"Lists",
"Filtering",
"Data Structures",
"Fundamentals"
] | https://www.codewars.com/kata/53dbd5315a3c69eed20002dd | 7 kyu |
When provided with a number between 0-9, return it in words.
Input :: 1
Output :: "One".
If your language supports it, try using a <a href="https://en.wikipedia.org/wiki/Switch_statement">switch statement</a>. | reference | def switch_it_up(n):
return ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'][n]
| Switch it Up! | 5808dcb8f0ed42ae34000031 | [
"Fundamentals"
] | https://www.codewars.com/kata/5808dcb8f0ed42ae34000031 | 8 kyu |
You get an array of numbers, return the sum of all of the positives ones.
Example `[1,-4,7,12]` => `1 + 7 + 12 = 20`
Note: if there is nothing to sum, the sum is default to `0`.
| reference | def positive_sum(arr):
return sum(x for x in arr if x > 0)
| Sum of positive | 5715eaedb436cf5606000381 | [
"Arrays",
"Fundamentals"
] | https://www.codewars.com/kata/5715eaedb436cf5606000381 | 8 kyu |
Philip's just turned four and he wants to know how old he will be in various years in the future such as 2090 or 3044. His parents can't keep up calculating this so they've begged you to help them out by writing a programme that can answer Philip's endless questions.
Your task is to write a function that takes two par... | reference | def calculate_age(year_of_birth, current_year):
diff = abs(current_year - year_of_birth)
plural = '' if diff == 1 else 's'
if year_of_birth < current_year:
return 'You are {} year{} old.' . format(diff, plural)
elif year_of_birth > current_year:
return 'You will be born in {} year{}.' . fo... | How old will I be in 2099? | 5761a717780f8950ce001473 | [
"Fundamentals"
] | https://www.codewars.com/kata/5761a717780f8950ce001473 | 8 kyu |
You have to write a function that describe Leo:
```python
def leo(oscar):
pass
```
```javascript
function leo(oscar) {
}
```
```elixir
def leo(oscar) do
# ...
end
```
if oscar was (integer) 88, you have to return "Leo finally won the oscar! Leo is happy".</br>
if oscar was 86, you have to return "Not even for Wol... | reference | def leo(oscar):
if oscar == 88:
return "Leo finally won the oscar! Leo is happy"
elif oscar == 86:
return "Not even for Wolf of wallstreet?!"
elif oscar < 88:
return "When will you give Leo an Oscar?"
elif oscar > 88:
return "Leo got one already!"
| Leonardo Dicaprio and Oscars | 56d49587df52101de70011e4 | [
"Fundamentals"
] | https://www.codewars.com/kata/56d49587df52101de70011e4 | 8 kyu |
In this kata we want to convert a string into an integer. The strings simply represent the numbers in words.
Examples:
* "one" => 1
* "twenty" => 20
* "two hundred forty-six" => 246
* "seven hundred eighty-three thousand nine hundred and nineteen" => 783919
Additional Notes:
* The minimum number is "zero" (inclusiv... | algorithms | ONES = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine',
'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen',
'eighteen', 'nineteen']
TENS = ['twenty', 'thirty', 'forty', 'fifty',
'sixty', 'seventy', 'eighty', 'ninety']
def... | parseInt() reloaded | 525c7c5ab6aecef16e0001a5 | [
"Parsing",
"Strings",
"Algorithms"
] | https://www.codewars.com/kata/525c7c5ab6aecef16e0001a5 | 4 kyu |
## Enough is enough!
Alice and Bob were on a holiday. Both of them took many pictures of the places they've been, and now they want to show Charlie their entire collection. However, Charlie doesn't like these sessions, since the motif usually repeats. He isn't fond of seeing the Eiffel tower 40 times.
He tells them ... | reference | def delete_nth(order, max_e):
ans = []
for o in order:
if ans . count(o) < max_e:
ans . append(o)
return ans
| Delete occurrences of an element if it occurs more than n times | 554ca54ffa7d91b236000023 | [
"Lists",
"Fundamentals"
] | https://www.codewars.com/kata/554ca54ffa7d91b236000023 | 6 kyu |
Create a function taking a positive integer between `1` and `3999` (both included) as its parameter and returning a string containing the Roman Numeral representation of that integer.
Modern Roman numerals are written by expressing each digit separately starting with the leftmost digit and skipping any digit with a va... | algorithms | def solution(n):
roman_numerals = {1000: 'M',
900: 'CM',
500: 'D',
400: 'CD',
100: 'C',
90: 'XC',
50: 'L',
40: 'XL',
10: 'X',
... | Roman Numerals Encoder | 51b62bf6a9c58071c600001b | [
"Algorithms"
] | https://www.codewars.com/kata/51b62bf6a9c58071c600001b | 6 kyu |
Complete the function that accepts a string parameter, and reverses each word in the string. **All** spaces in the string should be retained.
## Examples
```
"This is an example!" ==> "sihT si na !elpmaxe"
"double spaces" ==> "elbuod secaps"
``` | reference | def reverse_words(str):
return ' ' . join(s[:: - 1] for s in str . split(' '))
| Reverse words | 5259b20d6021e9e14c0010d4 | [
"Strings",
"Fundamentals"
] | https://www.codewars.com/kata/5259b20d6021e9e14c0010d4 | 7 kyu |
We need a simple function that determines if a plural is needed or not. It should take a number, and return true if a plural should be used with that number or false if not. This would be useful when printing out a string such as `5 minutes`, `14 apples`, or `1 sun`.
> You only need to worry about english grammar rul... | reference | def plural(n):
return n != 1
| Plural | 52ceafd1f235ce81aa00073a | [
"Fundamentals"
] | https://www.codewars.com/kata/52ceafd1f235ce81aa00073a | 8 kyu |
The main idea is to count all the occurring characters in a string. If you have a string like `aba`, then the result should be `{'a': 2, 'b': 1}`.
What if the string is empty? Then the result should be empty object literal, `{}`. | reference | from collections import Counter
def count(string):
return Counter(string)
| Count characters in your string | 52efefcbcdf57161d4000091 | [
"Strings",
"Fundamentals"
] | https://www.codewars.com/kata/52efefcbcdf57161d4000091 | 6 kyu |
The number 81 has a special property, a certain power of the sum of its digits is equal to 81 (nine squared). Eighty one (81), is the first number in having this property (not considering numbers of one digit).
The next one, is 512.
Let's see both cases with the details
8 + 1 = 9 and 9<sup>2</sup> = 81
512 = 5 + 1 +... | reference | series = [0]
for a in range(2, 99):
for b in range(2, 42):
c = a * * b
if a == sum(map(int, str(c))):
series . append(c)
power_sumDigTerm = sorted(series). __getitem__
| Numbers that are a power of their sum of digits | 55f4e56315a375c1ed000159 | [
"Algorithms",
"Mathematics",
"Sorting",
"Data Structures",
"Fundamentals"
] | https://www.codewars.com/kata/55f4e56315a375c1ed000159 | 5 kyu |
Write a function named sumDigits which takes a number as input and returns the sum of the absolute value of each of the number's decimal digits.
For example: (**Input --> Output**)
```
10 --> 1
99 --> 18
-32 --> 5
```
Let's assume that all numbers in the input will be integer values.
| reference | def sumDigits(number):
return sum(int(d) for d in str(abs(number)))
| Summing a number's digits | 52f3149496de55aded000410 | [
"Fundamentals"
] | https://www.codewars.com/kata/52f3149496de55aded000410 | 7 kyu |
A briefcase has a 4-digit **rolling-lock**. Each digit is a number from `0-9` that can be rolled either forwards or backwards.
Create a function that returns the smallest number of turns it takes to transform the lock from the current combination to the target combination. One turn is equivalent to rolling a number fo... | games | def min_turns(current, target):
total = 0
for i, j in zip(current, target):
a, b = map(int, [i, j])
total += min(abs(a - b), 10 - abs(b - a))
return total
| Briefcase Lock | 64ef24b0679cdc004d08169e | [
"Algorithms",
"Strings"
] | https://www.codewars.com/kata/64ef24b0679cdc004d08169e | 7 kyu |
# Palindromic Numbers
A [palindromic number](http://en.wikipedia.org/wiki/Palindromic_number) is a number that remains the same when its digits are reversed. Like 16461, for example, it is "symmetrical".
Non-palindromic numbers can be paired with palindromic ones via a series of operations. First, the non-palindromic ... | algorithms | def palindromize(number):
new, n = number, 0
while str(new) != str(new)[:: - 1]:
new += int(str(new)[:: - 1])
n += 1
return f' { n } { new } '
| Palindromic Numbers | 52a0f488852a85c723000aca | [
"Algorithms"
] | https://www.codewars.com/kata/52a0f488852a85c723000aca | 6 kyu |
The purpose of this kata is to write a higher-order function returning a new function that iterates on a specified function a given number of times. This new function takes in an argument as a seed to start the computation from.
```if-not:haskell
For instance, consider the function `getDouble`.
When run twice on value... | algorithms | def create_iterator(func, n):
def f(x):
for i in range(n):
x = func(x)
return x
return f
| Function iteration | 54b679eaac3d54e6ca0008c9 | [
"Algorithms"
] | https://www.codewars.com/kata/54b679eaac3d54e6ca0008c9 | 6 kyu |
ROT13 is a simple letter substitution cipher that replaces a letter with the letter 13 letters after it in the alphabet. ROT13 is an example of the Caesar cipher.
Create a function that takes a string and returns the string ciphered with Rot13.
If there are numbers or special characters included in the string, they s... | reference | import string
from codecs import encode as _dont_use_this_
def rot13(message):
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
outputMessage = ""
for letter in message:
if letter in alpha . lower():
outputMessage += alpha[(alpha . lower(). index(letter) + 13) % 26]. lower()
elif letter in alpha... | Rot13 | 530e15517bc88ac656000716 | [
"Ciphers",
"Fundamentals"
] | https://www.codewars.com/kata/530e15517bc88ac656000716 | 5 kyu |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.