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 |
---|---|---|---|---|---|---|---|
Flash has invited his nemesis The Turtle (He actually was a real villain! ) to play his favourite card game, SNAP. In this game a 52 card deck is dealt out so both Flash and the Turtle get 26 random cards.
Each players cards will be represented by an array like below
Flash’s pile:
```[ 'A', '5', 'Q', 'Q', '6', '2', 'A', '9', '10', '6', '4', '3', '10', '9', '3', '8', 'K', 'J', 'J', 'K', '7', '9', '5', 'J', '7', '2' ]```
Turtle’s pile:
```[ '8', 'A', '2', 'Q', 'K', '8', 'J', '6', '4', '8', '7', 'A', '5', 'K', '3', 'Q', '6', '9', '4', '3', '4', '10', '2', '7', '10', '5' ]```
The players take it in turn to take the top card from their deck (the first element in their array) and place it in a face up pile in the middle. Flash goes first.
When a card is placed on the face up pile that matches the card it is placed on top of the first player to shout ‘SNAP!’ wins that round. Due to Flash's speed he wins every round.
Face up pile in the middle:
```[ 'A', '8', '5', 'A', 'Q', '2', 'Q', 'Q',``` => SNAP!
The face up pile of cards in the middle are added to the bottom of Flash's pile.
Flash’s pile after one round:
```['6', '2', 'A', '9', '10', '6', '4', '3', '10', '9', '3', '8', 'K', 'J', 'J', 'K', '7', '9', '5', 'J', '7', '2', 'A', '8', '5', 'A', 'Q', '2', 'Q', 'Q' ]```
Flash then starts the next round by putting down the next card.
When Turtle runs out of cards the game is over.
How many times does Flash get to call Snap before Turtle runs out of cards?
If both the player put down all their cards into the middle without any matches then the game ends a draw and Flash calls SNAP 0 times.
| reference | def round(flash_pile, turtle_pile):
faceup_pile = []
while turtle_pile:
for pile in flash_pile, turtle_pile:
faceup_pile . append(pile . pop(0))
if len(faceup_pile) >= 2 and faceup_pile[- 1] == faceup_pile[- 2]:
flash_pile . extend(faceup_pile)
return True
def snap(flash_pile, turtle_pile):
for i in range(26):
if not round(flash_pile, turtle_pile):
return i
| SNAP | 5b49cc5a578c6ab6b200004c | [
"Recursion",
"Arrays",
"Fundamentals"
]
| https://www.codewars.com/kata/5b49cc5a578c6ab6b200004c | 6 kyu |
A friend of mine told me privately: "I don't like palindromes". "why not?" - I replied. "Because when I want to do some programming challenges, I encounter 2 or 3 ones first related with palindromes. I'm fed up" - he confess me with anger. I said to myself:"Thankfully, that doesn't happen in Codewars".
Talking seriously, we have to count the palindrome integers. Doing that, perhaps, it will help us to make all the flood of palindrome programming challenges more understandable.
For example all the integers of 1 digit (not including 0) are palindromes, 9 cases.
We have nine of them with two digits, so the total amount of palidromes below ```100``` (10<sup>2</sup>) is ```18```.
At least, will we be able to calculate the amount of them for a certain number of digits?
Let's say for ```2000``` digits?
Prepare a code that given the number of digits ```n```, may output the amount of palindromes of length equals to n and the total amount of palindromes below 10<sup>n</sup>.
You will see more examples in the box.
Happy coding!!
(You don't know what palindromes are? Investigate, :))
| reference | def count_pal(n):
# No recursion; direct calculation:
return [9 * 10 * * ((n - 1) / / 2), 10 * * (n / / 2) * (13 - 9 * (- 1) * * n) / / 2 - 2]
| Allergy to Palindromes. | 5b33452ab6989d2407000100 | [
"Fundamentals",
"Algorithms",
"Mathematics",
"Performance",
"Permutations"
]
| https://www.codewars.com/kata/5b33452ab6989d2407000100 | 6 kyu |
In this kata, we will check is an array is (hyper)rectangular.
A rectangular array is an N-dimensional array with fixed sized within one dimension. Its sizes can be repsented like A1xA2xA3...xAN. That means a N-dimensional array has N sizes. The 'As' are the hyperrectangular properties of an array.
You should implement a functions that returns a N-tuple with the arrays hyperrectangular properties or None if the array is not hyperrectangular.
```
hyperrectangularity_properties(arr)
```
## Note
An empty array IS rectagular and has one dimension of length 0
```
hyperrectangularity_properties([]) == (0,)
```
## Example
```
1D array
hyperrectangularity_properties([1,2,3]) == (3,)
2D arrays
hyperrectangularity_properties(
[[0,1,2],
[3,4,5],
[6,7,8]] ) == (3,3)
hyperrectangularity_properties(
[[0,1,2],
[3,4,5]] ) == (2,3)
hyperrectangularity_properties(
[[0,1,2],
[3,4] ] ) == None
3D arrays
hyperrectangularity_properties(
[
[ [0], [2] ],
[ [0], [2] ],
[ [0], [2] ]
] ) == (3,2,1)
hyperrectangularity_properties(
[
[[0],[2]],
[[0],[2,2]],
[[0],[2]]
] ) == None
hyperrectangularity_properties(
[[ [], [], [] ]]
) == (1,3,0)
```
### Heterogeneous Arrays can appear too
```
hyperrectangularity_properties(
[[0,1,2],
3,
[[4],5,6]] ) == None
hyperrectangularity_properties(
[1,
[1,2],
[[3],[4,[5]],[6]]
] ) == None
hyperrectangularity_properties(
[[ [], [] ], [] ]
) == None
hyperrectangularity_properties(
[ 1, [], [2, [3]] ]
) == None
```
The first property shows the length of the outer layer. The second of the layer one step deeper and so on. The function should handle higher dimensions too.
## Input
##### N-dimensional array of integers
## Expected Ouput
##### An N-tuple with the hyperrectangularity properties | algorithms | import numpy as np
def hyperrectangularity_properties(arr):
try:
return np . array(arr, np . int32). shape
except:
return None
| Array Hyperrectangularity | 5b33e9c291c746b102000290 | [
"Mathematics",
"Arrays",
"Recursion",
"Algorithms",
"Data Structures",
"Lists"
]
| https://www.codewars.com/kata/5b33e9c291c746b102000290 | 6 kyu |
This kata is the third part of a series: [Neighbourhood kata collection](https://www.codewars.com/collections/5b2f4db591c746349d0000ce). You may want to do the first two before trying this version.
___
# Now we are ready for higher dimensions
We add one dimension. You should have good spatial thinking to solve this kata.
There are two popular types of cellular neighbourhoods:
* [Moore neighborhood](https://en.wikipedia.org/wiki/Moore_neighborhood) - cells that shape a 'square' around the given cell
* [Von Neumann neighborhood](https://en.wikipedia.org/wiki/Von_Neumann_neighborhood) - cells that shape a 'diamond' around the given cell
___
# Task
Given a neighbourhood type (`"moore"` or `"von_neumann"`), a MxNxK 3D matrix (list of lists of lists), a 3-tuple of coordinates and the distance, return the list of neighbours of the given cell.
Order of the indices: The first index should be applied for the outer/first matrix layer. The last index for the most inner/last layer. `coordinates = (i, j, k)` should be applied like `mat[i][j][k]`
Note: you should return an empty array if any of these conditions are true:
* Matrix is empty
* Coordinates are outside the matrix
* Distance is equal to `0`
___
## Example:
I have tried my best to represent a 3D matrix.
It would be very difficult to represent distances higher than 1 in the example. But you already know what to do with the distance from the [previous kata](https://www.codewars.com/kata/2d-cellular-neighbourhood-part-2).
```
(i==0) k 0 1 2
j ---------------- (i==1)
0 | 0 | 1 | 2 | ---------------- (i==2)
1 | 3 | 4 | 5 | | 9 | 10 | 11 | ----------------
2 | 6 | 7 | 8 | | 12 | 13 | 14 | | 18 | 19 | 20 |
---------------- | 15 | 16 | 17 | | 21 | 22 | 23 |
---------------- | 24 | 25 | 26 |
----------------
get_neighbourhood("moore", mat, (2,2,2), 1) == [0,1,2,3,4,5,6,7,8,9,10,11,12,14,15,16,17,18,19,20,21,22,23,24,25,26]
get_neighbourhood("von_neumann", mat, (2,2,2), 1) == [10,12,14,16,4,22]
get_neighbourhood("moore", mat, (100,100,100), 1) == []
get_neighbourhood("moore", [[[]]], (0,0,0), 1) == []
get_neighbourhood("moore", mat, (0,0,0), 0) == []
```
___
Translations are appreciated ^^
If you like chess take a look at [Chess Aesthetics](https://www.codewars.com/kata/5b574980578c6a6bac0000dc)
If you like puzzles take a look at [Rubik's cube](https://www.codewars.com/kata/5b3bec086be5d8893000002e) | reference | NEIGHBOURHOOD = {"von_neumann": sum, "moore": max}
def closer_cells(n_type, distance, x, y, z):
return ((x + u, y + v, z + w)
for u in range(- distance, distance + 1) for v in range(- distance, distance + 1) for w in range(- distance, distance + 1)
if 0 < NEIGHBOURHOOD[n_type](map(abs, (u, v, w))) <= distance)
def get_3Dneighbourhood(n_type, arr, coordinates, distance=1):
def is_inside(x, y, z):
return 0 <= x < len(arr) and 0 <= y < len(arr[0]) and 0 <= z < len(arr[0][0])
return [] if not is_inside(* coordinates) else [arr[x][y][z]
for x, y, z in closer_cells(n_type, distance, * coordinates)
if is_inside(x, y, z)]
| 3D Cellular Neighbourhood | 5b33fee525c2bb5753000168 | [
"Algorithms",
"Data Structures",
"Arrays",
"Lists",
"Matrix"
]
| https://www.codewars.com/kata/5b33fee525c2bb5753000168 | 6 kyu |
This kata is the second part of a series: [Neighbourhood kata collection](https://www.codewars.com/collections/5b2f4db591c746349d0000ce). You may want to do the first one before trying this version.
___
# Now we will implement the distance
The distance extends the reach of the neighbourhood - instead of returning only the closest neighbours, you'll be searching for all neighbours in a given maximum distance.
There are two popular types of cellular neighbourhoods:
* [Moore neighborhood](https://en.wikipedia.org/wiki/Moore_neighborhood) - the eight cells that surround the given cell
* [Von Neumann neighborhood](https://en.wikipedia.org/wiki/Von_Neumann_neighborhood) - the four cells that share a border with the given cell
___
# Task
Given a neighbourhood type (`"moore"` or `"von_neumann"`), a 2D matrix (a list of lists), a pair of coordinates and the distance, return the list of neighbours of the given cell.
Order of the indices: The first index should be applied for the outer/first matrix layer. The last index for the most inner/last layer. `coordinates = (m, n)` should be applied like `mat[m][n]`
Note: you should return an empty array if any of these conditions are true:
- Matrix is empty
- Coordinates are outside the matrix
- Distance is equal to `0`
___
## Example:
```
\ n 0 1 2 3 4
m --------------------------
0 | 0 | 1 | 2 | 3 | 4 |
1 | 5 | 6 | 7 | 8 | 9 |
2 | 10 | 11 | 12 | 13 | 14 |
3 | 15 | 16 | 17 | 18 | 19 |
4 | 20 | 21 | 22 | 23 | 24 |
--------------------------
get_neighborhood("moore", arr, (2,2), 1) == [6,7,8,11,13,16,17,18]
get_neighborhood("moore", arr, (2,2), 2) == [0,1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24]
get_neighborhood("von_neumann", arr, (2,2), 1) == [7,11,13,17]
get_neighborhood("von_neumann", arr, (2,2), 2) == [2,6,7,8,10,11,13,14,16,17,18,22]
```
___
Translations are appreciated ^^
If you like chess take a look at [Chess Aesthetics](https://www.codewars.com/kata/5b574980578c6a6bac0000dc)
If you like puzzles take a look at [Rubik's cube](https://www.codewars.com/kata/5b3bec086be5d8893000002e) | algorithms | def get_neighbourhood(t, a, c, d=1):
r, t = [], t == "von_neumann"
x, y = c
if x < len(a) and y < len(a[0]):
for i in range(- d, d + 1):
for j in range(- d + abs(i) * t, d - abs(i) * t + 1):
try:
if x + i >= 0 and y + j >= 0 and (i or j):
r . append(a[x + i][y + j])
except:
pass
return r
| 2D Cellular Neighbourhood - Part 2 | 5b315b8ca454c8c5b40003a2 | [
"Algorithms",
"Data Structures",
"Arrays",
"Matrix"
]
| https://www.codewars.com/kata/5b315b8ca454c8c5b40003a2 | 6 kyu |
Related to [MrZizoScream's Product Array](https://www.codewars.com/kata/product-array-array-series-number-5) kata. You might want to solve that one first :)
This is an adaptation of a problem I came across on LeetCode.
Given an array of numbers, your task is to return a new array where each index (`new_array[i]`) is equal to the product of the original array, except for the number at that index (`array[i]`).
**Two things to keep in mind:**
* Zeroes will be making their way into some of the arrays you are given
* O(n²) solutions will not pass.
All input arrays will be valid arrays of nonzero length.
## Examples:
```
[1, 2, 3, 4] => [24, 12, 8, 6]
[2, 3, 4, 5] => [60, 40, 30, 24]
[1, 1, 1] => [1, 1, 1]
[9, 0, -2] => [0, -18, 0]
[0, -99, 0] => [0, 0, 0]
[3, 14, 9, 11, 11] => [15246, 3267, 5082, 4158, 4158]
[-8, 1, 5, 13, -1] => [-65, 520, 104, 40, -520]
[4, 7, 3, 6, 2, 14, 7, 5] => [123480, 70560, 164640, 82320, 246960, 35280, 70560, 98784]
```
Have fun! Please upvote if you enjoyed :) | reference | from functools import reduce
def product_sans_n(nums):
z = nums . count(0)
if z > 1:
return [0] * len(nums)
p = reduce(int . __mul__, (v for v in nums if v))
return [not v and p for v in nums] if z else [p / / v for v in nums]
| Array Product (Sans n) | 5b3e609cd58499284100007a | [
"Arrays",
"Fundamentals"
]
| https://www.codewars.com/kata/5b3e609cd58499284100007a | 6 kyu |
Roma is programmer and he likes memes about IT,
Maxim is chemist and he likes memes about chemistry,
Danik is designer and he likes memes about design,
and Vlad likes all other memes.
___
You will be given a meme (string), and your task is to identify its category, and send it to the right receiver: `IT - 'Roma'`, `chemistry - 'Maxim'`, `design - 'Danik'`, or `other - 'Vlad'`.
IT meme has letters `b, u, g`.
Chemistry meme has letters `b, o, o, m`.
Design meme has letters `e, d, i, t, s`.
If there is more than one possible answer, the earliest match (the one that completes first) should be chosen.
**Note:** letters are case-insensetive and should come in the order specified above.
___
## Examples:
(Matching letters are surrounded by curly braces for readability.)
```
this is programmer meme {b}ecause it has b{ug}
this is also program{bu}r meme {g}ecause it has needed key word
this is {ed}s{i}gner meme cause i{t} ha{s} key word
this could {b}e chemistry meme b{u}t our{g}Gey word 'boom' is too late
instead of
this could {b}e chemistry meme but {o}ur gey w{o}rd 'boo{m}' is too late
``` | reference | import re
from itertools import accumulate
patterns = [
(re . compile('.*' . join('bug'), flags=re . I), 'Roma'),
(re . compile('.*' . join('boom'), flags=re . I), 'Maxim'),
(re . compile('.*' . join('edits'), flags=re . I), 'Danik'),
]
def memesorting(meme):
return next((who for m in accumulate(meme) for pattern, who in patterns if pattern . search(m)), 'Vlad')
| Memesorting | 5b6183066d0db7bfac0000bb | [
"Strings",
"Regular Expressions",
"Fundamentals",
"Sorting"
]
| https://www.codewars.com/kata/5b6183066d0db7bfac0000bb | 6 kyu |
We have a big list having values fom 1 to n, occurring only once but unordered with an unknown amount of missing values. The number `n` will be considered the maximum value of the array.
We have to output the missing numbers sorted by value.
Example:
```
[8, 10, 11, 7, 3, 15, 6, 1, 14, 5, 12] ---> [2, 4, 9, 13]
```
The number `1` should be in the input array, if it's not present in the input array, should be included in the results. See the example below.
```
[8, 10, 11, 7, 3, 15, 6, 14, 5, 12] ---> [1, 2, 4, 9, 13]
```
As this is a hardcore version, the tests are prepared for only algorithms of time complexityO(n) to pass.
As the speed of each language are different, we will have different maximum lengths for the input.
```javascript
Features of the random tests:
1000 <= length of arrays <= 30.000.000
1 <= amount of missing numbers <= 10
amount of tests: 20
```
```python
Features of the random tests:
1000 <= length of arrays <= 4.000.000
1 <= amount of missing numbers <= 10
amount of tests: 20
```
```ruby
Features of the random tests:
1000 <= length of arrays <= 14.000.000
1 <= amount of missing numbers <= 10
amount of tests: 20
```
```cpp
Features of the random tests:
1000 <= length of arrays <= 30.000.000
1 <= amount of missing numbers <= 10
amount of tests: 35
```
Enjoy it. | reference | def miss_nums_finder(arr):
mx = max(arr)
s = set(arr)
return [x for x in range(1, mx) if x not in s]
| Unknown Amount of Missing Numbers in an Unordered Array. (Hardcore version) | 5b559899f7e38620ef000803 | [
"Algorithms",
"Performance",
"Arrays",
"Fundamentals"
]
| https://www.codewars.com/kata/5b559899f7e38620ef000803 | 6 kyu |
Given the molecular mass of two molecules `$M_1$` and `$M_2$`, their masses present `$m_1$` and `$m_2$` in a vessel of volume `$V$` at a specific temperature `$T$`, find the total pressure `$P_{total}$` exerted by the molecules. Formula to calculate the pressure is:
```math
\LARGE P_{total} = {{({{m_1} \over {M_1}} + {{m_2} \over {M_2}}) R T} \over V}
```
### Input
Six values :
- `$M_1$`, `$M_2$`: molar masses of both gases, in `$\ g \cdot mol^{-1}$`
- `$m_1$` and `$m_2$`: present mass of both gases, in grams (`$g$`)
- `$V$`: volume of the vessel, in `$\ dm^3$`
- `$T$`: temperature, in `$\ \degree C$`
### Output
One value: `$P_{total}$`, in units of `$atm$`.
### Notes
Remember: Temperature is given in Celsius while SI unit is Kelvin (`$K$`). `$\ 0\degree C = 273.15K$`
The gas constant `$\ R = 0.082dm^3 \cdot atm \cdot K^{-1} \cdot mol^{-1}$` | reference | def solution(M1, M2, m1, m2, V, T):
return (m1 / M1 + m2 / M2) * 0.082 * (T + 273.15) / V
| Total pressure calculation | 5b7ea71db90cc0f17c000a5a | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b7ea71db90cc0f17c000a5a | 8 kyu |
```if:python
Given a sorted array of distinct integers, write a function `index_equals_value` that returns the lowest index for which `array[index] == index`.
Return `-1` if there is no such index.
```
```if:haskell,javascript
Given a sorted array of distinct integers, write a function `indexEqualsValue` that returns the lowest index for which `array[index] == index`.
Return `-1` if there is no such index.
```
```if:rust
Given a sorted slice of distinct integers, write a function `index_equals_value` that returns the lowest index for which `slice[index] == index`.
Return `-1` if there is no such index.
```
Your algorithm should be very performant.
[input] array of integers ( with `0`-based nonnegative indexing )
[output] integer
### Examples:
<!-- no need to add more languages really. but leave "python" in or words get coloured -->
```python
input: [-8,0,2,5]
output: 2 # since array[2] == 2
input: [-1,0,3,6]
output: -1 # since no index in array satisfies array[index] == index
```
### Random Tests Constraints:
```if:python,javascript
Array length: 200 000
```
```if:rust
Slice length: 200 000
```
```if:haskell
Array length: 10 000
```
Amount of tests: 1 000
```if:python
Time limit: 1.5 s
```
```if:haskell,javascript,rust
Time limit: 150 ms
```
___
If you liked this Kata check out my more complex creations:
Find the neighbourhood in big dimensions. [Neighbourhood collection](https://www.codewars.com/collections/5b2f4db591c746349d0000ce)
The [Rubik's cube](https://www.codewars.com/kata/5b3bec086be5d8893000002e) | algorithms | def index_equals_value(arr):
lo, hi = 0, len(arr)
while lo < hi:
mid = lo + hi >> 1
if arr[mid] >= mid:
hi = mid
else:
lo = mid + 1
return lo if lo < len(arr) and arr[lo] == lo else - 1
| Element equals its index | 5b7176768adeae9bc9000056 | [
"Arrays",
"Algorithms"
]
| https://www.codewars.com/kata/5b7176768adeae9bc9000056 | 6 kyu |
In this Kata, we define an arithmetic progression as a series of integers in which the differences between adjacent numbers are the same. You will be given an array of ints of `length > 2` and your task will be to convert it into an arithmetic progression by the following rule:
```Haskell
For each element there are exactly three options: an element can be decreased by 1, an element can be increased by 1
or it can be left unchanged.
```
Return the minimum number of changes needed to convert the array to an arithmetic progression. If not possible, return `-1`.
```Haskell
For example:
solve([1,1,3,5,6,5]) == 4 because [1,1,3,5,6,5] can be changed to [1,2,3,4,5,6] by making 4 changes.
solve([2,1,2]) == 1 because it can be changed to [2,2,2]
solve([1,2,3]) == 0 because it is already a progression, and no changes are needed.
solve([1,1,10) == -1 because it's impossible.
solve([5,6,5,3,1,1]) == 4. It becomes [6,5,4,3,2,1]
```
More examples in the test cases. Good luck! | reference | def solve(arr):
res = []
for first in (arr[0] - 1, arr[0], arr[0] + 1):
for second in (arr[1] - 1, arr[1], arr[1] + 1):
val, step, count = second, second - \
first, abs(arr[0] - first) + abs(arr[1] - second)
for current in arr[2:]:
val += step
if abs(val - current) > 1:
break
count += abs(val - current)
else:
res . append(count)
return min(res, default=- 1)
| Fix arithmetic progression | 5b77b030f0aa5c9114000024 | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b77b030f0aa5c9114000024 | 5 kyu |
Consider the string `"adfa"` and the following rules:
```
a) each character MUST be changed either to the one before or the one after in alphabet.
b) "a" can only be changed to "b" and "z" to "y".
```
From our string, we get:
```
"adfa" -> ["begb","beeb","bcgb","bceb"]
Here is another example:
"bd" -> ["ae","ac","ce","cc"]
--We see that in each example, one of the outcomes is a palindrome. That is, "beeb" and "cc".
```
You will be given a lowercase string and your task is to return `True` if at least one of the outcomes is a palindrome or `False` otherwise.
More examples in test cases. Good luck! | algorithms | def solve(st):
return all(True if ord(x) - ord(y) in [- 2, 0, 2] else False for x, y in zip(st, st[:: - 1]))
| Create palindrome | 5b7bd90ef643c4df7400015d | [
"Algorithms"
]
| https://www.codewars.com/kata/5b7bd90ef643c4df7400015d | 7 kyu |
Assume we take a number `x` and perform any one of the following operations:
```Pearl
a) Divide x by 3 (if it is divisible by 3), or
b) Multiply x by 2
```
After each operation, we write down the result. If we start with `9`, we can get a sequence such as:
```
[9,3,6,12,4,8] -- 9/3=3 -> 3*2=6 -> 6*2=12 -> 12/3=4 -> 4*2=8
```
You will be given a shuffled sequence of integers and your task is to reorder them so that they conform to the above sequence. There will always be an answer.
```
For the above example:
solve([12,3,9,4,6,8]) = [9,3,6,12,4,8].
```
More examples in the test cases. Good luck!
| reference | def solve(a):
for i in a:
li = [i]
while 1:
if li[- 1] % 3 == 0 and li[- 1] / / 3 in a:
li . append(li[- 1] / / 3)
elif li[- 1] * 2 in a:
li . append(li[- 1] * 2)
else:
break
if len(li) == len(a):
return li
| Fix array sequence | 5b7bae02402fb702ce000159 | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b7bae02402fb702ce000159 | 6 kyu |
## Given two words, how many letters do you have to remove from them to make them anagrams?
# Example
* First word :
<span style="color: green">c</span>
<span style="color: red">od</span>
<span style="color: green">e</span>
<span style="color: red">w</span>
<span style="color: green">ar</span>
<span style="color: red">s</span> (4 letters removed)
* Second word :
<span style="color: red">ha</span>
<span style="color: green">c</span>
<span style="color: red">k</span>
<span style="color: green">er</span>
<span style="color: red">r</span>
<span style="color: green">a</span>
<span style="color: red">nk</span> (6 letters removed)
* Result : __10__
### Hints
* A word is an anagram of another word if they have the same letters (usually in a different order).
* Do not worry about case. All inputs will be lowercase.
* When you're done with this kata, check out its big brother/sister : https://www.codewars.com/kata/hardcore-anagram-difference
| reference | from collections import Counter
def anagram_difference(* words):
c1, c2 = map(Counter, words)
c1 . subtract(c2)
return sum(map(abs, c1 . values()))
| Anagram difference | 5b1b27c8f60e99a467000041 | [
"Strings",
"Algorithms",
"Fundamentals"
]
| https://www.codewars.com/kata/5b1b27c8f60e99a467000041 | 6 kyu |
You have the `radius` of a circle with the center in point `(0,0)`.
Write a function that calculates the number of points in the circle where `(x,y)` - the cartesian coordinates of the points - are `integers`.
Example: for `radius = 2` the result should be `13`.
`0 <= radius <= 1000`
 | reference | def points(R):
from math import sqrt
point = sum(int(sqrt(R * R - x * x)) for x in range(0, R + 1)) * 4 + 1
return point
| Points in the circle | 5b55c49d4a317adff500015f | [
"Geometry",
"Algorithms",
"Logic",
"Mathematics",
"Fundamentals"
]
| https://www.codewars.com/kata/5b55c49d4a317adff500015f | 6 kyu |
You are given 4 spheres, one of them lies on 3 others; all the spheres are in contact - see the image below:
<img src='https://i.imgur.com/LJCiIya.png' alt='figure'>
*(The front sphere was made transparent for clear view)*
All spheres have the same radius `r`
## Task
Your task is to write a function that accepts a radius `r`, and returns the distance between the bottom of the upper sphere and the plane on which they are all located (vertical dashed line at the image below). The answer should be rounded to 4 decimal places. If the function recieves invalid float for radius (r < 0), then it should return `0.0` as an answer.
<img src="https://i.imgur.com/JPoLnoy.png" alt="distance">
## Code limit
~~~if:python
The maximum code length: `58`
~~~
~~~if:ruby
The maximum code length: `62`
~~~
## Examples
```python
10 --> 16.3299
9 --> 14.6969
1.224744871391589 --> 2.0
-10 --> 0.0
```
| reference | def calculate_distance(r): return round(r * (8 / 3) * * .5, 4) * (r > 0)
| [Code Golf] One Line Task: Pyramid of Spheres | 5b74532131ef05150d000109 | [
"Mathematics",
"Geometry",
"Restricted",
"Fundamentals"
]
| https://www.codewars.com/kata/5b74532131ef05150d000109 | 7 kyu |
Your task is to remove all **consecutive duplicate** words from a string, leaving only first words entries. For example:
```
"alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta"
--> "alpha beta gamma delta alpha beta gamma delta"
```
Words will be separated by a single space. There will be no leading or trailing spaces in the string. An empty string (0 words) is a valid input. | algorithms | from itertools import groupby
def remove_consecutive_duplicates(s):
return ' ' . join(k for k, _ in groupby(s . split()))
| Remove consecutive duplicate words | 5b39e91ee7a2c103300018b3 | [
"Strings",
"Regular Expressions",
"Algorithms"
]
| https://www.codewars.com/kata/5b39e91ee7a2c103300018b3 | 7 kyu |
You are the best freelancer in the city. Everybody knows you, but what they don't know, is that you are actually offloading your work to other freelancers and and you rarely need to do any work. You're living the life!
To make this process easier you need to write a method called workNeeded to figure out how much time you need to contribute to a project.
Giving the amount of time in `minutes` needed to complete the project and an array of pair values representing other freelancers' time in `[Hours, Minutes]` format ie. `[[2, 33], [3, 44]]` calculate how much time **you** will need to contribute to the project (if at all) and return a string depending on the case.
* If we need to contribute time to the project then return `"I need to work x hour(s) and y minute(s)"`
* If we don't have to contribute any time to the project then return `"Easy Money!"`
| reference | def work_needed(project_minutes, freelancers):
available_minutes = sum(
hours * 60 + minutes for hours, minutes in freelancers)
workload_minutes = project_minutes - available_minutes
if workload_minutes <= 0:
return 'Easy Money!'
else:
hours, minutes = divmod(workload_minutes, 60)
return 'I need to work {} hour(s) and {} minute(s)' . format(hours, minutes)
| Offload your work! | 5b3e1dca3da310a4390000f3 | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b3e1dca3da310a4390000f3 | 7 kyu |
Given a logarithm base X and two values A and B, return a sum of logratihms with the base X: `$ \log_XA + \log_XB $`. | algorithms | from math import log
def logs(x, a, b):
# Your code here
return log(a * b, x)
| easy logs | 5b68c7029756802aa2000176 | [
"Algorithms"
]
| https://www.codewars.com/kata/5b68c7029756802aa2000176 | 8 kyu |
We need you to implement a method of receiving commands over a network, processing the information and responding.
Our device will send a single packet to you containing data and an instruction which you must perform before returning your reply.
To keep things simple, we will be passing a single "packet" as a string.
Each "byte" contained in the packet is represented by 4 chars.
One packet is structured as below:
```
Header Instruction Data1 Data2 Footer
------ ------ ------ ------ ------
H1H1 0F12 0012 0008 F4F4
------ ------ ------ ------ ------
The string received in this case would be - "H1H10F1200120008F4F4"
Instruction: The calculation you should perform, always one of the below.
0F12 = Addition
B7A2 = Subtraction
C3D9 = Multiplication
FFFF = This instruction code should be used to identify your return value.
```
- The Header and Footer are unique identifiers which you must use to form your reply.
- Data1 and Data2 are the decimal representation of the data you should apply your instruction to. _i.e 0109 = 109._
- Your response must include the received header/footer, a "FFFF" instruction code, and the result of your calculation stored in Data1.
- Data2 should be zero'd out to "0000".
```
To give a complete example:
If you receive message "H1H10F1200120008F4F4".
The correct response would be "H1H1FFFF00200000F4F4"
```
In the event that your calculation produces a negative result, the value returned should be "0000", similarly if the value is above 9999 you should return "9999".
Goodluck, I look forward to reading your creative solutions! | reference | INSTRUCTIONS = {"0F12": int . __add__,
"B7A2": int . __sub__, "C3D9": int . __mul__}
def communication_module(packet):
header, inst, d1, d2, footer = (packet[i: i + 4] for i in range(0, 20, 4))
res = max(0, min(9999, INSTRUCTIONS[inst](int(d1), int(d2))))
return f" { header } FFFF { res : 0 > 4 } 0000 { footer } "
| String Packet Based Communications | 5b2be37991c7460d17000009 | [
"Networks",
"Strings",
"Fundamentals",
"Logic"
]
| https://www.codewars.com/kata/5b2be37991c7460d17000009 | 7 kyu |
Your job is to find the gravitational force between two spherical objects (obj1 , obj2).
input
====
Two arrays are given :
- arr_val (value array), consists of 3 elements
- 1st element : mass of obj 1
- 2nd element : mass of obj 2
- 3rd element : distance between their centers
- arr_unit (unit array), consists of 3 elements
- 1st element : unit for mass of obj 1
- 2nd element : unit for mass of obj 2
- 3rd element : unit for distance between their centers
mass units are :
- kilogram (kg)
- gram (g)
- milligram (mg)
- microgram (μg)
- pound (lb)
distance units are :
- meter (m)
- centimeter (cm)
- millimeter (mm)
- micrometer (μm)
- feet (ft)
Note
====
value of G = 6.67 × 10<sup>−11</sup> N⋅kg<sup>−2</sup>⋅m<sup>2<sup>
1 ft = 0.3048 m
1 lb = 0.453592 kg
return value must be Newton for force (obviously)
`μ` copy this from here to use it in your solution
| algorithms | units = {"kg": 1, "g": 1e-3, "mg": 1e-6, "μg": 1e-9, "lb": 0.453592,
"m": 1, "cm": 1e-2, "mm": 1e-3, "μm": 1e-6, "ft": 0.3048,
"G": 6.67e-11}
def solution(v, u):
m1, m2, r = (v[i] * units[u[i]] for i in range(3))
return units["G"] * m1 * m2 / r * * 2
| Find the force of gravity between two objects | 5b609ebc8f47bd595e000627 | [
"Algorithms"
]
| https://www.codewars.com/kata/5b609ebc8f47bd595e000627 | 8 kyu |
Your company is working with an old, proprietary piece of software. This software has a python API that, for no good reason, supplies you with 32-bit big-endian signed integers as *a list of byte arrays*...
You have been tasked with writing a function that receives a list of byte strings and interprets them as integers, returning them as an iterable over the contained integers.
To summarize using an example:
```
input: ["\0\0\0\0\0\0\0\1\0\0\0\2", "\0\0\1\1"]
output: [ 0, 1, 2, 257 ]
```
Note: The incoming iterable sequence should be considered as a continuous stream of data, and is not guaranteed to align to 32 bits for each packet. | algorithms | def interpret_as_int32(a):
s = b"" . join(a)
return [int . from_bytes(s[i: i + 4], "big", signed=True) for i in range(0, len(s) / / 4 * 4, 4)]
| Receiving integers as bytes | 56df605f2ebcd54c4d000335 | [
"Algorithms"
]
| https://www.codewars.com/kata/56df605f2ebcd54c4d000335 | 6 kyu |
You are working at a lower league football stadium and you've been tasked with automating the scoreboard.
The referee will shout out the score, you have already set up the voice recognition module which turns the ref's voice into a string, but the spoken score needs to be converted into a pair for the scoreboard!
e.g. `"The score is four nil"` should return `[4,0]`
Either teams score has a range of 0-9, and the ref won't say the same string every time e.g.
"new score: two three"
"two two"
"Arsenal just conceded another goal, two nil"
Note:
```cpp
Please return a std::vector<int>
```
```python
Please return an array
```
```haskell
Please return an array or tuple
```
```ruby
Please return an array
```
```javascript
Please return an array
```
Please rate and enjoy! | reference | def scoreboard(string):
scores = {'nil': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}
return [scores[x] for x in string . split() if x in scores]
| Convert the score | 5b6c220fa0a661fbf200005d | [
"Fundamentals",
"Arrays"
]
| https://www.codewars.com/kata/5b6c220fa0a661fbf200005d | 7 kyu |
This kata is the first part of a series: [Neighbourhood kata collection](https://www.codewars.com/collections/5b2f4db591c746349d0000ce). If this one is too easy you can try out the harder katas. ;)
___
The neighbourhood of a cell (in a matrix) are cells that are near to it. There are two popular types:
- The [Moore neighborhood](https://en.wikipedia.org/wiki/Moore_neighborhood) are eight cells which surround a given cell
- The [Von Neumann neighborhood](https://en.wikipedia.org/wiki/Von_Neumann_neighborhood) are four cells which share a border with the given cell
___
## Task
Given a neighbourhood type (`"moore"` or `"von_neumann"`), a 2D matrix (a list of lists) and a pair of coordinates, return the list of neighbours of the given cell.
Notes:
- The order of the elements in the output list is not important
- If the input indexes are outside the matrix, return an empty list
- If the the matrix is empty, return an empty list
- Order of the indices: the first index should be applied for the outer/first matrix layer and the last index for the most inner/last layer. `coordinates = (m, n)` should be applied like `mat[m][n]`
___
## Examples
```
\ n 0 1 2 3 4
m --------------------------
0 | 0 | 1 | 2 | 3 | 4 |
1 | 5 | 6 | 7 | 8 | 9 |
2 | 10 | 11 | 12 | 13 | 14 |
3 | 15 | 16 | 17 | 18 | 19 |
4 | 20 | 21 | 22 | 23 | 24 |
--------------------------
get_neighborhood("moore", mat, (1,1)) == [0, 1, 2, 5, 7, 10, 11, 12]
get_neighborhood("moore", mat, (0,0)) == [1, 6, 5]
get_neighborhood("moore", mat, (4,2)) == [21, 16, 17, 18, 23]
get_neighborhood("von_neumann", mat, (1,1)) == [1, 5, 7, 11]
get_neighborhood("von_neumann", mat, (0,0)) == [1, 5]
get_neighborhood("von_neumann", mat, (4,2)) == [21, 17, 23]
```
___
*Translations are appreciated*
* If you like chess take a look at [Chess Aesthetics](https://www.codewars.com/kata/5b574980578c6a6bac0000dc)
* If you like puzzles take a look at [Rubik's cube](https://www.codewars.com/kata/5b3bec086be5d8893000002e)
| algorithms | def get_neighbourhood(typ, arr, coordinates):
def isInside(x, y): return 0 <= x < len(arr) and 0 <= y < len(arr[0])
x, y = coordinates
if not isInside(x, y):
return []
neigh = ([(dx, dy) for dx in range(- 1, 2) for dy in range(- 1, 2) if (dx, dy) != (0, 0)]
if typ == 'moore' else [(0, 1), (0, - 1), (1, 0), (- 1, 0)])
return [arr[a][b] for a, b in ((x + dx, y + dy) for dx, dy in neigh) if isInside(a, b)]
| 2D Cellular Neighbourhood | 5b2e5a02a454c82fb9000048 | [
"Algorithms",
"Data Structures",
"Arrays",
"Matrix"
]
| https://www.codewars.com/kata/5b2e5a02a454c82fb9000048 | 7 kyu |
Create a Circular List
A circular list is of finite size, but can infititely be asked for its previous and next elements. This is because it acts like it is joined at the ends and loops around.
For example, imagine a CircularList of `[1, 2, 3, 4]`. Five invocations of `next()` in a row should return 1, 2, 3, 4 and then 1 again. At this point, five invocations of `prev()` in a row should return 4, 3, 2, 1 and then 4 again.
Your CircularList is created by passing a vargargs parameter in, e.g. `new CircularList(1, 2, 3)`. Your list constructor/init code should throw an Exception if nothing is passed in.
| reference | class CircularList ():
def __init__(self, * args):
if not args:
raise Exception("missing required args")
self . n = len(args)
self . lst = args
self . i = None
def next(self):
if self . i is None:
self . i = - 1
self . i = (self . i + 1) % self . n
return self . lst[self . i]
def prev(self):
if self . i is None:
self . i = 0
self . i = (self . i - 1) % self . n
return self . lst[self . i]
| Circular List | 5b2e60742ae7543f9d00005d | [
"Lists",
"Data Structures",
"Fundamentals"
]
| https://www.codewars.com/kata/5b2e60742ae7543f9d00005d | 7 kyu |
The concept of "[smooth number](https://en.wikipedia.org/wiki/Smooth_number)" is applied to all those numbers whose prime factors are lesser than or equal to `7`: `60` is a smooth number (`2 * 2 * 3 * 5`), `111` is not (`3 * 37`).
More specifically, smooth numbers are classified by their highest prime factor and your are tasked with writing a `isSmooth`/`is_smooth` function that returns a string with this classification as it follows:
* 2-smooth numbers should be all defined as a `"power of 2"`, as they are merely that;
* 3-smooth numbers are to return a result of `"3-smooth"`;
* 5-smooth numbers will be labelled as `"Hamming number"`s (incidentally, you might appreciate [this nice kata on them](https://www.codewars.com/kata/hamming-numbers));
* 7-smooth numbers are classified as `"humble number"`s;
* for all the other numbers, just return `non-smooth`.
Examples:
```javascript
isSmooth(16) === "power of 2"
isSmooth(36) === "3-smooth"
isSmooth(60) === "Hamming number"
isSmooth(98) === "humble number"
isSmooth(111) === "non-smooth"
```
```cpp
isSmooth(16) == "power of 2"
isSmooth(36) == "3-smooth"
isSmooth(60) == "Hamming number"
isSmooth(98) == "humble number"
isSmooth(111) == "non-smooth"
```
```python
is_smooth(16) == "power of 2"
is_smooth(36) == "3-smooth"
is_smooth(60) == "Hamming number"
is_smooth(98) == "humble number"
is_smooth(111) == "non-smooth"
```
```ruby
is_smooth(16) == "power of 2"
is_smooth(36) == "3-smooth"
is_smooth(60) == "Hamming number"
is_smooth(98) == "humble number"
is_smooth(111) == "non-smooth"
```
```crystal
is_smooth(16) == "power of 2"
is_smooth(36) == "3-smooth"
is_smooth(60) == "Hamming number"
is_smooth(98) == "humble number"
is_smooth(111) == "non-smooth"
```
```c
is_smooth(16) == "power of 2"
is_smooth(36) == "3-smooth"
is_smooth(60) == "Hamming number"
is_smooth(98) == "humble number"
is_smooth(111) == "non-smooth"
```
```java
isSmooth(16) == "power of 2"
isSmooth(36) == "3-smooth"
isSmooth(60) == "Hamming number"
isSmooth(98) == "humble number"
isSmooth(111) == "non-smooth"
```
The provided input `n` is always going to be a positive number `> 1`.
| games | def is_smooth(n):
smooth = {
2: "power of 2",
3: "3-smooth",
5: "Hamming number",
7: "humble number"
}
for k in smooth:
while n % k == 0:
n / /= k
if n == 1:
return smooth[k]
return "non-smooth"
| Smooth numbers | 5b2f6ad842b27ea689000082 | [
"Number Theory"
]
| https://www.codewars.com/kata/5b2f6ad842b27ea689000082 | 7 kyu |
A forest fire has been spotted at *fire*, a simple 2 element array with x, y coordinates.
The forest service has decided to send smoke jumpers in by plane and drop them in the forest.
The terrain is dangerous and surveyors have determined that there are three possible safe *dropzones*, an array of three simple arrays with x, y coordinates.
The plane is en route and time is of the essence. Your mission is to return a simple [x,y] array with the coordinates of the dropzone closest to the fire.
EDIT:
The airplane is leaving from the origin at 0,0. If your result returns two possible dropzones that are both an equal distance from the fire, choose the dropzone that is closest to 0,0.
If the two dropzones are both equal distance away from 0,0, then return the dropzone that is first in the given array.
For example, if you are given: fire = [1,1], possibleDZ = [0,1],[1,0],[2,2] . The answer is [0,1] because that is the first possible drop zone in the given array. | reference | from math import hypot
def dropzone(fire, dropzones):
return min(dropzones, key=lambda p: hypot(p[0] - fire[0], p[1] - fire[1]))
| Dropzone | 5b6d065a1db5ce9b4c00003c | [
"Geometry",
"Fundamentals"
]
| https://www.codewars.com/kata/5b6d065a1db5ce9b4c00003c | 7 kyu |
You receive the name of a city as a string, and you need to return a string that shows how many times each letter shows up in the string by using asterisks (`*`).
For example:
```
"Chicago" --> "c:**,h:*,i:*,a:*,g:*,o:*"
```
As you can see, the letter `c` is shown only once, but with 2 asterisks.
The return string should include **only the letters** (not the dashes, spaces, apostrophes, etc). There should be no spaces in the output, and the different letters are separated by a comma (`,`) as seen in the example above.
Note that the return string must list the letters in order of their first appearance in the original string.
More examples:
```
"Bangkok" --> "b:*,a:*,n:*,g:*,k:**,o:*"
"Las Vegas" --> "l:*,a:**,s:**,v:*,e:*,g:*"
```
Have fun! ;) | reference | from collections import Counter
def get_strings(city):
return "," . join(f" { char } : { '*' * count } " for char, count in Counter(city . replace(" ", ""). lower()). items())
| Interview Question (easy) | 5b358a1e228d316283001892 | [
"Fundamentals",
"Strings"
]
| https://www.codewars.com/kata/5b358a1e228d316283001892 | 7 kyu |
# Meanwhile... somewhere in a Pentagon basement
Your job is to compare two confidential documents that have come into your possession.
The first document has parts <a href=https://www.merriam-webster.com/dictionary/redacted>redacted</a>, and the other one doesn't.
<img src="https://i.imgur.com/8BSbFEy.png" style='width:300px'/>
But the original (unredacted) document might be a fake!
You need to compare the two documents and decide if it is *possible* they are the **same** or not.
# Kata Task
Return `true` if the two documents are possibly the same. Return `false` otherwise.
## Notes
* Each document is made of any visible characters, spaces, punctuation, and newlines `\n`
* Any character might be redacted (except `\n`)
* The redaction character is `X`
* The redacted document is always the first one
# Examples
<style>
#mytable {
width: 75%;
margin-bottom: 20px;
}
#mytable #myth, #mytd {
border-collapse: collapse;
border: 2px solid gray;
padding: 3px 15px 3px 15px;
}
</style>
<table id="mytable">
<tr id="mytr"><th id="myth">Document 1 (redacted)<th id="myth">Document 2 (original)<th id="myth">Possibly Same?</tr>
<tr>
<td id="mytd">
<pre style='background-color:white;color:gray'>
TOP SECRET:
The missile launch code for Sunday <span style='background-color:black'>XXXXXXXXXX</span> is:
<span style='background-color:black'>XXXXXXXXXXXXXXXXX</span>
<td id="mytd">
<pre style='background-color:white;color:gray'>
TOP SECRET:
The missile launch code for Sunday 5th August is:
7-ZERO-8X-ALPHA-1
<td id="mytd">
true
</tr>
<tr>
<td id="mytd">
<pre style='background-color:white;color:gray'>
The name of the mole is Professor <span style='background-color:black'>XXXXX</span>
<td id="mytd">
<pre style='background-color:white;color:gray'>
The name of the mole is Professor Plum
<td id="mytd">
false
</tr>
<tr>
<td id="mytd">
<pre style='background-color:white;color:gray'>
<span style='background-color:black'>XXXXXXXX</span> <span style='background-color:black'>XXXXXXX</span> <span style='background-color:black'>XXXXXXXXXXXXXXXXXXX</span>
<span style='background-color:black'>XXXX</span> <span style='background-color:black'>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</span> <span style='background-color:black'>XXXXXXXXX</span> <span style='background-color:black'>XXXXXXXXXXXXX</span> <span style='background-color:black'>XXXXX</span>
<td id="mytd">
<pre style='background-color:white;color:gray'>
Area-51. Medical Report. 23/Oct/1969
E.T. subject 4 was given an asprin after reporting sick for duty today
<td id="mytd">
true
</tr>
</table>
| reference | def redacted(doc1, doc2):
return len(doc1) == len(doc2) and all((c1 == 'X' and c2 != '\n') or c1 == c2 for c1, c2 in zip(doc1, doc2))
| Redacted! | 5b662d286d0db722bd000013 | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b662d286d0db722bd000013 | 7 kyu |
# First Things First
## Description
Well the purpose of this kata to find a way to do some operations
after the return statement.
## Your task
You are required to call two functions `first` and `last`. You must call them
in that order inside your function.
The catch is that your function must return what the first function returns.
Also you must not declare any variables in your function.
| bug_fixes | def solution(first, last):
try:
return first()
finally:
last()
| First thing first. | 5b64334ab1788374fb0000c8 | [
"Debugging"
]
| https://www.codewars.com/kata/5b64334ab1788374fb0000c8 | 7 kyu |
Given a long number, return all the possible sum of two digits of it.
For example, `12345`: all possible sum of two digits from that number are:
[ 1 + 2, 1 + 3, 1 + 4, 1 + 5, 2 + 3, 2 + 4, 2 + 5, 3 + 4, 3 + 5, 4 + 5 ]
Therefore the result must be:
[ 3, 4, 5, 6, 5, 6, 7, 7, 8, 9 ] | algorithms | from itertools import combinations
def digits(num):
return list(map(sum, combinations(map(int, str(num)), 2)))
| Every possible sum of two digits | 5b4e474305f04bea11000148 | [
"Algorithms"
]
| https://www.codewars.com/kata/5b4e474305f04bea11000148 | 7 kyu |
Given an array (or list or vector) of arrays (or, guess what, lists or vectors) of integers, your goal is to return the sum of a specific set of numbers, starting with elements whose position is equal to the main array length and going down by one at each step.
Say for example the parent array (etc, etc) has 3 sub-arrays inside: you should consider the third element of the first sub-array, the second of the second array and the first element in the third one: `[[3, 2, 1, 0], [4, 6, 5, 3, 2], [9, 8, 7, 4]]` would have you considering `1` for `[3, 2, 1, 0]`, `6` for `[4, 6, 5, 3, 2]` and `9` for `[9, 8, 7, 4]`, which sums up to `16`.
One small note is that not always each sub-array will have enough elements, in which case you should then use a default value (if provided) or `0` (if not provided), as shown in the test cases. | algorithms | def elements_sum(arr, d=0):
return sum(r[i] if i < len(r) else d for i, r in enumerate(reversed(arr)))
| Sub-array elements sum | 5b5e0ef007a26632c400002a | [
"Arrays",
"Lists",
"Algorithms"
]
| https://www.codewars.com/kata/5b5e0ef007a26632c400002a | 7 kyu |
You are given a array which contains sub-arrays. Each sub-array represents a
point in a (2d) cartesian coordinate system.
Create a function which returns the distance of the two points which are farthest apart.
All distances are to be rounded to 2 decimal places.
If the array contains two points return the distance between them. There will always be at least two points.
```python
furthest_distance([[1,2], [3,8], [4,3]]) # returns 6.32
```
Distances between
`[1,2] [3,8]` : `6.32`
`[3,8] [4,3]` : `5.10`
`[1,2] [4,3]` : `3.16`
This [link](http://www.purplemath.com/modules/distform.htm) may help if you don't know how to work out the distance between two points. | reference | from itertools import combinations
def furthestDistance(arr):
return round(max(sum((y - x) * * 2 for x, y in zip(* comb)) * * .5 for comb in combinations(arr, 2)), 2)
| Farthest Distance | 5b56e42805f04b1780000073 | [
"Arrays",
"Mathematics",
"Fundamentals"
]
| https://www.codewars.com/kata/5b56e42805f04b1780000073 | 7 kyu |
Beaches are filled with sand, water, fish, and sun. Given a string, calculate how many times the words `"Sand"`, `"Water"`, `"Fish"`, and `"Sun"` appear without overlapping (regardless of the case).
## Examples
```csharp
SumOfABeach("WAtErSlIde") ==> 1
SumOfABeach("GolDeNSanDyWateRyBeaChSuNN") ==> 3
SumOfABeach("gOfIshsunesunFiSh") ==> 4
SumOfABeach("cItYTowNcARShoW") ==> 0
```
```python
sum_of_a_beach("WAtErSlIde") ==> 1
sum_of_a_beach("GolDeNSanDyWateRyBeaChSuNN") ==> 3
sum_of_a_beach("gOfIshsunesunFiSh") ==> 4
sum_of_a_beach("cItYTowNcARShoW") ==> 0
```
```javascript
sumOfABeach("WAtErSlIde") ==> 1
sumOfABeach("GolDeNSanDyWateRyBeaChSuNN") ==> 3
sumOfABeach("gOfIshsunesunFiSh") ==> 4
sumOfABeach("cItYTowNcARShoW") ==> 0
```
```coffeescript
sumOfABeach("WAtErSlIde") ==> 1
sumOfABeach("GolDeNSanDyWateRyBeaChSuNN") ==> 3
sumOfABeach("gOfIshsunesunFiSh") ==> 4
sumOfABeach("cItYTowNcARShoW") ==> 0
```
```php
sumOfABeach("WAtErSlIde") ==> 1
sumOfABeach("GolDeNSanDyWateRyBeaChSuNN") ==> 3
sumOfABeach("gOfIshsunesunFiSh") ==> 4
sumOfABeach("cItYTowNcARShoW") ==> 0
```
```ruby
sum_of_a_beach("WAtErSlIde") ==> 1
sum_of_a_beach("GolDeNSanDyWateRyBeaChSuNN") ==> 3
sum_of_a_beach("gOfIshsunesunFiSh") ==> 4
sum_of_a_beach("cItYTowNcARShoW") ==> 0
```
```elixir
sum_of_a_beach("WAtErSlIde") ==> 1
sum_of_a_beach("GolDeNSanDyWateRyBeaChSuNN") ==> 3
sum_of_a_beach("gOfIshsunesunFiSh") ==> 4
sum_of_a_beach("cItYTowNcARShoW") ==> 0
```
```cpp
sum_of_a_beach("WAtErSlIde") ==> 1
sum_of_a_beach("GolDeNSanDyWateRyBeaChSuNN") ==> 3
sum_of_a_beach("gOfIshsunesunFiSh") ==> 4
sum_of_a_beach("cItYTowNcARShoW") ==> 0
```
```crystal
sum_of_a_beach("WAtErSlIde") ==> 1
sum_of_a_beach("GolDeNSanDyWateRyBeaChSuNN") ==> 3
sum_of_a_beach("gOfIshsunesunFiSh") ==> 4
sum_of_a_beach("cItYTowNcARShoW") ==> 0
```
```dart
sumOfABeach("WAtErSlIde") ==> 1
sumOfABeach("GolDeNSanDyWateRyBeaChSuNN") ==> 3
sumOfABeach("gOfIshsunesunFiSh") ==> 4
sumOfABeach("cItYTowNcARShoW") ==> 0
``` | algorithms | import re
def sum_of_a_beach(beach):
return len(re . findall('Sand|Water|Fish|Sun', beach, re . IGNORECASE))
| Sum of a Beach | 5b37a50642b27ebf2e000010 | [
"Fundamentals",
"Algorithms",
"Strings",
"Regular Expressions"
]
| https://www.codewars.com/kata/5b37a50642b27ebf2e000010 | 7 kyu |
# Summary
Given a `Hash` made up of _keys_ and _values_, invert the hash by swapping them.
# Examples
```ruby
Given:
{ 'a' => 1,
'b' => 2,
'c' => 3 }
Return:
{ 1 => 'a',
2 => 'b',
3 => 'c' }
Given:
{ 'foo' => 'bar',
'hello' => 'world' }
Return:
{ 'bar' => 'foo',
'world' => 'hello' }
```
```python
Given:
{ 'a' : 1,
'b' : 2,
'c' : 3 }
Return:
{ 1 : 'a',
2 : 'b',
3 : 'c' }
Given:
{ 'foo' : 'bar',
'hello' : 'world' }
Return:
{ 'bar' : 'foo',
'world' : 'hello' }
```
```javascript
Given:
{ a: '1',
b: '2',
c: '3' }
Return:
{ 1: 'a',
2: 'b',
3: 'c' }
Given:
{ foo: 'bar',
hello: 'world' }
Return:
{ bar: 'foo',
world: 'hello' }
```
# Notes
* Keys and values may be of any type appropriate for use as a key.
* All hashes provided as input will have unique values, so the inversion is [involutive](https://en.wikipedia.org/wiki/Involution_%28mathematics%29). In other words, do not worry about identical values stored under different keys.
```if:ruby
Ruby has a built-in `Hash#invert`. This is awesome, but is disabled for this kata so you can solve it yourself.
``` | reference | def invert_hash(dictionary):
return {v: k for k, v in dictionary . items()}
| Inverting a Hash | 5b5604e26dc79e6832000101 | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b5604e26dc79e6832000101 | 7 kyu |
You managed to send your friend to queue for tickets in your stead, but there is a catch: he will get there only if you tell him how much that is going to take. And everybody can only take one ticket at a time, then they go back in the last position of the queue if they need more (or go home if they are fine).
Each ticket takes one minutes to emit, the queue is well disciplined, [Brit-style](https://www.codewars.com/kata/english-beggars), and so it moves smoothly, with no waste of time.
You will be given an array/list/vector with all the people queuing and the *initial* position of your buddy, so for example, knowing that your friend is in the third position (that we will consider equal to the index, `2` (`3` in COBOL): he is the guy that wants 3 tickets!) and the initial queue is `[2, 5, 3, 4, 6]`.
The first dude gets his ticket and the queue goes now like this `[5, 3, 4, 6, 1]`, then `[3, 4, 6, 1, 4]` and so on. In the end, our buddy will be queuing for 12 minutes, true story!
Build a function to compute it, resting assured that only positive integers are going to be there and you will be always given a valid index; but we also want to go to pretty popular events, so be ready for big queues with people getting plenty of tickets.
| algorithms | def queue(queuers, pos):
return sum(min(queuer, queuers[pos] - (place > pos)) for place, queuer in enumerate(queuers))
| Queue time counter | 5b538734beb8654d6b00016d | [
"Queues",
"Lists",
"Algorithms"
]
| https://www.codewars.com/kata/5b538734beb8654d6b00016d | 7 kyu |
Given a number `n`, draw stairs using the letter `"I"`, `n` tall and `n` wide, with the tallest in the top left.
For example `n = 3` result in:
```
"I\n I\n I"
```
or printed:
```
I
I
I
```
Another example, a 7-step stairs should be drawn like this:
```
I
I
I
I
I
I
I
``` | algorithms | def draw_stairs(n):
return '\n' . join(' ' * i + 'I' for i in range(n))
| Draw stairs | 5b4e779c578c6a898e0005c5 | [
"ASCII Art",
"Algorithms"
]
| https://www.codewars.com/kata/5b4e779c578c6a898e0005c5 | 8 kyu |
Given a non-empty array of non-empty integer arrays, multiply the contents of each nested array and return the smallest total.
### Example
```
input = [
[1, 5],
[2],
[-1, -3]
]
result = 2
``` | reference | from math import prod
def smallest_product(a):
return min(map(prod, a))
| Smallest Product | 5b6b128783d648c4c4000129 | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b6b128783d648c4c4000129 | 7 kyu |
You have a group chat application, but who is online!?
You want to show your users which of their friends are online and available to chat!
Given an input of an array of objects containing usernames, status and time since last activity (in mins), create a function to work out who is ```online```, ```offline``` and ```away```.
If someone is ```online``` but their ```lastActivity``` was more than 10 minutes ago they are to be considered ```away```.
The input data has the following structure:
```javascript
[{
username: 'David',
status: 'online',
lastActivity: 10
}, {
username: 'Lucy',
status: 'offline',
lastActivity: 22
}, {
username: 'Bob',
status: 'online',
lastActivity: 104
}]
```
```csharp
// Example input:
new User[]
{
new User("David", UserStatus.Online, 10),
new User("Lucy", UserStatus.Offline, 22),
new User("Bob", UserStatus.Online, 104)
};
// Reference:
public enum UserStatus
{
Online,
Offline,
Away
}
public class User
{
public string Username;
public UserStatus Status;
public int LastActivity;
public User(string username, UserStatus status, int lastActivity)
{
Username = username;
Status = status;
LastActivity = lastActivity;
}
}
```
The corresponding output should look as follows:
```javascript
{
online: ['David'],
offline: ['Lucy'],
away: ['Bob']
}
```
```csharp
Dictionary<UserStatus, IEnumerable<string>>
{
{UserStatus.Online, new[] {"David"}},
{UserStatus.Offline, new[] {"Lucy"}},
{UserStatus.Away, new[] {"Bob"}}
};
```
If for example, no users are ```online``` the output should look as follows:
```javascript
{
offline: ['Lucy'],
away: ['Bob']
}
```
```csharp
new Dictionary<UserStatus, IEnumerable<string>>
{
{UserStatus.Offline, new[] {"Lucy"}},
{UserStatus.Away, new[] {"Bob"}}
};
```
username will always be a ```string```, status will always be either ```'online'``` or ```'offline'``` (UserStatus enum in C#) and lastActivity will always be ```number >= 0```.
Finally, if you have no friends in your chat application, the input will be an empty array ```[]```. In this case you should return an empty object ```{}``` (empty Dictionary in C#).
| reference | from collections import defaultdict
def who_is_online(friends):
d = defaultdict(list)
for user in friends:
status = 'away' if user['status'] == 'online' and user['last_activity'] > 10 else user['status']
d[status]. append(user['username'])
return d
| Who's Online? | 5b6375f707a2664ada00002a | [
"Arrays",
"Fundamentals"
]
| https://www.codewars.com/kata/5b6375f707a2664ada00002a | 7 kyu |
A number is a Kaprekar number if its square can be split up into two parts which sum up to the original number. (https://en.wikipedia.org/wiki/Kaprekar_number )
For example, the following are Kaprekar numbers:
- 9: 9^2=81 and 8+1=9.
- 45: 45^2=2025 and 20+25=45
- 2223: 2223^2=4941729 and 494+1729=2223
Create a function that - if the input is a Kaprekar number - outputs the index that splits the square into the two parts that sum to the original number. For non-Kaprekar numbers, the output should be -1.
E.g Given an input of 2223, the square will be 4941729. 4941729 has to be split before the 3rd index to get 494 and 1729, which sum to the original number 2223. So for 2223, the function should output 3.
Examples:
```
9 -> 1
45 -> 2
2223 -> 3
5050 -> 4
5051 -> -1
```
Note:
- The function should also work in cases where there are leading zeros. e.g For 99999, its square is 9999800001, which can be split into 99998 and 00001 to sum to the original number 99999.
- 1 is a Kaprekar number as 1^2=1 and 0+1=1. Given an input of 1, the desired output is 0.
| reference | def kaprekar_split(n):
s = str(n * * 2)
for i in range(len(s)):
if int(s[: i] or 0) + int(s[i:] or 0) == n:
return i
return - 1
| Kaprekar Split | 5b6ee22ac5cc71833f0010d7 | [
"Strings",
"Arrays",
"Fundamentals"
]
| https://www.codewars.com/kata/5b6ee22ac5cc71833f0010d7 | 7 kyu |
DNA sequencing data can be stored in many different formats. In this Kata, we will be looking at SAM formatting. It is a plain text file where every line (excluding the first header lines) contains data about a "read" from whatever sample the file comes from. Rather than focusing on the whole read, we will take two pieces of information: the cigar string and the nucleotide sequence.
The cigar string is composed of numbers and flags. It represents how the read aligns to what is known as a reference genome. A reference genome is an accepted standard for mapping the DNA.
The nucleotide sequence shows us what bases actually make up that section of DNA. They can be represented with the letters A, T, C, or G.
Example Read: ('36M', 'ACTCTTCTTGCGAAAGTTCGGTTAGTAAAGGGGATG')
The M in the above cigar string stands for "match", and the 36 stands for the length of the nucleotide sequence. Since all 36 bases are given the 'M' distinction, we know they all matched the reference.
Example Read: ('20M10S', 'ACTCTTCTTGCGAAAGTTCGGTTAGTAAAG')
In the above cigar string, only 20 have the "M" distinction, but the length of the actual string of nucleotides is 30. Therefore we know that read did not match the reference. (Don't worry about what the other letters mean. That will be covered in a later kata.)
Your job for this kata is to create a function that determines whether a cigar string fully matches the reference and accounts for all bases. If it does fully match, return True. If the numbers in the string do not match the full length of the string, return 'Invalid cigar'. If it does not fully match, return False.
*Note for C++: Return True, False, or Invalid Cigar as strings*
| reference | import re
def is_matched(read):
total = sum([int(num) for num in re . findall(r'\d+', read[0])])
if read[0] == str(len(read[1])) + 'M':
return True
elif len(read[1]) != total:
return 'Invalid cigar'
else:
return False
| Cigar Strings (Easy) | 5b64d2cd83d64828ce000039 | [
"Lists",
"Fundamentals"
]
| https://www.codewars.com/kata/5b64d2cd83d64828ce000039 | 7 kyu |
Given two forces (_F<sub>1</sub>_ and _F<sub>2</sub>_ ) and the angle _F<sub>2</sub>_ makes with _F<sub>1</sub>_ find the resultant force _R_ and the angle it makes with _F<sub>1</sub>_.
input
====
Three values :
- _F<sub>1</sub>_
- _F<sub>2</sub>_ making an angle _θ_ with _F<sub>1</sub>_
- angle _θ_
output
====
An array consisting of two values :
- _R_ (the resultant force)
- angle _R_ makes with _F<sub>1</sub>_ (_φ_)
notes
====
Units for each of the following are given as under :
- _F<sub>1</sub>_ = Newton
- _F<sub>2</sub>_ = Newton
- angle _θ_ = degree
- _R_ = Newton
- _φ_ = degree | algorithms | from math import cos, radians, sin, atan2, degrees, hypot
def solution(f1, f2, theta):
r = radians(theta)
x = f1 + f2 * cos(r)
y = f2 * sin(r)
return hypot(x, y), degrees(atan2(y, x))
| Calculate the resultant force | 5b707fbc8adeaee7ac00000c | [
"Physics",
"Geometry",
"Algorithms"
]
| https://www.codewars.com/kata/5b707fbc8adeaee7ac00000c | 7 kyu |
Ronny the robot is watching someone perform the Cups and Balls magic trick. The magician has one ball and three cups, he shows Ronny which cup he hides the ball under (b), he then mixes all the cups around by performing multiple two-cup switches (arr). Ronny can record the switches but can't work out where the ball is. Write a programme to help him do this.
Rules:
- There will only ever be three cups.
- Only two cups will be swapped at a time.
- The cups and their switches will be refered to by their index in a row of three, beginning at one. So [[1,2]] means the cup at position one, is swapped with the cup at position two.
- Arr will be an array of integers 1 - 3 organised in pairs.
- There won't be any empty sub-arrays.
- If arr is just an empty array b should be returned.
Examples:
(b) = 2,
(arr) = [[1,2]]
The ball is under cup number : 1
-------
(b) = 1,
(arr) = [[2,3],[1,2],[1,2]]
The ball is under cup number : 1
-------
(b) = 2,
(arr) = [[1,3],[1,2],[2,1],[2,3]]
The ball is under cup number : 3
| reference | from functools import reduce
def cup_and_balls(b, arr):
return reduce(lambda x, y: y[1] if x == y[0] else y[0] if x == y[1] else x, arr, b)
| Ball and Cups | 5b715fd11db5ce5912000019 | [
"Arrays",
"Fundamentals"
]
| https://www.codewars.com/kata/5b715fd11db5ce5912000019 | 7 kyu |
A bug lives in a world which is a cuboid and has to walk from one corner of the cuboid to the opposite corner (see the picture below).
<img src="https://www.technologyuk.net/mathematics/geometry/images/geometry_0161.gif"
alt="Google 'Cuboid Space Diagonal' "
style="float: right; margin-right: 10px;" />
### Task
Define a function which takes 3 arguments: the length `a` , width `b`, and height `c` of the bug's "world", and finds the shortest distance needed to **walk** from start to finish. The dimensions will be positive numbers.
**Note**: The bug cannot fly and has to maintain contact with a surface at all times but can walk up walls.
### Example
```
a=1, b=2, c=3: distance=4.242640687119285
```
___
### Hints
**Hint 1**: Consider how many different routes can be made to get from start to finish. If stuck for where to start, click
[here](https://www.flickr.com/photos/141856599@N06/42176717300/in/dateposted-public/)
for general guidance.
**Hint 2**: Consider using paper and opening up the net of a cuboid (and think if there are multiple ways this can be viewed) and play around with it to find the shortest length. | reference | def shortest_distance(a, b, c):
a, b, c = sorted([a, b, c])
return ((a + b) * * 2 + c * * 2) * * 0.5
| Bugs Life | 5b71af678adeae41df00008c | [
"Fundamentals",
"Geometry"
]
| https://www.codewars.com/kata/5b71af678adeae41df00008c | 7 kyu |
Your task is to sum the differences between consecutive pairs in the array in descending order.
## Example
```
[2, 1, 10] --> 9
```
In descending order: `[10, 2, 1]`
Sum: `(10 - 2) + (2 - 1) = 8 + 1 = 9`
If the array is empty or the array has only one element the result should be `0` (`Nothing` in Haskell, `None` in Rust).
~~~if:lambdacalc
#### Encodings
purity: `LetRec`
numEncoding: `BinaryScott`
export constructors `nil, cons` for your `List` encoding
~~~
| reference | def sum_of_differences(arr):
return max(arr) - min(arr) if arr else 0
| Sum of differences in array | 5b73fe9fb3d9776fbf00009e | [
"Arrays",
"Fundamentals"
]
| https://www.codewars.com/kata/5b73fe9fb3d9776fbf00009e | 8 kyu |
In this Kata, you will be given a lower case string and your task will be to remove `k` characters from that string using the following rule:
```Python
- first remove all letter 'a', followed by letter 'b', then 'c', etc...
- remove the leftmost character first.
```
```Python
For example:
solve('abracadabra', 1) = 'bracadabra' # remove the leftmost 'a'.
solve('abracadabra', 2) = 'brcadabra' # remove 2 'a' from the left.
solve('abracadabra', 6) = 'rcdbr' # remove 5 'a', remove 1 'b'
solve('abracadabra', 8) = 'rdr'
solve('abracadabra',50) = ''
```
More examples in the test cases. Good luck!
Please also try:
[Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9db0000f2)
[Simple remove duplicates](https://www.codewars.com/kata/5ba38ba180824a86850000f7)
| reference | def solve(st, k):
for l in sorted(st)[: k]:
st = st . replace(l, '', 1)
return st
| Simple letter removal | 5b728f801db5cec7320000c7 | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b728f801db5cec7320000c7 | 7 kyu |
In this Kata, you will be given two positive integers `a` and `b` and your task will be to apply the following operations:
```
i) If a = 0 or b = 0, return [a,b]. Otherwise, go to step (ii);
ii) If a ≥ 2*b, set a = a - 2*b, and repeat step (i). Otherwise, go to step (iii);
iii) If b ≥ 2*a, set b = b - 2*a, and repeat step (i). Otherwise, return [a,b].
```
`a` and `b` will both be lower than 10E8.
More examples in tests cases. Good luck!
Please also try [Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9db0000f2) | reference | def solve(a, b):
'''
Used the % operator instead of repeated subtraction of a - 2*b or b - 2*a
Because as long as a > 2*b, the repeated subtraction has to be done and it will
eventually give a % 2*b. Repeated subtration in recursion has the problem of
exceeding the recursion depth, so this approach is better
'''
if a == 0 or b == 0:
return [a, b]
elif a >= 2 * b:
return solve(a % (2 * b), b)
elif b >= 2 * a:
return solve(a, b % (2 * a))
else:
return [a, b]
| Recursion 101 | 5b752a42b11814b09c00005d | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b752a42b11814b09c00005d | 7 kyu |
You start with a value in dollar form, e.g. $5.00. You must convert this value to a string in which the value is said, like '5 dollars' for example. This should account for ones, cents, zeroes, and negative values. Here are some examples:
```python
dollar_to_speech('$0.00') == '0 dollars.'
dollar_to_speech('$1.00') == '1 dollar.'
dollar_to_speech('$0.01') == '1 cent.'
dollar_to_speech('$5.00') == '5 dollars.'
dollar_to_speech('$20.18') == '20 dollars and 18 cents.'
dollar_to_speech('$-1.00') == 'No negative numbers are allowed!'
```
These examples account for pretty much everything. This kata has many specific outputs, so good luck! | algorithms | def dollar_to_speech(value):
if "-" in value:
return "No negative numbers are allowed!"
d, c = (int(n) for n in value . replace("$", ""). split("."))
dollars = "{} dollar{}" . format(
str(d), "s" if d != 1 else "") if d or not c else ""
link = " and " if (d and c) else ""
cents = "{} cent{}" . format(str(c), "s" if c != 1 else "") if c else ""
return "{}{}{}." . format(dollars, link, cents)
| Dollar Value to Speech Conversion | 5b23d98da97f02a5f4000a4c | [
"Algorithms"
]
| https://www.codewars.com/kata/5b23d98da97f02a5f4000a4c | 7 kyu |
You will be given a matrix of ```m``` rows and ```n``` columns like:
<a href="http://imgur.com/0w2EWQb"><img src="http://i.imgur.com/0w2EWQb.png?2" title="source: imgur.com" /></a>
The matrix has some ```aij``` equals to ```0``` at different locations ```i, j``` and the others, all positive.
Your task will be to find the maximum possible product in all the rows and in all the columns of contiguous elements (horizontally or vertically).
The products should be result of at least two adjacent elements in vertical or horizontal direction.
Let's see an example:
```
matrix = [[2, 1, 4, 1], [0, 4, 8, 1], [1, 0, 10, 0]]
```
The horizontal and vertical products of contiguous elements different than ```0``` will be:
```
location numbers product direction (H = horizontal, V = vertical)
row 1 [2, 1] 2 H
row 1 [1, 4] 4 H
row 1 [4, 1] 4 H
row 1 [2, 1, 4] 8 H
row 1 [2, 1, 4, 1] 8 H
row 2 [4, 8] 32 H
row 2 [8, 1] 8 H
row 2 [4, 8, 1] 32 H
column 2 [1, 4] 4 V
column 3 [4, 8] 32 V
column 3 [8, 10] 80 V
column 3 [4, 8, 10] 320 V <---- maximum product
column 4 [1, 1] 1 V
```
So, the function that calculates the maximum possible product will work in the following way:
```python
highest_prod([[2, 1, 4, 1], [0, 4, 8, 1], [1, 0, 10, 0]]) == 320
```
```javascript
highest_prod([[2, 1, 4, 1], [0, 4, 8, 1], [1, 0, 10, 0]]) == 320
```
If the abundance of zeroes in the matrix is very high, the result can be zero, although the matrix may have some numbers different than zero.
```python
highest_prod([[2, 0, 4, 0], [0, 0, 0, 0], [1, 0, 10, 0]]) == 0
```
```javascript
highestProd([[2, 0, 4, 0], [0, 0, 0, 0], [1, 0, 10, 0]]) == 0
```
You will find more cases in the Example Test Cases box.
Enjoy it!! | reference | from itertools import groupby
from functools import reduce
def highest_prod(matrix, isH=1):
return max([reduce(int . __mul__, g) for row in matrix
for k, g in map(lambda t: (t[0], list(t[1])), groupby(row, key=bool))
if k and len(g) > 1]
+ [highest_prod(zip(* matrix), 0) if isH else 0])
| Has the Largest Product Horizontal or Vertical Direction? Find it!! | 5b216555a454c8eaa2000019 | [
"Fundamentals",
"Data Structures",
"Algorithms",
"Mathematics",
"Algebra",
"Performance"
]
| https://www.codewars.com/kata/5b216555a454c8eaa2000019 | 6 kyu |
# Leonardo numbers
The **Leonardo numbers** are a sequence of numbers defined by:
L(0) = 1 || 0
L(1) = 1 || 0
L(x) = L(x - 1) + L(x - 2) + 1
Generalizing the above a bit more:
L(x) = L(x - 1) + L(x - 2) + a
Assume `a` to be the __add number__.
---
# Task
Return the first `n` **Leonardo numbers** as an array (`vector<int>` in C++)
# Input
- `n` : The number of Leonardo numbers to be shown
- `L0` : The initial value of L(0)
- `L1` : The initial value of L(1)
- `add` : The add number
---
# Examples
input : n = 5 , L0 = 1 , L1 = 1 , add = 1
output : [ 1, 1, 3, 5, 9 ]
input : n = 5 , L0 = 0 , L1 = 0 , add = 2
output : [ 0, 0, 2, 4, 8 ]
input : n = 10 , L0 = 0 , L1 = 1 , add = 4
output : [ 0, 1, 5, 10, 19, 33, 56, 93, 153, 250 ]
input : n = 5 , L0 = 0 , L1 = 0 , add = 0
output : [ 0, 0, 0, 0, 0 ]
---
# Note
`n` will always be greater than or equal to 2 | algorithms | def L(n, a, b, inc):
lst = []
for _ in range(n):
lst . append(a)
a, b = b, a + b + inc
return lst
| Leonardo numbers | 5b2117eea454c89d4400005f | [
"Algorithms",
"Arrays"
]
| https://www.codewars.com/kata/5b2117eea454c89d4400005f | 7 kyu |
You are the Dungeon Master for a public DnD game at your local comic shop and recently you've had some trouble keeping your players' info neat and organized so you've decided to write a bit of code to help keep them sorted!
The goal of this code is to create an array of objects that stores a player's name and contact number from a given string.
The method should return an empty array if the argument passed is an empty string or `nil`/`None`/`null`.
## Examples
```ruby
player_manager("John Doe, 8167238327, Jane Doe, 8163723827") returns [{player: "John Doe", contact: 8167238327}, {player: "Jane Doe", contact: 8163723827}]
player_manager(nil) returns []
player_manager("") returns []
```
```python
player_manager("John Doe, 8167238327, Jane Doe, 8163723827") returns [{"player": "John Doe", "contact": 8167238327}, {"player": "Jane Doe", "contact": 8163723827}]
player_manager(None) returns []
player_manager("") returns []
```
```
playerManager("John Doe, 8167238327, Jane Doe, 8163723827") returns [{player: "John Doe", contact: 8167238327}, {player: "Jane Doe", contact: 8163723827}]
playerManager(null) returns []
playerManager("") returns []
```
Have at thee! | games | import re
def player_manager(players):
return players and [{'player': who, 'contact': int(num)}
for who, num in re . findall(r'(.+?), (\d+)(?:, )?', players)] or []
| Player Contact Manager | 5b203de891c7469b520000b4 | [
"Arrays"
]
| https://www.codewars.com/kata/5b203de891c7469b520000b4 | 7 kyu |
<img src="https://i.imgur.com/ta6gv1i.png?1" title="source: imgur.com" />
# A History Lesson
The <a href=https://en.wikipedia.org/wiki/Pony_Express>Pony Express</a> was a mail service operating in the US in 1859-60.
<img src="https://i.imgur.com/oEqUjpP.png" title="Pony Express" />
It reduced the time for messages to travel between the Atlantic and Pacific coasts to about 10 days, before it was made obsolete by the [transcontinental telegraph](https://en.wikipedia.org/wiki/First_transcontinental_telegraph).
# How it worked
There were a number of *stations*, where:
* The rider switched to a fresh horse and carried on, or
* The mail bag was handed over to the next rider
# Kata Task
`stations` is a list/array of distances (miles) from one station to the next along the Pony Express route.
Implement the `riders` method/function, to return how many riders are necessary to get the mail from one end to the other.
**NOTE:** Each rider travels as far as he can, but never more than 100 miles.
---
*Good Luck.</br>
DM.*
---
See also
* The Pony Express
* <a href = https://www.codewars.com/kata/the-pony-express-missing-rider>The Pony Express (missing rider)</a>
| reference | def riders(stations):
riders, travelled = 1, 0
for dist in stations:
if travelled + dist > 100:
riders += 1
travelled = dist
else:
travelled += dist
return riders
| The Pony Express | 5b18e9e06aefb52e1d0001e9 | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b18e9e06aefb52e1d0001e9 | 7 kyu |
## Given a set of words, how many letters do you have to remove from them to make them anagrams?
# Example
You are given the set of words ```{'hello', 'hola', 'allo'}```. To obtain anagrams, you have to remove 3 letters from 'hello' (the letters 'hel'), 2 letters from 'hola' (the letters 'ha'), and 2 letters from 'allo' ('al'), therefore the result is __7__ (the anagram is 'lo', or 'ol' since order doesn't matter).
## Hints
* A word is an anagram of another word if they have the same letters (usually in a different order).
* Do not worry about case. All inputs will be lowercase.
### You may want to check out this kata's little brother (or sister) : https://www.codewars.com/kata/anagram-difference | algorithms | from collections import Counter
from functools import reduce
from operator import and_
def anagram_difference(words):
cWords = list(map(Counter, words))
required = reduce(and_, cWords)
return sum(sum((c - required). values()) for c in cWords)
| Hardcore anagram difference | 5b1b48cc647c7e7c56000083 | [
"Strings",
"Algorithms"
]
| https://www.codewars.com/kata/5b1b48cc647c7e7c56000083 | 6 kyu |
Comparing two numbers written in index form like `2^11` and `3^7` is not difficult, as any calculator would confirm that `2^11 = 2048 < 3^7 = 2187`.
However, confirming that `632382^518061 > 519432^525806` would be much more difficult, as both numbers contain over three million digits.
Your task is to write a function that takes two arrays (or two tuples in Python) in the form of `[base, exponent]` where `base` and `exponent` are positive integers, and return the largest of the two pairs of numbers.
Inspired by [Project Euler #99](https://projecteuler.net/problem=99) | algorithms | from math import log
def compare(* numbers):
return max(numbers, key=lambda n: n[1] * log(n[0]))
| Exponential Comparison | 5b1cce03777ab73442000134 | [
"Mathematics",
"Algorithms"
]
| https://www.codewars.com/kata/5b1cce03777ab73442000134 | 6 kyu |
```if:python
<strong>Note: Python may currently have some performance issues. If you find them, please let me know and provide suggestions to improve the Python version! It's my weakest language... any help is much appreciated :)</strong>
```
Artlessly stolen and adapted from <a href="https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem">Hackerrank</a>.
Kara Danvers is new to CodeWars, and eager to climb up in the ranks. We want to determine Kara's rank as she progresses up the leaderboard.
This kata uses <a href="https://en.wikipedia.org/wiki/Ranking#Dense_ranking_(%221223%22_ranking)">Dense Ranking</a>, so any identical scores count as the same rank (e.g, a scoreboard of `[100, 97, 97, 90, 82, 80, 72, 72, 60]` corresponds with rankings of `[1, 2, 2, 3, 4, 5, 6, 6, 7]`
You are given an array, `scores`, of leaderboard scores, descending, and another array, `kara`, representing Kara's Codewars score over time, ascending. Your function should return an array with each item corresponding to the rank of Kara's current score on the leaderboard.
**Note:** This kata's performance requirements are significantly steeper than the Hackerrank version. Some arrays will contain millions of elements; optimize your code so you don't time out. If you're timing out before 200 tests are completed, you've likely got the wrong code complexity. If you're timing out around 274 tests (there are 278), you likely need to make some tweaks to how you're handling the arrays.
<h1>Examples:</h1>
```ruby
scores = [100, 90, 90, 80]
kara = [70, 80, 105]
Should return: [4, 3, 1]
```
```ruby
scores = [982, 490, 339, 180]
kara = [180, 250, 721, 2500]
Should return: [4, 4, 2, 1]
```
```ruby
scores = [1982, 490, 339, 180]
kara = [180, 250, 721, 880]
Should return: [4, 4, 2, 2]
```
```javascript
const scores = [100, 90, 90, 80];
const kara = [70, 80, 105];
Should return: [4, 3, 1]
```
```javascript
const scores = [982, 490, 339, 180]
const kara = [180, 250, 721, 2500]
Should return: [4, 4, 2, 1]
```
```javascript
const scores = [1982, 490, 339, 180]
const kara = [180, 250, 721, 880]
Should return: [4, 4, 2, 2]
```
(For the uninitiated, Kara Danvers is Supergirl. This is important, because Kara thinks and moves so fast that she can complete a kata within microseconds. Naturally, latency being what it is, she's already opened many kata across many, many tabs, and solves them one by one on a special keyboard so she doesn't have to wait hundreds of milliseconds in between solving them. As a result, the only person's rank changing on the leaderboard is Kara's, so we don't have to worry about shifting values of other codewarriors. Thanks, Supergirl.)
Good luck! Please upvote if you enjoyed it :)
| reference | def leaderboard_climb(arr, kara):
scores = sorted(set(arr), reverse=True)
position = len(scores)
ranks = []
for checkpoint in kara:
while position >= 1 and checkpoint >= scores[position - 1]:
position -= 1
ranks . append(position + 1)
return ranks
| Climbing the Leaderboard | 5b19f34c7664aacf020000ec | [
"Arrays",
"Fundamentals"
]
| https://www.codewars.com/kata/5b19f34c7664aacf020000ec | 6 kyu |
# Description
You are required to implement a function `find_nth_occurrence` that returns the index of the nth occurrence of a substring within a string (considering that those substring could overlap each others). If there are less than n occurrences of the substring, return -1.
# Example
```python
string = "This is an example. Return the nth occurrence of example in this example string."
find_nth_occurrence("example", string, 1) == 11
find_nth_occurrence("example", string, 2) == 49
find_nth_occurrence("example", string, 3) == 65
find_nth_occurrence("example", string, 4) == -1
```
```c
const char *string = "This is an example. Return the nth occurrence of example in this example string.";
find_nth_occurrence("example", string, 1) == 11
find_nth_occurrence("example", string, 2) == 49
find_nth_occurrence("example", string, 3) == 65
find_nth_occurrence("example", string, 4) == -1
```
```java
String string = "This is an example. Return the nth occurrence of example in this example string.";
findNthOccurrence("example", string, 1) == 11
findNthOccurrence("example", string, 2) == 49
findNthOccurrence("example", string, 3) == 65
findNthOccurrence("example", string, 4) == -1
```
Multiple occurrences of a substring are allowed to overlap, e.g.
```python
find_nth_occurrence("TestTest", "TestTestTestTest", 1) == 0
find_nth_occurrence("TestTest", "TestTestTestTest", 2) == 4
find_nth_occurrence("TestTest", "TestTestTestTest", 3) == 8
find_nth_occurrence("TestTest", "TestTestTestTest", 4) == -1
```
```c
find_nth_occurrence("TestTest", "TestTestTestTest", 1) == 0
find_nth_occurrence("TestTest", "TestTestTestTest", 2) == 4
find_nth_occurrence("TestTest", "TestTestTestTest", 3) == 8
find_nth_occurrence("TestTest", "TestTestTestTest", 4) == -1
```
```java
findNthOccurrence("TestTest", "TestTestTestTest", 1) == 0
findNthOccurrence("TestTest", "TestTestTestTest", 2) == 4
findNthOccurrence("TestTest", "TestTestTestTest", 3) == 8
findNthOccurrence("TestTest", "TestTestTestTest", 4) == -1
```
| reference | def find_nth_occurrence(substring, string, occurrence=1):
idx = - 1
for i in range(occurrence):
idx = string . find(substring, idx + 1)
if idx == - 1:
return - 1
return idx
| Find the nth occurrence of a word in a string! | 5b1d1812b6989d61bd00004f | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b1d1812b6989d61bd00004f | 7 kyu |
# Story:
Everybody is going crazy about the new cool battle-royale gamemode, but **you are not**, you are crazy about **math**! After seeing how people are rushing towards a safe-zone every couple of minutes to not get killed by some force, you, on the other hand, rushed to see what distance does one have to travel to avoid the damage...
___
# Task:
Based on player's current position, and the position and radius of an ellipse-shaped safe-zone, you have to find the minimal distance he has to travel moving **towards its center** to enter it.
### Input:
1) Player's `(x, y)` coordinate
2) Safe-zone coordinate relocation
3) Safe-zone coordinate quotients
4) Safe-zone radius
### Output:
Distance between the player and the safe-zone.
___
## Notes:
* The radius will always be a `> 0` integer
* If player is already inside the safe-zone, return `0`
* You can assume that there're no obstacles on player's path
* Safe-zone coordinate relocation `(a, b)`, quotients `(p, q)`, and radius `r` can be transformed into this equation: `(px - a)^2 + (qy - b)^2 = r^2` | reference | import numpy as np
def distance(player, relocation, quotients, radius):
y_movement = player[1] - relocation[1] / quotients[1]
x_movement = player[0] - relocation[0] / quotients[0]
distance_p_center = np . sqrt(y_movement * * 2 + x_movement * * 2)
distance_to_cross = distance_p_center * radius / np . sqrt(quotients[0] * * 2 * x_movement * * 2 + quotients[1] * * 2 * y_movement * * 2)
d = distance_p_center - distance_to_cross
if d < 0:
return (0)
else:
return d
| Distance to the safe-zone moving towards its center | 5b1d0685da48c294e3001b31 | [
"Fundamentals",
"Mathematics"
]
| https://www.codewars.com/kata/5b1d0685da48c294e3001b31 | 6 kyu |
Consider the sequence `U(n, x) = x + 2x**2 + 3x**3 + .. + nx**n` where x is a real number and n a positive integer.
When `n` goes to infinity and `x` has a correct value (ie `x` is in its domain of convergence `D`), `U(n, x)` goes to a finite limit `m` depending on `x`.
Usually given `x` we try to find `m`. Here we will try to find `x` (x real, 0 < x < 1) when `m` is given (m real, m > 0).
Let us call `solve` the function `solve(m)` which returns `x` such as U(n, x) goes to `m` when `n` goes to infinity.
#### Examples:
`solve(2.0) returns 0.5` since `U(n, 0.5)` goes to `2` when `n` goes to infinity.
`solve(8.0) returns 0.7034648345913732` since `U(n, 0.7034648345913732)` goes to `8` when `n` goes to infinity.
#### Note:
You pass the tests if `abs(actual - expected) <= 1e-12` | reference | def solve(m):
'''U = x + 2*x^2 + 3*x^3 + ... + n*x^n
x*U = x^2 + 2*x^3 + 3*x^4 + ... + (n-1)*x^n + n*x^(n+1)
(1-x)*U = x + x^2 + x^3 + ... + x^n - n*x^(n+1)
x*(1-x^n)
(1-x)*U = --------- - n*x^(n+1)
1-x
x*(1-x^n) n*x^(n+1) x - x^(n+1) - n*x^(n+1) + n*x^(n+2)
U = --------- - ---------- = ----------------------------------- =
(1-x)^2 1-x (1-x)^2
x - (n+1)*x^(n+1) + n*x^(n+2) x
= ----------------------------- = (n goes to infinity) = -------
(1-x)^2 (1-x)^2
x
------- -> m, then x = m*(1-x)^2 = m - 2*m*x + m*x^2
(1-x)^2
m*x^2 - (2*m + 1)*x + m = 0
D = (-2*m - 1)^2 - 4*m^2 = 4*m^2 +4*m + 1 - 4*m^2 = 4*m + 1
-(-2*m - 1) + (4*m + 1)^0.5 -(-2*m - 1) - (4*m + 1)^0.5
x1, x2 = ---------------------------, ---------------------------
2*m 2*m
2*m + 1 - (4*m + 1)^0.5
x1 is always greater than 1 or equals to 1, then x = -----------------------
2*m'''
return (2 * m + 1 - (4 * m + 1) * * 0.5) / (2 * m)
| Which x for that sum? | 5b1cd19fcd206af728000056 | [
"Fundamentals",
"Mathematics"
]
| https://www.codewars.com/kata/5b1cd19fcd206af728000056 | 5 kyu |
Linear Kingdom has exactly one tram line. It has `n` stops, numbered from 1 to n in the order of tram's movement. At the i-th stop a<sub>i</sub> passengers exit the tram, while b<sub>i</sub> passengers enter it. The tram is empty before it arrives at the first stop.
## Your task
Calculate the tram's minimum capacity such that the number of people inside the tram never exceeds this capacity at any time. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
## Example
```c++
tram(4, {0, 2, 4, 4}, {3, 5, 2, 0}) ==> 6
```
Explaination:
* The number of passengers inside the tram before arriving is 0.
* At the first stop 3 passengers enter the tram, and the number of passengers inside the tram becomes 3.
* At the second stop 2 passengers exit the tram (1 passenger remains inside). Then 5 passengers enter the tram. There are 6 passengers inside the tram now.
* At the third stop 4 passengers exit the tram (2 passengers remain inside). Then 2 passengers enter the tram. There are 4 passengers inside the tram now.
* Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | algorithms | from itertools import accumulate
def tram(stops, descending, onboarding):
return max(accumulate(o - d for d, o in zip(descending[: stops], onboarding)))
| Tram Capacity | 5b190aa7803388ec97000054 | [
"Fundamentals",
"Algorithms"
]
| https://www.codewars.com/kata/5b190aa7803388ec97000054 | 7 kyu |
You wrote all your unit test names in camelCase.
But some of your colleagues have troubles reading these long test names.
So you make a compromise to switch to underscore separation.
To make these changes fast you wrote a class to translate a camelCase name
into an underscore separated name.
Implement the ToUnderscore() method.
Example:
`"ThisIsAUnitTest" => "This_Is_A_Unit_Test"`
**But of course there are always special cases...**
You also have some calculation tests. Make sure the results don't get split by underscores.
So only add an underscore in front of the first number.
Also Some people already used underscore names in their tests. You don't want to change them.
But if they are not split correct you should adjust them.
Some of your colleagues mark their tests with a leading and trailing underscore.
Don't remove this.
And of course you should handle empty strings to avoid unnecessary errors. Just return an empty string then.
Example:
`"Calculate15Plus5Equals20" => "Calculate_15_Plus_5_Equals_20"`
`"This_Is_Already_Split_Correct" => "This_Is_Already_Split_Correct"`
`"ThisIs_Not_SplitCorrect" => "This_Is_Not_Split_Correct"`
`"_UnderscoreMarked_Test_Name_" => _Underscore_Marked_Test_Name_"`
| algorithms | import re
def toUnderScore(name):
return re . sub("(?<=[^_-])_?(?=[A-Z])|(?<=[^\\d_])_?(?=\\d)", "_", name)
| CamelCase to underscore | 5b1956a7803388baae00003a | [
"Fundamentals",
"Regular Expressions",
"Algorithms"
]
| https://www.codewars.com/kata/5b1956a7803388baae00003a | 6 kyu |
In this Kata, you will be given a string that may have mixed uppercase and lowercase letters and your task is to convert that string to either lowercase only or uppercase only based on:
* make as few changes as possible.
* if the string contains equal number of uppercase and lowercase letters, convert the string to lowercase.
For example:
```Haskell
solve("coDe") = "code". Lowercase characters > uppercase. Change only the "D" to lowercase.
solve("CODe") = "CODE". Uppercase characters > lowecase. Change only the "e" to uppercase.
solve("coDE") = "code". Upper == lowercase. Change all to lowercase.
```
More examples in test cases. Good luck!
Please also try:
[Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9db0000f2)
[Simple remove duplicates](https://www.codewars.com/kata/5ba38ba180824a86850000f7) | reference | def solve(s):
upper = 0
lower = 0
for char in s:
if char . islower():
lower += 1
else:
upper += 1
if upper == lower or lower > upper:
return s . lower()
else:
return s . upper()
| Fix string case | 5b180e9fedaa564a7000009a | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b180e9fedaa564a7000009a | 7 kyu |
### Task
You are given a dictionary/hash/object containing some languages and your test results in the given languages. Return the list of languages where your test score is at least `60`, in descending order of the scores.
Note: the scores will always be unique (so no duplicate values)
### Examples
```ruby
{"Java" => 10, "Ruby" => 80, "Python" => 65} --> ["Ruby", "Python"]
{"Hindi" => 60, "Dutch" => 93, "Greek" => 71} --> ["Dutch", "Greek", "Hindi"]
{"C++" => 50, "ASM" => 10, "Haskell" => 20} --> []
```
```python
{"Java": 10, "Ruby": 80, "Python": 65} --> ["Ruby", "Python"]
{"Hindi": 60, "Dutch" : 93, "Greek": 71} --> ["Dutch", "Greek", "Hindi"]
{"C++": 50, "ASM": 10, "Haskell": 20} --> []
```
```javascript
{"Java": 10, "Ruby": 80, "Python": 65} --> ["Ruby", "Python"]
{"Hindi": 60, "Dutch" : 93, "Greek": 71} --> ["Dutch", "Greek", "Hindi"]
{"C++": 50, "ASM": 10, "Haskell": 20} --> []
```
```haskell
[ ("Java", 10), ("Ruby", 80), ("Python", 65) ] -> ["Ruby", "Python"]
[ [ ("Hindi", 60), ("Dutch", 93), ("Greek", 71) ] -> ["Dutch", "Greek", "Hindi"]
[ ("C++", 50), ("ASM", 10), ("Haskell", 20) ] -> []
```
```csharp
new Dictionary<string, int> {{"Java", 10}, {"Ruby", 80}, {"Python", 65}} => {"Ruby", "Python"}
new Dictionary<string, int> {{"Hindi", 60}, {"Greek", 71}, {"Dutch", 93}} => {"Dutch", "Greek", "Hindi"}
new Dictionary<string, int> {{"C++", 50}, {"ASM", 10}, {"Haskell", 20}} => {}
```
```powershell
@{"Java" = 10; "Ruby" = 80; "Python" = 65} --> @("Ruby", "Python")
@{"Hindi"= 60; "Greek"= 71; "Dutch"= 93} --> @("Dutch", "Greek", "Hindi")
@{"C++"= 50; "ASM"= 10; "Haskell"= 20} --> @()
```
---
### My other katas
If you enjoyed this kata then please try [my other katas](https://www.codewars.com/users/anter69/authored)! :-)
#### _Translations are welcome!_ | algorithms | def my_languages(results):
return sorted((l for l, r in results . items() if r >= 60), reverse=True, key=results . get)
| My Language Skills | 5b16490986b6d336c900007d | [
"Sorting",
"Arrays",
"Algorithms"
]
| https://www.codewars.com/kata/5b16490986b6d336c900007d | 7 kyu |
We need a function (for commercial purposes) that may perform integer partitions with some constraints.
The function should select how many elements each partition should have.
The function should discard some "forbidden" values in each partition.
So, create ```part_const()```, that receives three arguments.
```part_const((1), (2), (3))```
```
(1) - The integer to be partitioned
(2) - The number of elements that each partition should have
(3) - The "forbidden" element that cannot appear in any partition
```
```part_const()``` should output the amount of different integer partitions with the constraints required.
Let's see some cases:
```python
part_const(10, 3, 2) ------> 4
/// we may have a total of 8 partitions of three elements (of course, the sum of the elements of each partition should be equal 10) :
[1, 1, 8], [1, 2, 7], [1, 3, 6], [1, 4, 5], [2, 2, 6], [2, 3, 5], [2, 4, 4], [3, 3, 4]
but 2 is the forbidden element, so we have to discard [1, 2, 7], [2, 2, 6], [2, 3, 5] and [2, 4, 4]
So the obtained partitions of three elements without having 2 in them are:
[1, 1, 8], [1, 3, 6], [1, 4, 5] and [3, 3, 4] (4 partitions)///
```
```ruby
part_const(10, 3, 2) ------> 4
# we may have a total of 8 partitions of three elements (of course, the sum of the elements of each partition should be equal 10) :
[1, 1, 8], [1, 2, 7], [1, 3, 6], [1, 4, 5], [2, 2, 6], [2, 3, 5], [2, 4, 4], [3, 3, 4]
# but 2 is the forbidden element, so we have to discard:
[1, 2, 7], [2, 2, 6], [2, 3, 5] and [2, 4, 4]
# So the obtained partitions of three elements without having 2 in them are:
[1, 1, 8], [1, 3, 6], [1, 4, 5] and [3, 3, 4] (4 partitions)
```
```part_const()``` should have a particular feature:
if we introduce ```0``` as the forbidden element, we will obtain the total amount of partitions with the constrained number of elements.
In fact,
```python
part_const(10, 3, 0) ------> 8 # The same eight partitions that we saw above.
```
Enjoy it and happy coding!!
| reference | def part_const(n, k, num):
return part(n, k) - part(n - (num or n), k - 1)
def part(n, k):
return 1 if k in (1, n) else sum(part(n - k, i) for i in range(1, min(n - k, k) + 1))
| Cut me in Pieces but in The Way I Like | 55fbb7063097cf0b6b000032 | [
"Fundamentals",
"Algorithms",
"Mathematics"
]
| https://www.codewars.com/kata/55fbb7063097cf0b6b000032 | 6 kyu |
This kata is inspired on the problem #50 of the Project Euler.
The prime ``` 41``` is the result of the sum of many consecutive primes.
In fact, ``` 2 + 3 + 5 + 7 + 11 + 13 = 41 , (6 addens) ```
Furthermore, the prime ``` 41``` is the prime below ``` 100 (val_max)``` that has the longest chain of consecutive prime addens.
The prime with longest chain of addens for ```val_max = 500``` is ```499``` with ```17``` addens.
In fact:
```3+5+7+11+13+17+19+23+29+31+37+41+43+47+53+59+61= 499```
Write a function that receives an integer `n` as argument and returns a sorted list of prime numbers strictly inferior to `n` that have the longest longest chain of consecutive prime addens.
Let's see some cases (Input -> Output):
```
* 100 -> [41]
* 500 -> [499]
* 499 -> [379, 491]
```
Range for `n` in random tests:
```
100 ≤ n ≤ 500,000
```
Enjoy it! | reference | PRIME_SUMS = [(0, 0), (2, 2), (3, 5), (5, 10), (7, 17),
(11, 28), (13, 41), (17, 58), (19, 77), (23, 100)]
def is_prime(n: int) - > bool:
sqrt = int(n * * .5)
for i in range(1, len(PRIME_SUMS)):
p = PRIME_SUMS[i][0]
if p > sqrt:
return n > 1
if n % p == 0:
return False
return True
def get_sum_index(n: int) - > int:
left, right = 0, len(PRIME_SUMS) - 1
while left < right:
mid = (left + right) >> 1
if PRIME_SUMS[mid][0] >= n:
right = mid
else:
left = mid + 1
return right
def prime_maxlength_chain(n: int) - > list[int]:
if PRIME_SUMS[- 1][1] >= n:
idx = get_sum_index(n)
else:
p, s = PRIME_SUMS[- 1]
while s < n:
p += 2
if is_prime(p):
s += p
PRIME_SUMS . append((p, s))
idx = len(PRIME_SUMS) - 1
res = []
for i in range(idx):
for j in reversed(range(i + 1)):
diff = PRIME_SUMS[idx - j][1] - PRIME_SUMS[i - j][1]
if diff < n and is_prime(diff):
res . append(diff)
if res:
return res
return res
| The Primes as a Result of the Longest Consecutive Sum I | 56e93159f6c72164b700062b | [
"Performance",
"Algorithms",
"Mathematics",
"Data Structures",
"Arrays",
"Fundamentals"
]
| https://www.codewars.com/kata/56e93159f6c72164b700062b | 5 kyu |
A product-sum number is a natural number N which can be expressed as both the product and the sum of the same set of numbers.
N = a1 × a2 × ... × ak = a1 + a2 + ... + ak
For example, 6 = 1 × 2 × 3 = 1 + 2 + 3.
For a given set of size, k, we shall call the smallest N with this property a minimal product-sum number. The minimal product-sum numbers for sets of size, k = 2, 3, 4, 5, and 6 are as follows.
```
k=2: 4 = 2 × 2 = 2 + 2
k=3: 6 = 1 × 2 × 3 = 1 + 2 + 3
k=4: 8 = 1 × 1 × 2 × 4 = 1 + 1 + 2 + 4
k=5: 8 = 1 × 1 × 2 × 2 × 2 = 1 + 1 + 2 + 2 + 2
k=6: 12 = 1 × 1 × 1 × 1 × 2 × 6 = 1 + 1 + 1 + 1 + 2 + 6
```
Hence for 2 ≤ k ≤ 6, the sum of all the minimal product-sum numbers is 4+6+8+12 = 30; note that 8 is only counted once in the sum.
Your task is to write an algorithm to compute the sum of all minimal product-sum numbers where 2 ≤ k ≤ n.
Courtesy of ProjectEuler.net
| algorithms | """
code to generate arr (takes ~18s so is precomputed):
from math import log2, ceil
from bisect import bisect_right
def find_terms(lower_bound, length, curr_sum, curr_prod, curr_min):
# searches for terms that are >= lower_bound such that sum(terms) + curr_sum = prod(terms) * curr_prod. the number of terms is 'length'
if length == 1:
last_term = curr_sum / ((curr_prod - 1) or 1)
if last_term.is_integer() and curr_sum + last_term < curr_min:
curr_min = curr_sum + int(last_term)
return curr_min, (last_term <= lower_bound)
curr_term = lower_bound
while True:
new_sum = curr_sum + curr_term
new_prod = curr_prod * curr_term
if new_prod >= new_sum or new_sum >= curr_min or new_prod >= curr_min: break
curr_min, flag = find_terms(curr_term, length - 1, new_sum, new_prod, curr_min)
if flag:
# the flag was a signal from the recursive call that this value of curr_term
# is the maximum it could be, so don't increment it any more
break
curr_term += 1
return curr_min, (curr_term == lower_bound)
pow_2s = [2**x for x in range(int(ceil(log2(12000))))]
def min_productsum(k):
# returns the minimal product sum number for a set of size k
curr_min = 2*k
for num_of_ones in range(k-bisect_right(pow_2s, k), k-1):
curr_min, flag = find_terms(2, k - num_of_ones, num_of_ones, 1, curr_min)
return curr_min
arr = [min_productsum(k) for k in range(2, 12000+1)]
since the array is long, write it to a text file, use Ctrl A to select all of it, then paste it
to_print = 'arr = [' + ', '.join(map(str, arr)) + ']'
f = open('productsum_array.txt', 'w')
f.write(to_print)
one could also precompute the return values of product_sum(n)
"""
arr = [4, 6, 8, 8, 12, 12, 12, 15, 16, 16, 16, 18, 20, 24, 24, 24, 24, 24, 28, 27, 32, 30, 48, 32, 32, 32, 36, 36, 36, 42, 40, 40, 48, 48, 48, 45, 48, 48, 48, 48, 48, 54, 60, 54, 56, 54, 60, 63, 60, 60, 60, 63, 64, 64, 64, 64, 64, 70, 72, 72, 72, 72, 72, 72, 84, 80, 80, 81, 80, 80, 80, 81, 84, 88, 96, 90, 96, 90, 108, 90, 96, 96, 96, 96, 96, 96, 96, 96, 100, 110, 112, 105, 108, 108, 108, 117, 108, 108, 108, 112, 112, 120, 120, 120, 120, 120, 120, 120, 120, 120, 152, 125, 228, 126, 128, 128, 128, 128, 128, 128, 140, 144, 140, 135, 156, 140, 140, 144, 144, 144, 144, 144, 144, 144, 144, 150, 156, 150, 156, 162, 192, 160, 168, 160, 160, 160, 176, 160, 160, 160, 176, 162, 168, 168, 168, 168, 176, 184, 176, 175, 176, 180, 180, 180, 180, 190, 180, 180, 180, 192, 192, 189, 348, 192, 192, 189, 192, 192, 192, 192, 192, 192, 192, 200, 216, 216, 200, 200, 208, 208, 208, 210, 216, 210, 216, 210, 216, 216, 216, 216, 216, 216, 216, 216, 216, 216, 224, 224, 240, 224, 224, 224, 248, 234, 240, 234, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 264, 252, 243, 252, 252, 252, 250, 252, 252, 252, 260, 256, 256, 256, 256, 256, 256, 256, 264, 272, 270, 272, 270, 280, 270, 288, 270, 312, 270, 280, 280, 280, 280, 288, 288, 280, 280, 288, 288, 288, 288, 288, 288, 288, 288, 288, 288, 288, 288, 300, 297, 300, 306, 300, 306, 300, 300, 300, 308, 308, 312, 312, 312, 312, 312, 320, 315, 320, 320, 324, 315, 320, 324, 320, 320, 320, 320, 320, 320, 320, 330, 324, 324, 324, 336, 336, 336, 336, 342, 336, 336, 336, 336, 336, 343, 352, 352, 396, 350, 384, 350, 352, 351, 360, 350, 352, 352, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, 468, 378, 380, 375, 408, 378, 380, 384, 392, 378, 384, 375, 384, 378, 384, 378, 384, 384, 384, 384, 384, 384, 384, 384, 384, 384, 392, 392, 396, 396, 396, 405, 420, 400, 400, 405, 400, 400, 400, 405, 420, 432, 420, 405, 416, 416, 420, 416, 416, 416, 420, 425, 420, 432, 420, 420, 420, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 440, 448, 441, 448, 450, 448, 448, 448, 448, 448, 448, 448, 448, 448, 450, 468, 504, 588, 462, 484, 462, 888, 468, 468, 480, 468, 468, 468, 476, 476, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, 500, 486, 504, 486, 528, 486, 504, 495, 500, 504, 504, 504, 500, 504, 504, 500, 500, 504, 504, 504, 504, 504, 512, 525, 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, 528, 528, 528, 540, 528, 525, 528, 528, 528, 540, 540, 540, 540, 539, 540, 540, 540, 540, 540, 540, 540, 546, 540, 540, 540, 575, 576, 550, 560, 560, 588, 560, 560, 567, 560, 560, 560, 560, 560, 570, 560, 560, 560, 572, 572, 567, 576, 576, 576, 567, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, 594, 600, 595, 588, 588, 588, 594, 600, 594, 600, 594, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 612, 612, 612, 616, 624, 616, 624, 624, 616, 616, 624, 624, 624, 630, 624, 624, 624, 624, 624, 630, 644, 625, 648, 630, 640, 630, 640, 630, 640, 640, 640, 648, 640, 640, 640, 640, 640, 640, 640, 640, 640, 640, 648, 648, 648, 648, 648, 648, 648, 648, 660, 672, 660, 660, 660, 672, 680, 672, 672, 672, 672, 672, 672, 672, 672, 672, 672, 672, 672, 672, 672, 672, 684, 675, 696, 696, 720, 700, 720, 686, 700, 693, 720, 700, 720, 693, 700, 720, 700, 702, 700, 702, 700, 702, 720, 700, 700, 704, 704, 704, 704, 714, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 729, 748, 750, 780, 729, 768, 750, 756, 729, 756, 748, 748, 756, 756, 750, 756, 756, 756, 750, 756, 756, 756, 750, 756, 750, 756, 750, 756, 756, 756, 768, 756, 756, 756, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 780, 780, 784, 784, 792, 784, 792, 784, 784, 784, 798, 792, 792, 792, 792, 792, 792, 800, 810, 800, 800, 840, 800, 800, 800, 840, 800, 800, 800, 816, 810, 816, 810, 816, 810, 816, 810, 828, 810, 828, 828, 828, 832, 832, 832, 840, 825, 832, 840, 840, 832, 832, 832, 832, 832, 832, 840, 840, 840, 840, 840, 840, 840, 840, 840, 840, 840, 884, 864, 864, 855, 864, 858, 864, 858, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 880, 882, 896, 875, 880, 882, 880, 880, 880, 882, 896, 882, 896, 912, 896, 891, 900, 896, 896, 891, 896, 896, 896, 896, 896, 896, 896, 896, 896, 896, 900, 900, 900, 910, 912, 918, 920, 918, 924, 918, 924, 918, 924, 924, 924, 936, 936, 931, 924, 924, 924, 935, 960, 950, 936, 936, 936, 952, 936, 936, 936, 936, 936, 936, 960, 950, 952, 945, 960, 950, 960, 945, 952, 952, 960, 945, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 972, 972, 972, 972, 972, 972, 972, 972, 990, 972, 972, 972, 980, 980, 990, 1000, 1000, 1164, 990, 1000, 990, 1008, 990, 1000, 1000, 1008, 1008, 1008, 1000, 1008, 1008, 1000, 1000, 1008, 1008, 1000, 1000, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1020, 1020, 1026, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1040, 1040, 1050, 1040, 1040, 1040, 1050, 1056, 1056, 1080, 1050, 1056, 1050, 1056, 1050, 1064, 1050, 1056, 1050, 1056, 1056, 1056, 1056, 1056, 1056, 1080, 1071, 1080, 1080, 1080, 1071, 1080, 1080, 1080, 1078, 1080, 1080, 1080, 1080, 1080, 1078, 1080, 1080, 1080, 1080, 1080, 1080, 1080, 1080, 1080, 1080, 1080, 1080, 1092, 1092, 1092, 1188, 1100, 1104, 1104, 1104, 1100, 1120, 1116, 1100, 1100, 1120, 1120, 1122, 1152, 1120, 1120, 1134, 1120, 1125, 1120, 1120, 1120, 1122, 1120, 1120, 1140, 1120, 1120, 1120, 1120, 1120, 1472, 1120, 1120, 1120, 1140, 1134, 1140, 1125, 1140, 1134, 1140, 1134, 1140, 1134, 1152, 1134, 1144, 1134, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1152, 1184, 1176, 1200, 1170, 1176, 1170, 1188, 1170, 1188, 1176, 1176, 1176, 1188, 1176, 1176, 1176, 1176, 1176, 1188, 1215, 1200, 1188, 1188, 1188, 1188, 1200, 1188, 1188, 1188, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1216, 1216, 1215, 1216, 1216, 1216, 1215, 1224, 1232, 1224, 1215, 1224, 1224, 1224, 1215, 1232, 1240, 1248, 1225, 1232, 1242, 1232, 1242, 1232, 1232, 1232, 1242, 1248, 1248, 1248, 1248, 1248, 1260, 1260, 1248, 1248, 1248, 1248, 1248, 1248, 1248, 1248, 1248, 1260, 1260, 1260, 1250, 1260, 1260, 1260, 1260, 1260, 1260, 1260, 1275, 1260, 1260, 1260, 1320, 1280, 1280, 1296, 1274, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1280, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1320, 1320, 1320, 1320, 1320, 1320, 1320, 1320, 1320, 1320, 1320, 1320, 1320, 1320, 1320, 1320, 1320, 1344, 1344, 1344, 1323, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1344, 1350, 1360, 1350, 1360, 1350, 1360, 1375, 1368, 1368, 1368, 1365, 1368, 1368, 1380, 1377, 1372, 1392, 1380, 1377, 1380, 1372, 1372, 1375, 1392, 1386, 1392, 1392, 1392, 1386, 1400, 1386, 1440, 1386, 1400, 1386, 1400, 1400, 1404, 1400, 1400, 1458, 1404, 1400, 1428, 1400, 1400, 1400, 1400, 1400, 1404, 1408, 1400, 1400, 1404, 1408, 1408, 1408, 1408, 1408, 1408, 1408, 1464, 1430, 1428, 1428, 1428, 1425, 1440, 1430, 1428, 1428, 1428, 1430, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1440, 1452, 1458, 1456, 1482, 1456, 1456, 1456, 1458, 1472, 1458, 1508, 1458, 1472, 1458, 1472, 1458, 1472, 1458, 1488, 1470, 1488, 1470, 1488, 1470, 1488, 1485, 1508, 1500, 1496, 1485, 1500, 1500, 1500, 1485, 1500, 1496, 1500, 1485, 1496, 1496, 1500, 1521, 1512, 1500, 1500, 1512, 1512, 1500, 1500, 1500, 1500, 1512, 1500, 1512, 1500, 1500, 1500, 1512, 1512, 1512, 1512, 1512, 1512, 1512, 1512, 1512, 1512, 1512, 1512, 1512, 1536, 1536, 1548, 1530, 1536, 1530, 1536, 1530, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1560, 1560, 1560, 1566, 1560, 1560, 1560, 1560, 1560, 1560, 1560, 1560, 1560, 1560, 1568, 1568, 1584, 1568, 1568, 1568, 1568, 1568, 1584, 1568, 1568, 1568, 1584, 1575, 1584, 1584, 1584, 1575, 1584, 1584, 1584, 1584, 1584, 1584, 1584, 1584, 1584, 1596, 1596, 1600, 1600, 1600, 1600, 1600, 1600, 1600, 1600, 1600, 1600, 1620, 1600, 1600, 1600, 1600, 1600, 1600, 1600, 1620, 1640, 1620, 1620, 1620, 1620, 1617, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1632, 1620, 1620, 1620, 1632, 1632, 1632, 1672, 1638, 1680, 1638, 1656, 1638, 1680, 1650, 1656, 1650, 1656, 1650, 1656, 1656, 1656, 1650, 1656, 1650, 1664, 1650, 1664, 1664, 1664, 1664, 1664, 1674, 1680, 1664, 1680, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1680, 1701, 1700, 1694, 1716, 1701, 1700, 1710, 1740, 1700, 1700, 1710, 1716, 1701, 1716, 1710, 1716, 1701, 1740, 1710, 1728, 1701, 1728, 1728, 1716, 1716, 1716, 1728, 1728, 1715, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1760, 1760, 1800, 1760, 1755, 1764, 1760, 1760, 1750, 1760, 1750, 1760, 1755, 1760, 1750, 1764, 1755, 1764, 1760, 1760, 1760, 1764, 1760, 1760, 1760, 1764, 1782, 1764, 1764, 1764, 1782, 1792, 1782, 1800, 1782, 1792, 1782, 1792, 1782, 1792, 1782, 1792, 1782, 1792, 1782, 1800, 1782, 1792, 1792, 1792, 1792, 1792, 1792, 1792, 1792, 1792, 1792, 1792, 1792, 1792, 1792, 1792, 1800, 1800, 1800, 1800, 1800, 1800, 1800, 1820, 1840, 1824, 1815, 1820, 1824, 1820, 1824, 1824, 1820, 1820, 1824, 1824, 1824, 1836, 1836, 1840, 1848, 1848, 1836, 1836, 1836, 1836, 1840, 1836, 1836, 1836, 1860, 1848, 1848, 1848, 1848, 1856, 1848, 1848, 1848, 1856, 1848, 1848, 1848, 1848, 1848, 1872, 1863, 1920, 1862, 1872, 1863, 1872, 1870, 1872, 1872, 1872, 1870, 1872, 1872, 1920, 1872, 1872, 1872, 1872, 1872, 1872, 1872, 1872, 1872, 1872, 1890, 1900, 1890, 1900, 1875, 1904, 1890, 2016, 1890, 1904, 1890, 1900, 1890, 1920, 1890, 1900, 1890, 1980, 1890, 1900, 1890, 1904, 1920, 1904, 1904, 1904, 1920, 1920, 1920, 1920, 1920, 1920, 1911, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1920, 1936, 1944, 1936, 1936, 1936, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1944, 1980, 1980, 1960, 1960, 1960, 1960, 1980, 1976, 1960, 1960, 1976, 1976, 1980, 1980, 1980, 1980, 1980, 1998, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1989, 1980, 1980, 1980, 2002, 2016, 2000, 2000, 1995, 2000, 2000, 2000, 2015, 2000, 2000, 2000, 2000, 2016, 2000, 2000, 2016, 2016, 2000, 2000, 2016, 2000, 2000, 2000, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016, 2040, 2040, 2040, 2025, 2040, 2040, 2040, 2025, 2040, 2040, 2040, 2040, 2040, 2040, 2064, 2070, 2048, 2052, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2112, 2070, 2088, 2079, 2080, 2080, 2080, 2079, 2080, 2080, 2080, 2088, 2088, 2080, 2088, 2079, 2080, 2080, 2100, 2079, 2080, 2080, 2100, 2100, 2100, 2100, 2100, 2100, 2100, 2208, 2100, 2100, 2100, 2112, 2100, 2100, 2100, 2100, 2100, 2106, 2100, 2106, 2100, 2100, 2100, 2106, 2112, 2106, 2112, 2112, 2112, 2112, 2112, 2112, 2112, 2112, 2112, 2142, 2128, 2125, 2128, 2128, 2128, 2142, 2160, 2142, 2160, 2142, 2160, 2160, 2160, 2142, 2160, 2142, 2160, 2142, 2160, 2142, 2156, 2145, 2160, 2160, 2156, 2160, 2156, 2160, 2160, 2160, 2156, 2160, 2160, 2160, 2160, 2156, 2156, 2160, 2160, 2160, 2160, 2160, 2160, 2160, 2160, 2160, 2160, 2160, 2160, 2160, 2160, 2176, 2176, 2176, 2176, 2176, 2176, 2176, 2184, 2184, 2200, 2184, 2184, 2184, 2184, 2184, 2200, 2200, 2232, 2187, 2200, 2214, 2200, 2187, 2220, 2200, 2208, 2187, 2200, 2200, 2208, 2205, 2200, 2200, 2236, 2205, 2232, 2232, 2280, 2205, 2232, 2232, 2232, 2223, 2232, 2232, 2232, 2232, 2232, 2232, 2240, 2240, 2240, 2240, 2240, 2240, 2244, 2240, 2240, 2240, 2268, 2240, 2268, 2240, 2240, 2240, 2240, 2240, 2240, 2240, 2240, 2240, 2240, 2240, 2240, 2240, 2240, 2240, 2240, 2250, 2268, 2280, 2268, 2250, 2268, 2250, 2268, 2250, 2268, 2268, 2268, 2277, 2268, 2268, 2268, 2268, 2268, 2268, 2268, 2268, 2268, 2268, 2268, 2275, 2268, 2268, 2268, 2280, 2304, 2300, 2304, 2295, 2288, 2304, 2288, 2288, 2288, 2304, 2300, 2295, 2304, 2300, 2300, 2295, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2304, 2340, 2340, 2350, 2340, 2352, 2340, 2688, 2368, 2340, 2340, 2340, 2340, 2340, 2340, 2352, 2340, 2340, 2340, 2340, 2340, 2340, 2340, 2352, 2340, 2340, 2340, 2376, 2352, 2352, 2352, 2352, 2352, 2352, 2352, 2352, 2352, 2366, 2352, 2352, 2352, 2352, 2352, 2366, 2376, 2376, 2376, 2376, 2376, 2376, 2376, 2376, 2376, 2375, 2376, 2376, 2376, 2376, 2376, 2376, 2376, 2376, 2376, 2376, 2376, 2376, 2400, 2394, 2400, 2394, 2400, 2394, 2400, 2394, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 2432, 2430, 2432, 2430, 2420, 2430, 2432, 2420, 2420, 2430, 2432, 2436, 2436, 2430, 2448, 2430, 2432, 2430, 2432, 2430, 2432, 2430, 2448, 2430, 2448, 2430, 2448, 2430, 2464, 2430, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2448, 2450, 2464, 2464, 2480, 2450, 2484, 2464, 2464, 2457, 2480, 2464, 2464, 2464, 2464, 2464, 2480, 2464, 2464, 2464, 2496, 2475, 2496, 2484, 2484, 2475, 2484, 2496, 2484, 2475, 2484, 2508, 2496, 2496, 2496, 2496, 2496, 2496, 2496, 2496, 2496, 2496, 2500, 2496, 2496, 2496, 2496, 2496, 2496, 2496, 2496, 2496, 2496, 2520, 2500, 2520, 2520, 2500, 2500, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2520, 2548, 2535, 2592, 2550, 2560, 2610, 2548, 2550, 2560, 2541, 2560, 2550, 2548, 2560, 2576, 2550, 2560, 2548, 2548, 2550, 2576, 2560, 2560, 2574, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2560, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2592, 2640, 2625, 2640, 2640, 2664, 2618, 2640, 2640, 2640, 2625, 2768, 2646, 2640, 2625, 2640, 2640, 2640, 2625, 2640, 2640, 2640, 2640, 2640, 2640, 2640, 2625, 2640, 2640, 2640, 2640, 2640, 2640, 2640, 2640, 2640, 2640, 2640, 2640, 2640, 2640, 2640, 2646, 2700, 2646, 2660, 2646, 2660, 2646, 2688, 2660, 2660, 2662, 2688, 2673, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2700, 2688, 2688, 2673, 2688, 2688, 2688, 2673, 2688, 2688, 2688, 2673, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2688, 2700, 2700, 2700, 2700, 2700, 2700, 2700, 2720, 2700, 2700, 2700, 2728, 2744, 2720, 2736, 2720, 2720, 2720, 2736, 2720, 2720, 2720, 2736, 2730, 2736, 2730, 2752, 2730, 2736, 2730, 2736, 2730, 2736, 2736, 2736, 2736, 2736, 2744, 2820, 2754, 2760, 2772, 2744, 2744, 2760, 2744, 2760, 2754, 2744, 2744, 2760, 2754, 2760, 2750, 2760, 2754, 2772, 2772, 2772, 2805, 2772, 2800, 2772, 2772, 2772, 2790, 2772, 2783, 2772, 2772, 2772, 2772, 2772, 2784, 2772, 2772, 2772, 2790, 2880, 2800, 2800, 2800, 2800, 2800, 2800, 2800, 2800, 2793, 2800, 2800, 2800, 2800, 2800, 2808, 2800, 2800, 2808, 2800, 2800, 2800, 2800, 2800, 2800, 2800, 2800, 2808, 2800, 2800, 2800, 2808, 2808, 2808, 2808, 2808, 2816, 2816, 2816, 2856, 2816, 2816, 2816, 2816, 2816, 2816, 2816, 2850, 2856, 2835, 2880, 2850, 2880, 2835, 2856, 2856, 2856, 2835, 2856, 2856, 2856, 2835, 2880, 2870, 2856, 2835, 2860, 2850, 2860, 2850, 2856, 2856, 2880, 2856, 2856, 2856, 2856, 2856, 2880, 2860, 2860, 2873, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2875, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2880, 2904, 2904, 2904, 2912, 2912, 2904, 2912, 2916, 2904, 2904, 2904, 2904, 2904, 2916, 2912, 2912, 2912, 2912, 2912, 2916, 2912, 2912, 2912, 2916, 2916, 2916, 2916, 2916, 2916, 2916, 2916, 2916, 2988, 2916, 2916, 2916, 2944, 2940, 2952, 2940, 2940, 2940, 2944, 2940, 2940, 2940, 2940, 2940, 2944, 2940, 2970, 2940, 2940, 2940, 2970, 3072, 2964, 3040, 2970, 2976, 2970, 2964, 2964, 2964, 2970, 2976, 2976, 2976, 2970, 2976, 2970, 2976, 2970, 3040, 2970, 2992, 2970, 3000, 2970, 2992, 2970, 2992, 2970, 3024, 2990, 2992, 2997, 3000, 3000, 3000, 3000, 2992, 3000, 2992, 2992, 2992, 3000, 3000, 3000, 3000, 3000, 3000, 3016, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3024, 3040, 3060, 3040, 3040, 3040, 3060, 3072, 3060, 3060, 3060, 3060, 3080, 3060, 3060, 3072, 3060, 3060, 3060, 3060, 3060, 3060, 3060, 3072, 3060, 3060, 3060, 3078, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3087, 3108, 3120, 3120, 3087, 3120, 3132, 3120, 3105, 3120, 3120, 3120, 3105, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3120, 3136, 3168, 3135, 3136, 3146, 3136, 3125, 3136, 3136, 3136, 3150, 3136, 3136, 3136, 3136, 3136, 3136, 3136, 3136, 3136, 3150, 3168, 3150, 3168, 3150, 3168, 3150, 3168, 3150, 3168, 3150, 3168, 3150, 3168, 3159, 3168, 3168, 3168, 3159, 3168, 3168, 3168, 3168, 3168, 3168, 3168, 3168, 3168, 3168, 3168, 3168, 3192, 3192, 3200, 3200, 3200, 3192, 3192, 3185, 3200, 3192, 3192, 3192, 3192, 3192, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3200, 3220, 3230, 3240, 3234, 3240, 3230, 3240, 3240, 3240, 3240, 3240, 3234, 3240, 3234, 3240, 3240, 3240, 3234, 3240, 3240, 3240, 3234, 3240, 3234, 3240, 3240, 3240, 3240, 3240, 3240, 3240, 3240, 3240, 3240, 3240, 3240, 3240, 3240, 3240, 3240, 3276, 3264, 3264, 3264, 3276, 3264, 3264, 3264, 3264, 3264, 3264, 3264, 3264, 3264, 3264, 3267, 3276, 3348, 3276, 3276, 3276, 3276, 3276, 3315, 3276, 3276, 3276, 3311, 3300, 3300, 3300, 3300, 3300, 3312, 3300, 3300, 3300, 3328, 3300, 3300, 3300, 3312, 3300, 3300, 3300, 3300, 3300, 3312, 3300, 3312, 3300, 3300, 3300, 3312, 3312, 3312, 3312, 3330, 3328, 3328, 3328, 3402, 3328, 3348, 3328, 3328, 3328, 3325, 3328, 3328, 3328, 3328, 3344, 3328, 3328, 3332, 3328, 3328, 3328, 3328, 3328, 3328, 3328, 3348, 3344, 3344, 3344, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3360, 3388, 3375, 3380, 3416, 3420, 3375, 3380, 3402, 3420, 3375, 3388, 3402, 3400, 3375, 3432, 3388, 3388, 3402, 3420, 3402, 3420, 3400, 3420, 3402, 3400, 3400, 3420, 3402, 3400, 3400, 3420, 3402, 3420, 3402, 3456, 3402, 3420, 3402, 3420, 3402, 3420, 3402, 3420, 3420, 3420, 3440, 3420, 3420, 3420, 3432, 3432, 3432, 3456, 3456, 3432, 3450, 3456, 3430, 3432, 3430, 3432, 3432, 3456, 3430, 3456, 3450, 3456, 3456, 3456, 3450, 3456, 3450, 3456, 3450, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3456, 3528, 3500, 3564, 3534, 3500, 3496, 3528, 3500, 3496, 3496, 3500, 3500, 3500, 3515, 3500, 3510, 3500, 3500, 3552, 3500, 3500, 3510, 3528, 3500, 3520, 3520, 3500, 3510, 3500, 3519, 3500, 3510, 3500, 3510, 3528, 3500, 3500, 3510, 3520, 3510, 3520, 3510, 3520, 3510, 3520, 3520, 3520, 3520, 3520, 3528, 3520, 3520, 3520, 3520, 3520, 3520, 3520, 3528, 3528, 3528, 3528, 3528, 3528, 3528, 3528, 3528, 3564, 3564, 3564, 3564, 3564, 3564, 3588, 3549, 3564, 3564, 3564, 3584, 3564, 3564, 3564, 3570, 3564, 3570, 3564, 3570, 3564, 3600, 3564, 3564, 3564, 3564, 3564, 3564, 3564, 3564, 3564, 3570, 3564, 3564, 3564, 3575, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3584, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3600, 3625, 3648, 3640, 3660, 3645, 3640, 3640, 3640, 3630, 3648, 3630, 3640, 3640, 3648, 3630, 3648, 3630, 3640, 3630, 3648, 3640, 3672, 3672, 3640, 3640, 3640, 3640, 3672, 3645, 3640, 3640, 3648, 3645, 3648, 3648, 3648, 3645, 3648, 3672, 3672, 3645, 3672, 3672, 3672, 3645, 3672, 3672, 3680, 3672, 3672, 3672, 3672, 3675, 3672, 3672, 3672, 3672, 3672, 3672, 3672, 3672, 3672, 3672, 3680, 3680, 3696, 3696, 3696, 3675, 3696, 3696, 3696, 3696, 3696, 3720, 3696, 3696, 3696, 3696, 3696, 3696, 3696, 3696, 3696, 3705, 3696, 3696, 3696, 3696, 3696, 3712, 3712, 3712, 3720, 3720, 3720, 3720, 3740, 3718, 3744, 3744, 3724, 3726, 3740, 3726, 3744, 3724, 3724, 3726, 3740, 3726, 3744, 3744, 3740, 3744, 3744, 3751, 3744, 3744, 3740, 3744, 3744, 3740, 3740, 3744, 3744, 3744, 3744, 3744, 3744, 3744, 3744, 3744, 3744, 3744, 3744, 3744, 3744, 3744, 3780, 3762, 3780, 3750, 3780, 3750, 3780, 3750, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3773, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3780, 3808, 3780, 3780, 3780, 3800, 3808, 3808, 3800, 3800, 3840, 3840, 3800, 3800, 3840, 3808, 3808, 3808, 3808, 3808, 3840, 3808, 3808, 3808, 3840, 3822, 3828, 3828, 3828, 3840, 3840, 3822, 3840, 3840, 3840, 3822, 3840, 3822, 3840, 3825, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3864, 3864, 3861, 3864, 3864, 3920, 3861, 3888, 3872, 3872, 3872, 3876, 3888, 3888, 3887, 3872, 3872, 3888, 3872, 3872, 3872, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3888, 3900, 3900, 3915, 3936, 3948, 3920, 3920, 3936, 3936, 3920, 3933, 3920, 3920, 3920, 3920, 3920, 3948, 3920, 3920, 3920, 3920, 3920, 3944, 3920, 3920, 3920, 3960, 3952, 3960, 3960, 3952, 3952, 3952, 3960, 3969, 3960, 3960, 3960, 3960, 3952, 3960, 3952, 3952, 3952, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3960, 3996, 3969, 4000, 3978, 4020, 3969, 3996, 3990, 3996, 3969, 3996, 3990, 3996, 3990, 4000, 3990, 4000, 3990, 4004, 3990, 4032, 3993, 4000, 4000, 4004, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4000, 4004, 4000, 4000, 4032, 4000, 4000, 4000, 4032, 4000, 4000, 4000, 4032, 4032, 4032, 4032, 4032, 4025, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4032, 4050, 4080, 4050, 4056, 4050, 4080, 4050, 4056, 4050, 4056, 4050, 4080, 4050, 4080, 4050, 4080, 4050, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4080, 4096, 4096, 4095, 4096, 4104, 4096, 4095, 4096, 4104, 4096, 4095, 4104, 4096, 4096, 4095, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4125, 4116, 4116, 4116, 4158, 4160, 4140, 4116, 4116, 4116, 4140, 4140, 4131, 4140, 4140, 4140, 4125, 4140, 4140, 4140, 4131, 4140, 4140, 4140, 4158, 4176, 4158, 4160, 4158, 4160, 4158, 4200, 4200, 4160, 4158, 4160, 4158, 4160, 4158, 4160, 4158, 4160, 4160, 4176, 4158, 4160, 4158, 4160, 4158, 4160, 4158, 4160, 4160, 4160, 4176, 4176, 4185, 4180, 4218, 4200, 4180, 4180, 4200, 4200, 4200, 4200, 4200, 4200, 4199, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4200, 4212, 4212, 4212, 4212, 4212, 4224, 4212, 4212, 4212, 4224, 4224, 4224, 4224, 4224, 4224, 4224, 4224, 4224, 4224, 4224, 4224, 4224, 4224, 4224, 4300, 4256, 4256, 4256, 4256, 4284, 4284, 4277, 4288, 4288, 4256, 4250, 4284, 4256, 4256, 4250, 4256, 4256, 4284, 4256, 4256, 4256, 4284, 4275, 4284, 4300, 4300, 4284, 4284, 4300, 4284, 4275, 4284, 4290, 4284, 4275, 4284, 4284, 4284, 4275, 4284, 4300, 4284, 4284, 4284, 4284, 4284, 4290, 4284, 4284, 4284, 4290, 4312, 4290, 4320, 4290, 4312, 4320, 4320, 4312, 4320, 4320, 4312, 4320, 4320, 4312, 4320, 4320, 4320, 4312, 4312, 4312, 4320, 4320, 4312, 4312, 4320, 4312, 4320, 4320, 4312, 4312, 4320, 4320, 4320, 4320, 4320, 4320, 4320, 4320, 4320, 4320, 4320, 4320, 4320, 4320, 4320, 4320, 4320, 4320, 4352, 4350, 4352, 4347, 4352, 4350, 4352, 4347, 4368, 4352, 4352, 4352, 4356, 4352, 4352, 4368, 4352, 4352, 4352, 4352, 4352, 4352, 4352, 4356, 4356, 4368, 4368, 4368, 4368, 4368, 4368, 4368, 4368, 4374, 4368, 4368, 4368, 4368, 4368, 4374, 4400, 4374, 4400, 4374, 4440, 4374, 4400, 4374, 5808, 4374, 4416, 4374, 4400, 4374, 4400, 4400, 4400, 4400, 4400, 4400, 4420, 4400, 4400, 4400, 4400, 4410, 4440, 4400, 4400, 4410, 4400, 4400, 4400, 4410, 4416, 4410, 4416, 4410, 4416, 4410, 4416, 4410, 4440, 4410, 4440, 4440, 4440, 4440, 4440, 4440, 4464, 4455, 4488, 4446, 4480, 4455, 4472, 4472, 4480, 4455, 4464, 4446, 4464, 4446, 4464, 4446, 4464, 4455, 4464, 4464, 4480, 4464, 4464, 4464, 4464, 4455, 4464, 4464, 4464, 4455, 4464, 4480, 4480, 4455, 4480, 4480, 4500, 4455, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4488, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4480, 4500, 4500, 4500, 4500, 4500, 4500, 4500, 4508, 4500, 4500, 4500, 4500, 4500, 4500, 4500, 4524, 4500, 4500, 4500, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4536, 4560, 4560, 4560, 4550, 4560, 4560, 4560, 4560, 4560, 4560, 4560, 4560, 4560, 4563, 4608, 4576, 4576, 4576, 4576, 4576, 4592, 4590, 4592, 4590, 4576, 4576, 4608, 4576, 4576, 4576, 4600, 4590, 4608, 4590, 4600, 4590, 4608, 4590, 4608, 4590, 4608, 4590, 4600, 4590, 4608, 4608, 4600, 4600, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4608, 4620, 4640, 4640, 4640, 4680, 4640, 4640, 4640, 4680, 4641, 4680, 4650, 4680, 4650, 4680, 4662, 4680, 4662, 4752, 4662, 4680, 4680, 4680, 4746, 4680, 4655, 4680, 4680, 4680, 4675, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4675, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4680, 4704, 4698, 4704, 4698, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4704, 4752, 4736, 4732, 4725, 4736, 4736, 4736, 4725, 4732, 4752, 4752, 4725, 4752, 4732, 4732, 4725, 4752, 4750, 4752, 4725, 4752, 4752, 4752, 4752, 4752, 4752, 4752, 4752, 4752, 4750, 4752, 4752, 4752, 4750, 4752, 4752, 4752, 4752, 4752, 4752, 4752, 4752, 4752, 4752, 4752, 4752, 4752, 4784, 4784, 4784, 4788, 4797, 4788, 4788, 4788, 4785, 4784, 4800, 4784, 4784, 4784, 4800, 4788, 4800, 4788, 4788, 4788, 4788, 4788, 4800, 4788, 4788, 4788, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4851, 4860, 4830, 4836, 4830, 4836, 4830, 4872, 4830, 4860, 4830, 4860, 4845, 4860, 4840, 4840, 4851, 4840, 4840, 4860, 4845, 4860, 4860, 4840, 4840, 4860, 4860, 4840, 4840, 4860, 4860, 4860, 4860, 4860, 4860, 4860, 4851, 4860, 4860, 4860, 4851, 4860, 4860, 4860, 4860, 4860, 4860, 4860, 4860, 4860, 4860, 4860, 4860, 4860, 4860, 4860, 4875, 4860, 4860, 4860, 4896, 4896, 4896, 4896, 4875, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4896, 4900, 4914, 4900, 4914, 4928, 4900, 4900, 4914, 4928, 4930, 4940, 4914, 4968, 4914, 4928, 4914, 4928, 4914, 4928, 4928, 4928, 4968, 4928, 4928, 4928, 4950, 4928, 4928, 4928, 4928, 4928, 4928, 4928, 4928, 4928, 4950, 4960, 4950, 4960, 4950, 4992, 4950, 4968, 4950, 4960, 4950, 4968, 4950, 4960, 4960, 5040, 4950, 4968, 4950, 4968, 4950, 4968, 4968, 4968, 4968, 4968, 4968, 4968, 4968, 4968, 4968, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 4992, 5016, 5000, 5040, 5022, 5000, 5000, 5040, 5016, 5000, 5000, 5016, 5016, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5040, 5082, 5088, 5088, 5088, 5070, 5088, 5088, 5100, 5070, 5096, 5075, 5100, 5070, 5100, 5070, 5096, 5070, 5100, 5082, 5124, 5082, 5096, 5096, 5100, 5082, 5100, 5100, 5096, 5082, 5100, 5082, 5100, 5100, 5096, 5096, 5104, 5100, 5100, 5103, 5096, 5096, 5100, 5096, 5100, 5120, 5096, 5096, 5100, 5100, 5100, 5103, 5120, 5120, 5120, 5103, 5120, 5120, 5120, 5103, 5120, 5120, 5120, 5103, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5120, 5160, 5148, 5145, 5148, 5152, 5152, 5145, 5152, 5148, 5148, 5152, 5148, 5148, 5148, 5145, 5180, 5184, 5184, 5175, 5168, 5184, 5168, 5168, 5168, 5180, 5180, 5175, 5184, 5184, 5184, 5175, 5184, 5184, 5184, 5175, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5184, 5200, 5200, 5220, 5200, 5200, 5200, 5220, 5220, 5280, 5220, 5220, 5220, 5236, 5280, 5239, 5236, 5250, 5264, 5225, 5248, 5250, 5236, 5244, 5280, 5248, 5236, 5248, 5244, 5244, 5244, 5236, 5236, 5250, 5264, 5250, 5264, 5250, 5264, 5250, 5280, 5250, 5280, 5250, 5280, 5250, 5280, 5250, 5280, 5270, 5280, 5250, 5280, 5250, 5280, 5250, 5280, 5250, 5280, 5250, 5280, 5278, 5292, 5265, 5280, 5280, 5280, 5265, 5280, 5280, 5280, 5265, 5280, 5280, 5280, 5280, 5280, 5280, 5280, 5280, 5280, 5280, 5280, 5280, 5280, 5280, 5280, 5280, 5280, 5280, 5292, 5292, 5292, 5486, 5292, 5292, 5292, 5292, 5292, 5304, 5292, 5292, 5292, 5313, 5400, 5328, 5320, 5328, 5328, 5320, 5328, 5328, 5320, 5320, 5320, 5320, 5360, 5376, 5320, 5320, 5376, 5324, 5324, 5346, 5368, 5346, 5376, 5346, 5412, 5346, 5376, 5346, 5376, 5346, 5424, 5346, 5376, 5346, 5376, 5346, 5376, 5346, 5376, 5346, 5376, 5346, 5376, 5346, 5376, 5346, 5376, 5346, 5376, 5346, 5376, 5346, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5376, 5400, 5400, 5390, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5400, 5440, 5440, 5460, 5440, 5440, 5439, 5440, 5460, 5440, 5434, 5440, 5544, 5440, 5440, 5440, 5440, 5440, 5440, 5440, 5440, 5460, 5440, 5440, 5460, 5440, 5440, 5440, 5440, 5440, 5440, 5440, 5460, 5460, 5445, 5460, 5472, 5460, 5460, 5460, 5472, 5460, 5460, 5460, 5460, 5460, 5472, 5460, 5472, 5460, 5460, 5460, 5472, 5472, 5472, 5472, 5472, 5472, 5472, 5472, 5472, 5472, 5472, 5488, 5488, 5488, 5504, 5500, 5504, 5504, 5488, 5488, 5488, 5488, 5520, 5508, 5488, 5488, 5508, 5488, 5500, 5488, 5488, 5488, 5544, 5500, 5520, 5508, 5508, 5500, 5508, 5508, 5500, 5500, 5508, 5508, 5520, 5508, 5508, 5508, 5520, 5520, 5520, 5520, 5520, 5520, 5525, 5544, 5544, 5544, 5544, 5544, 5544, 5568, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5544, 5600, 5566, 5568, 5568, 5568, 5568, 5568, 5568, 5568, 5568, 5568, 5580, 5580, 5580, 5580, 5589, 5580, 5580, 5580, 5577, 5600, 5600, 5600, 5600, 5600, 5586, 5600, 5589, 5616, 5586, 5600, 5586, 5600, 5600, 5600, 5589, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5600, 5616, 5600, 5600, 5600, 5616, 5616, 5616, 5616, 5616, 5616, 5616, 5616, 5616, 5616, 5616, 5616, 5616, 5632, 5664, 5625, 5632, 5632, 5632, 5625, 5632, 5632, 5632, 5625, 5632, 5632, 5632, 5632, 5632, 5632, 5632, 5632, 5684, 5670, 5712, 5670, 5676, 5670, 5676, 5670, 5712, 5670, 5740, 5670, 5700, 5670, 5700, 5670, 5684, 5670, 5712, 5670, 5700, 5670, 5684, 5670, 5712, 5670, 5700, 5670, 5684, 5670, 5700, 5670, 5712, 5670, 5700, 5670, 5700, 5670, 5700, 5700, 5700, 5712, 5712, 5700, 5700, 5720, 5712, 5700, 5700, 5700, 5700, 5712, 5700, 5712, 5700, 5700, 5700, 5712, 5712, 5712, 5712, 5712, 5712, 5712, 5712, 5720, 5712, 5712, 5712, 5712, 5712, 5742, 5720, 5720, 5740, 5742, 5720, 5720, 5760, 5733, 5760, 5742, 5760, 5742, 5760, 5742, 5760, 5733, 5760, 5760, 5760, 5733, 5760, 5760, 5760, 5760, 5760, 5750, 5760, 5760, 5760, 5750, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5760, 5840, 5840, 5796, 5775, 5796, 5808, 5796, 5800, 5796, 5796, 5796, 5796, 5796, 5814, 5796, 5796, 5796, 5814, 5808, 5808, 5832, 5832, 5808, 5808, 5808, 5808, 5808, 5814, 5808, 5808, 5808, 5824, 5808, 5808, 5808, 5808, 5808, 5824, 5824, 5832, 5824, 5824, 5824, 5824, 5824, 5832, 5824, 5824, 5824, 5824, 5824, 5824, 5824, 5824, 5824, 5832, 5832, 5832, 5832, 5832, 5832, 5832, 5832, 5832, 5832, 5832, 5832, 5832, 5832, 5832, 5832, 5832, 5880, 5880, 5880, 5850, 5880, 5850, 5880, 5850, 5880, 5880, 5880, 5880, 5888, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5880, 5920, 5916, 5920, 5922, 5920, 5922, 5916, 5916, 5916, 5920, 5920, 5920, 5936, 5920, 5920, 5920, 5940, 5940, 5940, 5928, 5928, 5915, 5940, 5940, 5940, 5940, 5928, 5940, 5940, 5928, 5928, 5928, 5928, 5928, 5940, 5950, 5940, 5929, 5940, 5978, 5940, 5940, 5940, 5940, 5940, 5940, 5940, 5940, 5940, 5940, 5940, 5940, 5940, 5940, 5940, 5950, 5940, 5940, 5940, 5950, 6000, 5984, 5984, 5984, 5980, 5985, 5984, 5980, 5980, 5967, 6000, 6000, 5984, 5967, 6000, 5984, 5980, 5984, 6000, 5980, 5980, 5984, 5984, 5984, 6000, 5985, 6000, 5994, 5984, 5984, 6000, 5984, 5984, 5984, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6048, 6032, 6048, 6032, 6032, 6032, 6045, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6045, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6048, 6072, 6072, 6072, 6072, 6120, 6075, 6080, 6080, 6080, 6075, 6084, 6080, 6080, 6075, 6080, 6080, 6080, 6075, 6080, 6080, 6080, 6075, 6084, 6120, 6120, 6075, 6120, 6120, 6120, 6120, 6120, 6136, 6120, 6118, 6144, 6120, 6120, 6120, 6120, 6118, 6120, 6120, 6144, 6120, 6120, 6120, 6120, 6138, 6120, 6120, 6120, 6120, 6120, 6120, 6120, 6120, 6120, 6120, 6120, 6120, 6120, 6120, 6144, 6150, 6144, 6144, 6144, 6144, 6144, 6125, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6144, 6160, 6171, 6160, 6160, 6160, 6174, 6192, 6174, 6188, 6174, 6192, 6200, 6204, 6174, 6188, 6174, 6216, 6174, 6216, 6174, 6188, 6210, 6200, 6200, 6216, 6210, 6200, 6200, 6240, 6216, 6216, 6216, 6240, 6210, 6216, 6210, 6216, 6210, 6232, 6210, 6240, 6210, 6240, 6210, 6240, 6210, 6240, 6240, 6240, 6237, 6240, 6240, 6240, 6240, 6240, 6240, 6240, 6237, 6240, 6240, 6240, 6237, 6240, 6240, 6240, 6237, 6240, 6240, 6240, 6237, 6240, 6240, 6240, 6237, 6240, 6240, 6240, 6237, 6240, 6240, 6240, 6237, 6240, 6240, 6240, 6240, 6264, 6264, 6264, 6264, 6264, 6264, 6264, 6250, 6264, 6264, 6272, 6250, 6272, 6270, 6272, 6270, 6272, 6270, 6272, 6272, 6272, 6272, 6272, 6272, 6272, 6272, 6272, 6272, 6272, 6272, 6272, 6272, 6272, 6272, 6272, 6272, 6300, 6300, 6300, 6292, 6292,
6300, 6300, 6300, 6300, 6300, 6300, 6300, 6300, 6300, 6300, 6318, 6300, 6300, 6300, 6300, 6300, 6300, 6300, 6336, 6300, 6300, 6300, 6336, 6336, 6318, 6336, 6318, 6336, 6318, 6336, 6318, 6336, 6318, 6336, 6318, 6336, 6318, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6336, 6370, 6384, 6400, 6384, 6375, 6380, 6380, 6384, 6405, 6380, 6392, 6384, 6370, 6384, 6384, 6380, 6384, 6384, 6370, 6380, 6370, 6384, 6396, 6384, 6370, 6384, 6384, 6384, 6375, 6384, 6384, 6384, 6510, 6384, 6384, 6384, 6384, 6384, 6400, 6400, 6400, 6400, 6400, 6400, 6417, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6400, 6426, 6440, 6426, 6480, 6448, 6448, 6426, 6440, 6426, 6468, 6426, 6468, 6426, 6440, 6440, 6440, 6435, 6448, 6468, 6440, 6435, 6468, 6460, 6480, 6475, 6468, 6468, 6480, 6480, 6468, 6480, 6460, 6480, 6480, 6460, 6460, 6468, 6468, 6468, 6468, 6475, 6468, 6480, 6480, 6468, 6468, 6480, 6468, 6480, 6468, 6468, 6468, 6480, 6480, 6480, 6468, 6468, 6468, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6480, 6510, 6500, 6510, 6528, 6525, 6500, 6528, 6536, 6500, 6500, 6528, 6528, 6525, 6528, 6528, 6528, 6517, 6528, 6528, 6528, 6525, 6528, 6528, 6528, 6528, 6528, 6528, 6528, 6528, 6528, 6528, 6528, 6528, 6528, 6528, 6528, 6528, 6528, 6528, 6552, 6534, 6552, 6534, 6552, 6545, 6552, 6552, 6552, 6552, 6552, 6552, 6552, 6552, 6552, 6552, 6552, 6552, 6552, 6552, 6552, 6552, 6552, 6552, 6600, 6561, 6600, 6600, 6600, 6561, 6600, 6600, 6600, 6561, 6600, 6608, 6600, 6561, 6600, 6600, 6600, 6561, 6600, 6624, 6624, 6600, 6600, 6600, 6600, 6591, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6600, 6624, 6624, 6624, 6615, 6624, 6624, 6624, 6615, 6624, 6624, 6624, 6615, 6624, 6624, 6624, 6615, 6656, 6630, 6656, 6656, 6656, 6650, 6688, 6650, 6660, 6678, 6660, 6656, 6660, 6656, 6656, 6656, 6656, 6650, 6656, 6650, 6656, 6656, 6664, 6650, 6656, 6656, 6656, 6655, 6656, 6656, 6656, 6696, 6656, 6656, 6656, 6656, 6656, 6656, 6656, 6656, 6656, 6656, 6688, 6688, 6696, 6696, 6720, 6688, 6720, 6688, 6688, 6688, 6696, 6720, 6696, 6696, 6688, 6688, 6696, 6688, 6688, 6688, 6696, 6696, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6720, 6750, 6760, 6750, 6768, 6750, 6768, 6750, 6768, 6750, 6768, 6750, 6768, 6750, 6760, 6760, 6776, 6750, 6784, 6750, 6784, 6750, 6760, 6750, 6804, 6750, 6760, 6750, 6804, 6750, 6800, 6804, 6804, 6816, 6776, 6776, 6804, 6786, 6776, 6776, 6804, 6776, 6820, 6800, 6776, 6776, 6800, 6825, 6804, 6800, 6800, 6804, 6800, 6800, 6800, 6804, 6800, 6800, 6804, 6800, 6804, 6800, 6800, 6804, 6804, 6800, 6800, 6804, 6800, 6800, 6800, 6804, 6804, 6804, 6804, 6804, 6804, 6804, 6804, 6804, 6804, 6840, 6804, 6804, 6804, 6840, 6840, 6825, 6860, 6840, 6840, 6831, 6840, 6840, 6840, 6825, 6840, 6840, 6840, 6840, 6840, 6840, 6840, 6840, 6840, 6840, 6840, 6840, 6840, 6840, 6860, 6864, 6864, 6864, 6864, 6860, 6864, 6864, 6864, 6864, 6864, 6860, 6860, 6864, 6860, 6880, 6864, 6864, 6860, 6888, 6860, 6864, 6864, 6860, 6860, 6885, 7020, 6912, 6900, 6912, 6900, 6900, 6900, 6885, 6912, 6912, 6900, 6875, 6900, 6902, 6912, 6885, 6900, 6912, 6912, 6885, 6900, 6900, 6900, 6912, 6900, 6912, 6900, 6900, 6900, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6912, 6930, 6960, 6930, 6944, 6930, 6960, 6930, 7896, 6960, 6960, 6960, 6960, 6960, 6960, 6960, 6960, 6960, 6960, 6960, 6960, 6960, 6960, 6960, 6960, 6996, 7008, 6975, 6992, 7008, 6996, 6975, 6992, 7000, 7020, 6975, 7020, 7000, 7020, 6992, 7000, 7000, 7000, 6993, 7000, 7020, 6992, 6993, 6992, 6992, 6992, 7011, 7000, 7000, 7040, 7000, 7000, 7000, 7000, 7000, 7000, 7000, 7000, 7038, 7000, 7000, 7020, 7000, 7000, 7000, 7020, 7000, 7020, 7000, 7000, 7000, 7000, 7000, 7020, 7040, 7000, 7000, 7020, 7020, 7020, 7020, 7020, 7020, 7020, 7020, 7020, 7020, 7020, 7020, 7020, 7038, 7020, 7020, 7020, 7040, 7040, 7056, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7040, 7056, 7056, 7056, 7056, 7056, 7056, 7056, 7056, 7056, 7056, 7056, 7056, 7056, 7056, 7056, 7056, 7056, 7072, 7072, 7072, 7128, 7098, 7104, 7084, 7084, 7106, 7140, 7104, 7104, 7104, 7128, 7104, 7104, 7098, 7104, 7104, 7104, 7104, 7104, 7098, 7104, 7105, 7140, 7098, 7128, 7098, 7128, 7128, 7128, 7125, 7128, 7150, 7128, 7128, 7128, 7128, 7128, 7125, 7128, 7128, 7128, 7128, 7128, 7128, 7128, 7125, 7128, 7128, 7128, 7128, 7128, 7128, 7128, 7125, 7128, 7128, 7128, 7128, 7128, 7128, 7128, 7128, 7128, 7128, 7128, 7128, 7128, 7128, 7140, 7140, 7140, 7168, 7176, 7161, 7176, 7150, 7168, 7182, 7168, 7150, 7168, 7168, 7168, 7176, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7200, 7280, 7225, 7280, 7280, 7296, 7245, 7252, 7254, 7260, 7250, 7296, 7254, 7252, 7245, 7260, 7260, 7260, 7245, 7252, 7254, 7260, 7245, 7280, 7254, 7260, 7245, 7260, 7260, 7260, 7280, 7260, 7290, 7280, 7280, 7260, 7260, 7260, 7290, 7260, 7260, 7260, 7260, 7260, 7290, 7260, 7280, 7260, 7260, 7260, 7290, 7280, 7280, 7280, 7280, 7280, 7296, 7280, 7280, 7280, 7280, 7280, 7290, 7280, 7280, 7280, 7280, 7280, 7290, 7280, 7280, 7280, 7290, 7296, 7290, 7296, 7290, 7296, 7290, 7296, 7290, 7296, 7290, 7296, 7290, 7296, 7290, 7332, 7290, 7344, 7290, 7344, 7326, 7392, 7315, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7360, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7344, 7350, 7360, 7350, 7360, 7350, 7360, 7350, 7360, 7350, 7360, 7371, 7380, 7392, 7392, 7371, 7392, 7392, 7392, 7371, 7392, 7392, 7392, 7371, 7392, 7392, 7392, 7371, 7392, 7392, 7392, 7392, 7392, 7392, 7392, 7392, 7424, 7392, 7392, 7392, 7392, 7392, 7392, 7392, 7392, 7392, 7392, 7392, 7392, 7392, 7392, 7392, 7440, 7410, 7452, 7410, 7440, 7424, 7424, 7424, 7436, 7424, 7424, 7425, 7424, 7424, 7424, 7424, 7424, 7424, 7424, 7425, 7436, 7440, 7440, 7425, 7440, 7440, 7440, 7425, 7440, 7436, 7436, 7425, 7488, 7448, 7452, 7488, 7452, 7480, 7448, 7448, 7548, 7448, 7452, 7452, 7448, 7448, 7452, 7475, 7452, 7452, 7452, 7480, 7488, 7488, 7480, 7488, 7488, 7480, 7488, 7488, 7480, 7480, 7500, 7475, 7480, 7488, 7480, 7480, 7488, 7488, 7488, 7488, 7480, 7480, 7488, 7488, 7480, 7480, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7488, 7500, 7500, 7514, 7524, 7500, 7500, 7500, 7500, 7544, 7500, 7560, 7500, 7500, 7500, 7540, 7540, 7524, 7552, 7524, 7524, 7552, 7524, 7524, 7524, 7548, 7548, 7533, 7540, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7546, 7560, 7560, 7560, 7546, 7560, 7560, 7560, 7560, 7560, 7546, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7560, 7616, 7590, 7600, 7650, 7616, 7590, 7600, 7590, 7600, 7590, 7600, 7600, 7600, 7614, 7600, 7600, 7616, 7600, 7632, 7600, 7600, 7632, 7616, 7600, 7600, 7616, 7600, 7600, 7600, 7616, 7616, 7605, 7700, 7656, 7616, 7616, 7616, 7644, 7616, 7616, 7616, 7616, 7616, 7616, 7616, 7616, 7616, 7623, 7668, 7644, 7644, 7623, 7680, 7656, 7656, 7644, 7644, 7650, 7680, 7650, 7644, 7644, 7644, 7650, 7656, 7680, 7644, 7644, 7644, 7650, 7656, 7650, 7644, 7644, 7644, 7650, 7680, 7650, 7680, 7650, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7680, 7700, 7722, 7700, 7722, 7700, 7722, 7728, 7700, 7700, 7728, 7728, 7722, 7728, 7722, 7728, 7722, 7728, 7722, 7728, 7728, 7728, 7722, 7728, 7722, 7728, 7722, 7728, 7722, 7728, 7752, 7744, 7735, 7744, 7770, 7776, 7776, 7776, 7744, 7744, 7770, 7744, 7744, 7744, 7752, 7744, 7752, 7752, 7744, 7744, 7744, 7744, 7744, 7744, 7770, 7776, 7770, 7776, 7776, 7776, 7776, 7776, 7774, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7776, 7800, 7800, 7800, 7800, 7800, 7800, 7800, 7800, 7800, 7800, 7800, 7800, 7800, 7800, 7820, 7840, 7840, 7830, 7872, 7830, 7840, 7830, 7840, 7830, 7840, 7830, 7840, 7830, 7840, 7830, 7884, 7840, 7840, 7840, 7840, 7854, 7872, 7840, 7840, 7875, 7840, 7840, 7840, 7840, 7840, 7840, 7840, 7840, 7904, 7840, 7840, 7840, 7840, 7840, 7872, 7840, 7840, 7840, 7872, 7866, 7872, 7872, 7872, 7875, 7896, 7896, 7904, 7865, 7920, 7896, 7896, 7875, 7920, 7896, 7888, 7875, 7888, 7888, 7888, 7875, 7920, 7904, 7912, 7875, 7904, 7904, 7920, 7875, 7904, 7904, 7920, 7875, 7920, 7904, 7904, 7904, 7904, 7920, 7920, 7920, 7920, 7920, 7904, 7904, 7920, 7904, 7904, 7904, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7920, 7938, 7992, 7938, 7956, 7938, 7956, 7938, 7956, 7938, 7956, 7938, 7956, 7938, 7980, 7938, 7980, 7938, 7980, 7938, 7956, 7990, 7956, 7956, 7956, 7980, 7980, 7992, 7980, 7992, 7980, 7975, 7980, 8000, 7980, 7986, 7980, 7980, 7980, 7995, 7980, 7980, 7980, 7980, 7980, 7986, 7980, 7992, 7980, 7980, 7980, 8000, 8000, 7986, 8000, 7986, 8000, 8000, 8000, 8000, 8000, 8008, 8000, 8000, 8000, 8000, 8000, 8000, 8000, 8000, 8000, 8000, 8000, 8000, 8000, 8000, 8000, 8050, 8000, 8000, 8000, 8000, 8000, 8000, 8000, 8056, 8064, 8019, 8064, 8064, 8064, 8019, 8064, 8050, 8064, 8019, 8064, 8064, 8060, 8019, 8064, 8060, 8060, 8064, 8064, 8064, 8064, 8064, 8064, 8050, 8060, 8050, 8064, 8060, 8060, 8050, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8064, 8096, 8085, 8100, 8092, 8092, 8100, 8096, 8096, 8100, 8085, 8096, 8096, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8100, 8112, 8100, 8100, 8100, 8160, 8140, 8151, 8160, 8140, 8140, 8151, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8125, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8151, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8160, 8208, 8184, 8184, 8184, 8184, 8184, 8192, 8190, 8192, 8190, 8192, 8192, 8192, 8190, 8192, 8190, 8192, 8190, 8192, 8190, 8208, 8190, 8192, 8190, 8208, 8190, 8192, 8190, 8192, 8190, 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8208, 8250, 8320, 8250, 8232, 8232, 8260, 8250, 8232, 8228, 8228, 8232, 8280, 8232, 8256, 8232, 8232, 8232, 8256, 8250, 8256, 8232, 8232, 8232, 8256, 8232, 8232, 8232, 8232, 8232, 8272, 8262, 8272, 8250, 8280, 8250, 8280, 8250, 8280, 8262, 8280, 8250, 8280, 8250, 8280, 8250, 8316, 8262, 8316, 8262, 8280, 8262, 8280, 8262, 8280, 8262, 8280, 8280, 8280, 8280, 8280, 8280, 8280, 8280, 8280, 8280, 8280, 8280, 8316, 8316, 8316, 8316, 8320, 8316, 8316, 8320, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8316, 8320, 8316, 8316, 8316, 8316, 8316, 8320, 8316, 8316, 8316, 8316, 8316, 8320, 8316, 8316, 8316, 8320, 8320, 8320, 8320, 8320, 8424, 8352, 8352, 8352, 8352, 8352, 8352, 8349, 8352, 8352, 8352, 8352, 8352, 8352, 8352, 8352, 8352, 8352, 8400, 8370, 8372, 8370, 8360, 8360, 8400, 8370, 8360, 8360, 8400, 8370, 8400, 8370, 8372, 8400, 8400, 8379, 8400, 8398, 8400, 8400, 8400, 8398, 8400, 8379, 8400, 8400, 8400, 8379, 8400, 8400, 8400, 8400, 8400, 8398, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8400, 8415, 8424, 8424, 8424, 8424, 8448, 8424, 8424, 8424, 8424, 8448, 8424, 8424, 8424, 8424, 8424, 8424, 8424, 8424, 8424, 8424, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8448, 8470, 8496, 8528, 8512, 8470, 8500, 8470, 8512, 8505, 8500, 8470, 8520, 8500, 8532, 8510, 8512, 8505, 8532, 8510, 8544, 8505, 8500, 8526, 8512, 8500, 8500, 8514, 8512, 8500, 8512, 8512, 8512, 8505, 8500, 8512, 8512, 8505, 8500, 8540, 8528, 8500, 8500, 8512, 8512, 8505, 8512, 8512, 8512, 8505, 8512, 8512, 8512, 8505, 8512, 8526, 8568, 8505, 8568, 8568, 8568, 8550, 8568, 8550, 8576, 8547, 8568, 8568, 8580, 8550, 8556, 8550, 8556, 8550, 8576, 8550, 8568, 8568, 8568, 8550, 8568, 8550, 8568, 8550, 8580, 8568, 8580, 8550, 8568, 8550, 8568, 8550, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8568, 8580, 8580, 8580, 8580, 8580, 8610, 8580, 8600, 8580, 8575, 8580, 8610, 8624, 8602, 8640, 8610, 8640, 8610, 8624, 8640, 8624, 8624, 8624, 8624, 8640, 8613, 8624, 8624, 8640, 8613, 8640, 8640, 8640, 8624, 8640, 8640, 8624, 8619, 8624, 8624, 8640, 8624, 8624, 8640, 8624, 8624, 8624, 8624, 8624, 8625, 8640, 8624, 8624, 8640, 8624, 8640, 8624, 8624, 8624, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8640, 8694, 8704, 8670, 8700, 8670, 8680, 8670, 8680, 8680, 8700, 8694, 8680, 8680, 8700, 8694, 8712, 8704, 8700, 8694, 8700, 8694, 8712, 8694, 8700, 8694, 8704, 8700, 8700, 8694, 8700, 8694, 8700, 8694, 8700, 8694, 8700, 8704, 8704, 8704, 8704, 8712, 8704, 8704, 8704, 8745, 8704, 8704, 8704, 8704, 8704, 8704, 8704, 8704, 8704, 8704, 8712, 8712, 8712, 8712, 8712, 8712, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8736, 8748, 8748, 8748, 8778, 8748, 8748, 8748, 8748, 8748, 8748, 8748, 8748, 8748, 8748, 8748, 8748, 8748, 8775, 8748, 8748, 8748, 8775, 8816, 8778, 8800, 8775, 8788, 8778, 8800, 8775, 8800, 8820, 8800, 8775, 8800, 8800, 8816, 8775, 8788, 8800, 8820, 8800, 8800, 8816, 8800, 8800, 8800, 8800, 8800, 8800, 8800, 8800, 8800, 8800, 8800, 8800, 8800, 8800, 8820, 8800, 8800, 8800, 8820, 8800, 8800, 8800, 8820, 8820, 8820, 8820, 8820, 8820, 8820, 8820, 8820, 8832, 8820, 8820, 8820, 8820, 8820, 8820, 8820, 8832, 8820, 8820, 8820, 8832, 8832, 8832, 8856, 8856, 8840, 8840, 8856, 8856, 8880, 8874, 8928, 8880, 8880, 8855, 8880, 8880, 8880, 8925, 8892, 8880, 8880, 8874, 8880, 8874, 8880, 8874, 8880, 8880, 8880, 8880, 8880, 8880, 8880, 8880, 8880, 8904, 8892, 8904, 8892, 8904, 8892, 8904, 8892, 8910, 8892, 8910, 8928, 8910, 8928, 8892, 8928, 8892, 8892, 8928, 8892, 8892, 8892, 8910, 8928, 8910, 8928, 8910, 8964, 8910, 8928, 8910, 8928, 8910, 8964, 8910, 8928, 8910, 8960, 8910, 8928, 8910, 8928, 8910, 8928, 8910, 8928, 8910, 8928, 8910, 8928, 8910, 8928, 8910, 8928, 8928, 8960, 8960, 8960, 8925, 8960, 8960, 8960, 8954, 8976, 8960, 8960, 8970, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8960, 8976, 8976, 8991, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9072, 9044, 9044, 9048, 9044, 9072, 9072, 9048, 9048, 9048, 9072, 9061, 9072, 9072, 9044, 9072, 9072, 9048, 9048, 9044, 9044, 9048, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9065, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9072, 9100, 9100, 9114, 9108, 9100, 9100, 9120, 9100, 9108, 9100, 9108, 9100, 9114, 9100, 9108, 9108, 9100, 9100, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9120, 9152, 9126, 9240, 9126, 9180, 9180, 9152, 9180, 9152, 9152, 9152, 9152, 9180, 9180, 9176, 9152, 9152, 9152, 9152, 9152, 9152, 9152, 9152, 9180, 9152, 9177, 9180, 9152, 9152, 9152, 9152, 9152, 9152, 9163, 9180, 9184, 9180, 9177, 9180, 9180, 9180, 9184, 9180, 9180, 9180, 9180, 9180, 9180, 9180, 9180, 9180, 9180, 9180, 9180, 9180, 9180, 9180, 9200, 9180, 9180, 9180, 9200, 9216, 9196, 9196, 9200, 9200, 9216, 9216, 9200, 9200, 9216, 9200, 9200, 9200, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9216, 9234, 9240, 9234, 9240, 9240, 9240, 9240, 9240, 9240, 9240, 9240, 9240, 9240, 9280, 9261, 9280, 9288, 9300, 9261, 9360, 9288, 9288, 9261, 9288, 9280, 9280, 9280, 9280, 9280, 9288, 9261, 9280, 9288, 9280, 9261, 9280, 9280, 9280, 9280, 9280, 9282, 9324, 9282, 9300, 9324, 9328, 9300, 9300, 9300, 9300, 9315, 9300, 9360, 9300, 9295, 9300, 9338, 9328, 9315, 9324, 9324, 9324, 9344, 9324, 9360, 9324, 9310, 9324, 9310, 9324, 9315, 9324, 9310, 9324, 9315, 9360, 9348, 9360, 9315, 9360, 9350, 9348, 9348, 9348, 9360, 9360, 9350, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9350, 9360, 9360, 9360, 9360, 9360, 9350, 9360, 9360, 9360, 9360, 9360, 9350, 9360, 9360, 9360, 9350, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9360, 9375, 9384, 9384, 9384, 9384, 9396, 9400, 9396, 9375, 9396, 9396, 9408, 9396, 9396, 9396, 9396, 9375, 9396, 9408, 9396, 9396, 9396, 9408, 9408, 9405, 9408, 9408, 9408, 9405, 9408, 9408, 9408, 9405, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9408, 9450, 9472, 9438, 9460, 9438, 9464, 9450, 9500, 9450, 9460, 9450, 9464, 9438, 9460, 9438, 9504, 9450, 9472, 9450, 9504, 9450, 9500, 9450, 9464, 9450, 9540, 9450, 9472, 9450, 9464, 9450, 9472, 9450, 9472, 9450, 9464, 9450, 9472, 9450, 9472, 9450, 9464, 9464, 9504, 9477, 9500, 9486, 9504, 9504, 9504, 9500, 9504, 9477, 9504, 9504, 9504, 9477, 9500, 9504, 9500, 9477, 9500, 9500, 9500, 9477, 9504, 9500, 9504, 9504, 9504, 9504, 9500, 9504, 9504, 9504, 9500, 9504, 9504, 9500, 9500, 9504, 9504, 9504, 9504, 9504, 9504, 9504, 9504, 9504, 9504, 9504, 9504, 9504, 9504, 9504, 9520, 9520, 9520, 9558, 9520, 9520, 9520, 9558, 9568, 9537, 9548, 9568, 9568, 9570, 9576, 9548, 9548, 9555, 9576, 9568, 9576, 9568, 9568, 9568, 9576, 9576, 9576, 9576, 9576, 9555, 9576, 9568, 9568, 9555, 9568, 9576, 9576, 9570, 9576, 9570, 9568, 9555, 9576, 9568, 9568, 9568, 9576, 9576, 9576, 9576, 9576, 9576, 9576, 9576, 9576, 9576, 9576, 9576, 9576, 9576, 9576, 9576, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9600, 9696, 9657, 9660, 9696, 9660, 9633, 9660, 9702, 9660, 9639, 9660, 9672, 9660, 9625, 9660, 9660, 9660, 9639, 9660, 9702, 9720, 9639, 9672, 9672, 9660, 9639, 9660, 9660, 9660, 9672, 9660, 9660, 9660, 9660, 9660, 9680, 9660, 9672, 9660, 9660, 9660, 9672, 9720, 9690, 9680, 9680, 9720, 9680, 9680, 9690, 9728, 9702, 9720, 9680, 9680, 9680, 9720, 9680, 9680, 9702, 9680, 9690, 9720, 9680, 9680, 9690, 9680, 9680, 9680, 9702, 9720, 9702, 9720, 9702, 9720, 9720, 9720, 9702, 9720, 9702, 9720, 9702, 9720, 9720, 9720, 9702, 9720, 9702, 9720, 9702, 9720, 9702, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9720, 9744, 9747, 9768, 9750, 9792, 9765, 9768, 9750, 9776, 9765, 9768, 9750, 9768, 9765, 9792, 9750, 9792, 9750, 9792, 9750, 9792, 9792, 9792, 9792, 9792, 9775, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9792, 9800, 9828, 9800, 9800, 9800, 9800, 9800, 9828, 9840, 9800, 9800, 9828, 9828, 9828, 9828, 9828, 9828, 9828, 9828, 9828, 9840, 9828, 9828, 9828, 9828, 9828, 9856, 9828, 9828, 9828, 9828, 9828, 9870, 9828, 9828, 9828, 9856, 9856, 9870, 9856, 9856, 9900, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9856, 9900, 9900, 9900, 9900, 9880, 9880, 9900, 9900, 9880, 9880, 9900, 9900, 9900, 9900, 9900, 9900, 9900, 9922, 9900, 9900, 9900, 9900, 9900, 9936, 9900, 9900, 9900, 9900, 9900, 9900, 9900, 9918, 9900, 9900, 9900, 9900, 9900, 9900, 9900, 9933, 9900, 9900, 9900, 9920, 9920, 9920, 9920, 9936, 9936, 9936, 9936, 9936, 9936, 9990, 9936, 9936, 9936, 9936, 9936, 9936, 9936, 9936, 9936, 9936, 9936, 9936, 9936, 9936, 9936, 9936, 9936, 9945, 9984, 9984, 9984, 9945, 9984, 9984, 9984, 9963, 9984, 9996, 9984, 9975, 9984, 9984, 9984, 9984, 9984, 9982, 9984, 9975, 9984, 9984, 9984, 9975, 9984, 9984, 9984, 9975, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9975, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9984, 9996, 9996, 10010, 10000, 10000, 10000, 10000, 10032, 10000, 10000, 10010, 10032, 10000, 10000, 10010, 10000, 10000, 10000, 10032, 10044, 10044, 10032, 10032, 10032, 10032, 10032, 10045, 10032, 10032, 10032, 10044, 10032, 10032, 10032, 10032, 10032, 10044, 10044, 10062, 10044, 10044, 10044, 10080, 10064, 10064, 10064, 10075, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10075, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10080, 10164, 10098, 10108, 10098, 10152, 10120, 10120, 10125, 10120, 10120, 10140, 10115, 10140, 10152, 10120, 10120, 10152, 10150, 10120, 10120, 10164, 10140, 10140, 10125, 10140, 10292, 10140, 10125, 10152, 10150, 10140, 10125, 10140, 10140, 10140, 10125, 10164, 10140, 10140, 10125, 10140, 10150, 10140, 10125, 10140, 10140, 10140, 10176, 10176, 10176, 10164, 10164, 10164, 10164, 10176, 10192, 10164, 10200, 10200, 10164, 10164, 10200, 10164, 10206, 10164, 10164, 10164, 10179, 10200, 10200, 10164, 10164, 10164, 10200, 10200, 10200, 10200, 10192, 10192, 10206, 10200, 10200, 10192, 10192, 10192, 10200, 10192, 10200, 10200, 10192, 10192, 10192, 10192, 10200, 10200, 10192, 10192, 10200, 10192, 10200, 10192, 10192, 10192, 10200, 10200, 10200, 10200, 10200, 10200, 10200, 10260, 10206, 10248, 10206, 10248, 10206, 10240, 10206, 10240, 10206, 10240, 10206, 10240, 10206, 10240, 10206, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10240, 10260, 10290, 10260, 10260, 10260, 10296, 10296, 10290, 10296, 10290, 10296, 10304, 10296, 10290, 10296, 10290, 10296, 10290, 10296, 10285, 10296, 10290, 10296, 10290, 10296, 10290, 10296, 10290, 10296, 10296, 10296, 10290, 10296, 10290, 10296, 10290, 10296, 10290, 10296, 10290, 10296, 10296, 10304, 10304, 10304, 10336, 10332, 10332, 10332, 10332, 10332, 10336, 10332, 10332, 10332, 10336, 10368, 10360, 10368, 10350, 10336, 10350, 10360, 10350, 10368, 10368, 10336, 10336, 10368, 10336, 10336, 10336, 10360, 10350, 10368, 10353, 10368, 10350, 10360, 10350, 10360, 10350, 10368, 10368, 10360, 10350, 10368, 10350, 10368, 10350, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10368, 10400, 10400, 10416, 10395, 10400, 10400, 10400, 10395, 10400, 10400, 10400, 10395, 10400, 10400, 10416, 10395, 10400, 10400, 10416, 10400, 10400, 10400, 10440, 10440, 10440, 10440, 10488, 10488, 10472, 10440, 10440, 10440, 10440, 10450, 10440, 10440, 10440, 10440, 10440, 10440, 10440, 10440, 10440, 10440, 10440, 10440, 10440, 10440, 10472, 10450, 10496, 10469, 10472, 10488, 10472, 10450, 10500, 10472, 10500, 10450, 10488, 10472, 10500, 10494, 10472, 10488, 10472, 10465, 10496, 10478, 10488, 10488, 10472, 10472, 10500, 10512, 10472, 10472, 10500, 10472, 10500, 10496, 10472, 10472, 10500, 10488, 10488, 10488, 10488, 10488, 10496, 10496, 10496, 10496, 10496, 10500, 10500, 10500, 10500, 10500, 10500, 10500, 10500, 10500, 10500, 10500, 10500, 10500, 10500, 10528, 10500, 10500, 10500, 10528, 10500, 10500, 10500, 10500, 10500, 10530, 10500, 10530, 10500, 10500, 10500, 10530, 10556, 10530, 10560, 10530, 10540, 10530, 10560, 10540, 10540, 10530, 10556, 10530, 10560, 10530, 10560, 10530, 10556, 10530, 10560, 10530, 10560, 10530, 10556, 10530, 10560, 10530, 10560, 10556, 10556, 10557, 10560, 10560, 10560, 10557, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10560, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10584, 10656, 10626, 10608, 10608, 10608, 10650, 10608, 10608, 10608, 10608, 10608, 10626, 10640, 10625, 10656, 10626, 10640, 10656, 10640, 10626, 10640, 10626, 10640, 10710, 10640, 10640, 10640, 10656, 10656, 10625, 10640, 10640, 10656, 10640, 10640, 10656, 10640, 10640, 10640, 10640, 10640, 10648, 10640, 10640, 10640, 10647, 10656, 10648, 10692, 10647, 10648, 10648, 10672, 10672, 10672, 10692, 10692, 10692, 10692, 10692, 10692, 10693, 10692, 10710, 10692, 10692, 10692, 10692, 10720, 10710, 10692, 10692, 10692, 10692, 10692, 10692, 10692, 10692, 10692, 10692, 10692, 10692, 10692, 10710, 10692, 10692, 10692, 10710, 10692, 10710, 10692, 10692, 10692, 10710, 10692, 10692, 10692, 10692, 10692, 10692, 10692, 10692, 10692, 10710, 10692, 10692, 10692, 10710, 10752, 10710, 10752, 10710, 10752, 10710, 10752, 10710, 10752, 10752, 10752, 10752, 10752, 10725, 10752, 10752, 10752, 10752, 10752, 10750, 10752, 10725, 10752, 10750, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10752, 10780, 10773, 10780, 10780, 10780, 10773, 10780, 10800, 10800, 10800, 10780, 10800, 10780, 10800, 10800, 10780, 10780, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10800, 10816, 10816, 10816, 10816, 10830, 10880, 10829, 10880, 10846, 10880, 10857, 10908, 10868, 10868, 10902, 10868, 10850, 10880, 10850, 10880, 10880, 10868, 10850, 10912, 10880, 10868, 10875, 10880, 10880, 10920, 10880, 10868, 10878, 10868, 10875, 10920, 10880, 10880, 10878, 10880, 10880, 10880, 10868, 10868, 10878, 10880, 10880, 10920, 10880, 10880, 10875, 10880, 10880, 10880, 10880, 10880, 10880, 10880, 10880, 10880, 10890, 10880, 10880, 10880, 10880, 10880, 10880, 10880, 10880, 10880, 10880, 10920, 10912, 10912, 10890, 10944, 10890, 10920, 10890, 10912, 10912, 10920, 10912, 10912, 10912, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10920, 10944, 10944, 10944, 10935, 10944, 10944, 10944, 10935, 10944, 10944, 10944, 10935, 10944, 10944, 10944, 10935, 10944, 10944, 10944, 10935, 10944, 10944, 10944, 10935, 11000, 10962, 11016, 10962, 10976, 10998, 11000, 11000, 11016, 10976, 10976, 11025, 10976, 10982, 11008, 10976, 10976, 10976, 10976, 10976, 11016, 11016, 10976, 10976, 10976, 10976, 11000, 10976, 10976, 10976, 10976, 10976, 11008, 10976, 10976, 10976, 11000, 11000, 11008, 11000, 11000, 11000, 11016, 11000, 11000, 11000, 11000, 11000, 11016, 11000, 11016, 11016, 11000, 11000, 11016, 11011, 11000, 11000, 11016, 11016, 11016, 11040, 11016, 11016, 11016, 11016, 11016, 11016, 11016, 11016, 11016, 11016, 11040, 11040, 11040, 11025, 11040, 11040, 11040, 11025, 11040, 11040, 11040, 11025, 11040, 11040, 11040, 11040, 11040, 11040, 11088, 11050, 11088, 11070, 11088, 11050, 11088, 11070, 11088, 11070, 11088, 11070, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11088, 11130, 11132, 11136, 11132, 11115, 11136, 11136, 11136, 11115, 11160, 11152, 11152, 11115, 11132, 11136, 11136, 11136, 11160, 11154, 11136, 11136, 11136, 11132, 11132, 11136, 11136, 11136, 11136, 11136, 11136, 11136, 11136, 11136, 11136, 11136, 11172, 11160, 11160, 11160, 11160, 11154, 11160, 11154, 11160, 11160, 11160, 11160, 11160, 11160, 11160, 11154, 11160, 11154, 11160, 11160, 11172, 11178, 11200, 11178, 11200, 11172, 11172, 11232, 11220, 11178, 11172, 11172, 11172, 11178, 11200, 11178, 11172, 11172, 11172, 11178, 11200, 11178, 11200, 11178, 11200, 11178, 11220, 11200, 11200, 11223, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11200, 11232, 11220, 11232, 11220, 11220, 11220, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11232, 11264, 11250, 11264, 11250, 11264, 11280, 11264, 11250, 11264, 11250, 11280, 11250, 11264, 11264, 11280, 11250, 11264, 11250, 11264, 11250, 11264, 11264, 11264, 11264, 11264, 11264, 11264, 11264, 11264, 11264, 11264, 11264, 11264, 11264, 11264, 11286, 11340, 11286, 11316, 11286, 11316, 11286, 11340, 11319, 11328, 11310, 11328, 11328, 11328, 11310, 11328, 11305, 11328, 11310, 11340, 11322, 11340, 11340, 11340, 11319, 11340, 11340, 11340, 11339, 11340, 11340, 11340, 11319, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11319, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11340, 11385, 11340, 11340, 11340, 11368, 11400, 11396, 11368, 11368, 11396, 11400, 11400, 11375, 11400, 11424, 11396, 11400, 11400, 11400, 11396, 11385, 11400, 11400, 11424, 11385, 11396, 11400, 11400, 11375, 11400, 11400, 11400, 11400, 11400, 11400, 11400, 11400, 11400, 11424, 11400, 11400, 11400, 11400, 11400, 11400, 11400, 11400, 11400, 11400, 11400, 11400, 11400, 11400, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11448, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11424, 11440, 11440, 11440, 11440, 11440, 11466, 11440, 11480, 11480, 11440, 11440, 11466, 11440, 11440, 11440, 11466, 11484, 11466, 11480, 11502, 11520, 11480, 11484, 11466, 11480, 11466, 11480, 11466, 11500, 11466, 11480, 11466, 11484, 11475, 11484, 11466, 11520, 11466, 11492, 11466, 11484, 11466, 11484, 11484, 11484, 11475, 11500, 11520, 11500, 11475, 11520, 11500, 11500, 11492, 11492, 11500, 11520, 11495, 11520, 11520, 11500, 11520, 11520, 11520, 11500, 11520, 11520, 11500, 11500, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11520, 11550, 11552, 11550, 11560, 11550, 11552, 11550, 11592, 11550, 11616, 11550, 11560, 11550, 11592, 11550, 11560, 11550, 11592, 11550, 11592, 11583, 11592, 11592, 11592, 11583, 11592, 11592, 11600, 11583, 11592, 11592, 11592, 11594, 11592, 11592, 11600, 11592, 11592, 11592, 11592, 11583, 11592, 11592, 11592, 11583, 11592, 11592, 11592, 11583, 11592, 11592, 11592, 11592, 11600, 11600, 11600, 11616, 11616, 11616, 11616, 11616, 11616, 11616, 11616, 11616, 11616, 11616, 11616, 11616, 11664, 11616, 11616, 11616, 11616, 11616, 11648, 11616, 11616, 11616, 11616, 11616, 11616, 11616, 11616, 11616, 11648, 11648, 11648, 11648, 11648, 11664, 11648, 11648, 11664, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11648, 11664, 11664, 11664, 11662, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11664, 11700, 11700, 11700, 11700, 11700, 11700, 11718, 11700, 11700, 11700, 11700, 11700, 11700, 11700, 11704, 11700, 11700, 11700, 11700, 11700, 11700, 11700, 11718, 11700, 11700, 11700, 11718, 11760, 11730, 11760, 11760, 11760, 11730, 11760, 11730, 11760, 11730, 11760, 11750, 11760, 11760, 11760, 11750, 11760, 11745, 11760, 11760, 11760, 11745, 11760, 11760, 11760, 11745, 11760, 11760, 11760, 11745, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11760, 11776, 11776, 11776, 11776, 11776, 11776, 11776, 11808, 11808, 11808, 11799, 11808, 11808, 11808, 11799, 11808, 11808, 11808, 11808, 11808, 11808, 11832, 11840, 11840, 11844, 11840, 11825, 11832, 11832, 11840, 11875, 11840, 11830, 11844, 11844, 11844, 11880, 11832, 11840, 11844, 11832, 11832, 11832, 11832, 11830, 11844, 11840, 11840, 12000, 11840, 11830, 11840, 11830, 11840, 11840, 11840, 11830, 11856, 11880, 11856, 11856, 11856, 11856, 11856, 11872, 11856, 11856, 11856, 11856, 11856, 11856, 11880, 11880, 11856, 11856, 11856, 11858, 11856, 11856, 11856, 11856, 11856, 11880, 11880, 11880, 11880, 11858, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11875, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11880, 11900, 11904, 11900, 11904, 11900, 11904, 11900, 11904, 11984, 11900, 11900, 11907, 11956, 11934, 12096, 11907, 12000, 11934, 11956, 11907, 11960, 11934, 12000, 11907, 11956, 11934, 11960, 11907, 11968, 11934, 11968, 11968, 11988, 11970, 12000, 11934, 11960, 11934, 11960, 11934, 11988, 11934, 11968, 11968, 11988, 11960, 11968, 11968, 11960, 11960, 11968, 11968, 11968, 11970, 12000, 11970, 11960, 11960, 11968, 11970, 11960, 11960, 11968, 11968, 11968, 11970, 11968, 11968, 11968, 11970, 11968, 11970, 11988, 11968, 11968, 11968, 11968, 11968, 11968, 11970, 11988, 12000, 11988, 11979, 11988, 12000, 12200, 11979, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12060, 12060, 12040, 12040, 12096, 12054, 12096, 12064, 12064, 12064, 12084, 12054, 12096, 12096, 12064, 12054, 12096, 12054, 12096]
def productsum(n):
return sum(set(arr[:n-1]))
| Product-Sum Numbers | 5b16bbd2c8c47ec58300016e | [
"Mathematics",
"Algorithms"
]
| https://www.codewars.com/kata/5b16bbd2c8c47ec58300016e | 4 kyu |
In this Kata, you will be given an integer `n` and your task will be to return `the largest integer that is <= n and has the highest digit sum`.
For example:
```
solve(100) = 99. Digit Sum for 99 = 9 + 9 = 18. No other number <= 100 has a higher digit sum.
solve(10) = 9
solve(48) = 48. Note that 39 is also an option, but 48 is larger.
```
Input range is `0 < n < 1e11`
More examples in the test cases.
Good luck! | algorithms | def solve(n):
x = str(n)
res = [x] + [str(int(x[: i]) - 1) + '9' * (len(x) - i)
for i in range(1, len(x))]
return int(max(res, key=lambda x: (sum(map(int, x)), int(x))))
| Simple max digit sum | 5b162ed4c8c47ea2f5000023 | [
"Algorithms"
]
| https://www.codewars.com/kata/5b162ed4c8c47ea2f5000023 | 6 kyu |
We have a set of consecutive numbers from ```1``` to ```n```.
We want to count all the subsets that do not contain consecutive numbers.
E.g.
If our set ```S1``` is equal to ```[1,2,3,4,5]```
The subsets that fulfill these property are:
```
[1],[2],[3],[4],[5],[1,3],[1,4],[1,5],[2,4],[2,5],[3,5],[1,3,5]
```
A total of ```12 ``` subsets.
From the set ```S2``` equals to```[1,2,3]```, it is obvious that we have only ```4``` subsets and are:
```
[1],[2],[3],[1,3]
```
Make a code that may give the amount of all these subsets for any integer ```n >= 2 ```.
Features of the random tests:
```
number of tests = 100
10 <= n <= 120
``` | reference | def f(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b + 1
return a
| # Counting 1: I Want Some Subsets, Not All! | 591392af88a4994caa0000e0 | [
"Number Theory",
"Fundamentals"
]
| https://www.codewars.com/kata/591392af88a4994caa0000e0 | 6 kyu |
### Task:
Your job is to take a pair of parametric equations, passed in as strings, and convert them into a single rectangular equation by eliminating the parameter. Both parametric halves will represent linear equations of x as a function of time and y as a function of time respectively.
The format of the final equation must be `Ax + By = C` or `Ax - By = C` where A and B must be positive and A, B, and C are integers. The final equation also needs to have the lowest possible whole coefficients. Omit coefficients equal to one.
The method is called `para_to_rect` or `EquationsManager.paraToRect` and takes in two strings in the form `x = at +(or -) b` and `y = ct +(or -) d` respectively, where `a` and `c` must be integers, and `b` and `d` must be positive integers. If `a` or `c` is omitted, the coefficient of _t_ is obviously assumed to be 1 (see final case in the example tests). There will NEVER be double signs in the equations inputted (For example: `"x = -12t + -18"` and `"y = -12t - -18"` won't show up.)
### Example 1
"x = 12t + 18", "y = 8t + 7" => "2x - 3y = 15"
CALCULATION:
x = 12t + 18
y = 8t + 7
2x = 24t + 36
3y = 24t + 21
2x - 3y = (24t + 36) - (24t + 21)
2x - 3y = 15
### Example 2
"x = -12t - 18", "y = 8t + 7" => "2x + 3y = -15"
CALCULATION:
x = -12t - 18
y = 8t + 7
2x = -24t - 36
3y = 24t + 21
2x + 3y = (-24t - 36) + (24t + 21)
2x + 3y = -15
### Example 3
"x = -t + 12", "y = 12t - 1" => "12x + y = 143"
CALCULATION:
x = -t + 12
y = 12t - 1
12x = -12t + 144
y = 12t - 1
12x + y = 143
### Note
As you can see above, sometimes you'll need to add the two parametric equations after multiplying by the necessary values; sometimes you'll need to subtract them – just get rid of the _t_! | reference | from math import gcd
def para_to_rect(eqn1, eqn2):
a, b = eqn1 . split('= ')[1]. split('t ')
c, d = eqn2 . split('= ')[1]. split('t ')
if a in ("", "-"):
a += '1'
if c in ("", "-"):
c += '1'
a, b, c, d = map(eval, (a, b, c, d))
x = gcd(a, c)
e, f = c / / x, - a / / x
if e < 0:
e, f = - e, - f
return f" { e if e > 1 else '' } x { '+-' [ f < 0 ]} { abs ( f ) if abs ( f ) > 1 else '' } y = { e * b + f * d } "
| Parametric to Rectangular Equation | 5b13530f828fab68820000c4 | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b13530f828fab68820000c4 | 6 kyu |
# Challenge :
Write a function that takes a single argument `n` that is a string representation of a simple mathematical expression and evaluates it as a floating point value.
# Commands :
- positive or negative decimal numbers
- `+, -, *, /, ( / ).`
---
Expressions use [infix notation](https://en.wikipedia.org/wiki/Infix_notation).
# Evaluation :
Operators should be evaluated in the order they appear and not as in `BODMAS`, though brackets __should__ be correctly observed.
The function should return the correct result for any possible expression of this form.
# Note :
- All given input will be valid.
- It will consist entirely of numbers or one of the operators.
- Parentheses will alway be matched.
- Use of `eval` or its equivalent is forbidden
- use of `exec` is forbidden (Python)
- Use of `Function` or any of their (Function, eval) equivalent is also forbidden.
- Using `require` is also forbidden. (`import` for python)
- Using more than 7 (8 for python) lines is also forbidden.
- Using more than 260 (JS) / 240 (python) characters is also forbidden.
- Having more than 100 chars per line is forbidden.
- Having more than 6 semi-colons is forbidden
and that is about it.
---
# Examples :
e("2*3*4*5+99") ---> 219
e("2*3*4*5+99*321-12312312") ---> -12242013
e("1-2*2/2*2-1*7+3") ---> -18
---
| games | def e(s, i=0):
l, o, r, i = 0, 0, '', i or iter(s + ' ')
for x in i:
if '(' == x:
r = e(s, i)
elif '/' < x or not r:
r += x
else:
r = float(r)
l, o, r = {'+': l + r, '-': l - r,
'*': l * r, '/': l / r, 0: r}[o], x, ''
if ')' == x:
break
return l
| Math expression [HARD][CODE-GOLF] | 5b05a8dd91cc5739df0000aa | [
"Puzzles",
"Restricted"
]
| https://www.codewars.com/kata/5b05a8dd91cc5739df0000aa | 5 kyu |
A group of students of Computer Science were studying the performance of the following generator in Python 2 and Python 3.
``` python
def permut(iterable):
if len(iterable) <=1: yield iterable
else:
for perm in permut(iterable[1:]):
for i in range(len(iterable)):
yield perm[:i] + iterable[0:1] + perm[i:]
```
As you can see, the code above may generate in a "lazy" way, all the permutations for a string or an array(iterable input).
In order to estimate how the runtime goes up when the length of the iterable increases, they introduced a counter as it follows below.
``` python
counter = 0
def permut(iterable):
global counter
if len(iterable) <=1: yield iterable
else:
for perm in permut(iterable[1:]):
for i in range(len(iterable)):
counter += 1
yield perm[:i] + iterable[0:1] + perm[i:]
```
For the string ```abc``` they got ```6``` different permutations, as expected, but the counter went up to ```8 ```.
They also tried the code in a super computer for the array = ```[1,2,3,4,5,6,7,8,9,10,11,12,13]``` and the counter value for the run reached up to ```6749977112```.
Could you create a code that can predict the value of the counter for different entries?
Random tests will include arrays or strings of length up to 200. | reference | from itertools import accumulate
from operator import mul
def fa(iterable):
return sum(accumulate(range(2, sum(1 for _ in iterable) + 1), mul))
| Avoid trillion years of calculations !! | 5b1027fe5b07a105f4000092 | [
"Performance",
"Algorithms",
"Mathematics",
"Machine Learning"
]
| https://www.codewars.com/kata/5b1027fe5b07a105f4000092 | 6 kyu |
I assume most of you are familiar with the ancient legend of the rice (but I see wikipedia suggests [wheat](https://en.wikipedia.org/wiki/Wheat_and_chessboard_problem), for some reason) problem, but a quick recap for you: a young man asks as a compensation only `1` grain of rice for the first square, `2` grains for the second, `4` for the third, `8` for the fourth and so on, always doubling the previous.
Your task is pretty straightforward (but not necessarily easy): given an amount of grains, you need to return up to which square of the chessboard one should count in order to get at least as many.
As usual, a few examples might be way better than thousands of words from me:
```
0 grains need 0 cells
1 grain needs 1 cell
2 grains need 2 cells
3 grains need 2 cells
4 grains need 3 cells
and etc.
```
Input is always going to be valid/reasonable: ie: a non negative number; extra cookie for *not* using a loop to compute square-by-square (at least not directly) and instead trying a smarter approach [hint: some peculiar operator]; a trick converting the number might also work: impress me!
| games | squares_needed = int . bit_length
| The wheat/rice and chessboard problem | 5b0d67c1cb35dfa10b0022c7 | [
"Mathematics",
"Recursion",
"Puzzles"
]
| https://www.codewars.com/kata/5b0d67c1cb35dfa10b0022c7 | 7 kyu |
Professor Chambouliard has just completed an experiment on gravitational waves.
He measures their effects on small magnetic particles. This effect is very small and negative. In his first experiment the effect satisfies the equation:
`x**2 + 1e9 * x + 1 = 0`.
Professor C. knows how to solve equations of the form:
`g(x) = a x ** 2 + b x + c = 0 (1)`
using the "discriminant".
It finds that the roots of `x**2 + 1e9 * x + 1 = 0` are `x1 = -1e9` and `x2 = 0`. The value of `x1` - good or bad - does not interest him because its absolute value is too big.
On the other hand, he sees immediately that the value of `x2` is not suitable!
He asks our help to solve equations of type (1)
with `a, b, c strictly positive numbers`, and `b being large (b >= 10 ** 9)`.
Professor C. will check your result `x2` (the smaller root in absolute value. Don't return the other root!) by reporting `x2` in (1)
and seeing if `abs(g(x2)) < 1e-12`.
#### Task:
`solve(a, b, c)`
that will return the "solution" `x2` of (1) such as `abs(a * x2 ** 2 + b * x2 + c) < 1e-12`.
#### Example:
for equation `7*x**2 + 0.40E+14 * x + 8 = 0` we can find: `x2 = -2e-13`
which verifies `abs(g(x)) < 1e-12`.
| reference | def quadratic(a, b, c):
return - c / b
| Floating-point Approximation (III) | 5b0c0ec907756ffcff00006e | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b0c0ec907756ffcff00006e | 7 kyu |
The code provided has a method `hello` which is supposed to show only those attributes which have been *explicitly* set. Furthermore, it is supposed to say them in the *same order* they were set.
But it's not working properly.
# Notes
There are 3 attributes
* name
* age
* sex ('M' or 'F')
When the same attribute is assigned multiple times the `hello` method shows it only once. If this happens the *order* depends on the **first** assignment of that attribute, but the *value* is from the **last** assignment.
# Examples
* `Hello.`
* `Hello. My name is Bob. I am 27. I am male.`
* `Hello. I am 27. I am male. My name is Bob.`
* `Hello. My name is Alice. I am female.`
* `Hello. My name is Batman.`
# Task
Fix the code so we can all go home early.
| bug_fixes | class Dinglemouse (object):
def __init__(self):
self . name = None
self . sex = None
self . age = None
self . hell = 'Hello.'
def setAge(self, age):
if self . age == None:
self . hell = self . hell + ' I am {age}.'
self . age = age
return self
def setSex(self, sex):
if self . sex == None:
self . hell = self . hell + ' I am {sex}.'
self . sex = "male" if sex == 'M' else "female"
return self
def setName(self, name):
if self . name == None:
self . hell = self . hell + ' My name is {name}.'
self . name = name
return self
def hello(self):
return self . hell . format(age=self . age, sex=self . sex, name=self . name)
| FIXME: Hello | 5b0a80ce84a30f4762000069 | [
"Debugging"
]
| https://www.codewars.com/kata/5b0a80ce84a30f4762000069 | 6 kyu |
Alice and Bob have participated to a Rock Off with their bands. A jury of true metalheads rates the two challenges, awarding points to the bands on a scale from 1 to 50 for three categories: Song Heaviness, Originality, and Members' outfits.
For each one of these 3 categories they are going to be awarded one point, should they get a better judgement from the jury. No point is awarded in case of an equal vote.
You are going to receive two arrays, containing first the score of Alice's band and then those of Bob's. Your task is to find their total score by comparing them in a single line.
Example:
Alice's band plays a Nirvana inspired grunge and has been rated
``20`` for Heaviness,
``32`` for Originality and only
``18`` for Outfits.
Bob listens to Slayer and has gotten a good
``48`` for Heaviness,
``25`` for Originality and a rather honest
``40`` for Outfits.
The total score should be followed by a colon ```:``` and by one of the following quotes:
if Alice's band wins: ```Alice made "Kurt" proud!```
if Bob's band wins: ```Bob made "Jeff" proud!```
if they end up with a draw: ```that looks like a "draw"! Rock on!```
The solution to the example above should therefore appear like
``'1, 2: Bob made "Jeff" proud!'``. | reference | def solve(a, b):
alice = sum(i > j for i, j in zip(a, b))
bob = sum(j > i for i, j in zip(a, b))
if alice == bob:
words = 'that looks like a "draw"! Rock on!'
elif alice > bob:
words = 'Alice made "Kurt" proud!'
else:
words = 'Bob made "Jeff" proud!'
return '{}, {}: {}' . format(alice, bob, words)
| Rock Off! | 5b097da6c3323ac067000036 | [
"Arrays",
"Fundamentals"
]
| https://www.codewars.com/kata/5b097da6c3323ac067000036 | 7 kyu |
The [Floyd's triangle](https://en.wikipedia.org/wiki/Floyd%27s_triangle) is a right-angled triangular array of natural numbers listing them in order, in lines of increasing length, so a Floyds triangle of size 6 looks like:
```
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
...
```
In this kata you're given a number, and expected to return the line number it falls in, in the Floyd's triangle
### Examples (input -> output)
```
3 -> 2 (i.e the number `3` falls in line 2 of the triangle)
17 -> 6
22 -> 7
499502 -> 1000
```
## Constraints
### 1 <= n <= 10<sup>9</sup>
| reference | def nth_floyd(n):
return ((1 + 8 * (n - 1)) * * 0.5 + 1) / / 2
| nth Floyd line | 5b096efeaf15bef812000010 | [
"Mathematics",
"Puzzles",
"Fundamentals"
]
| https://www.codewars.com/kata/5b096efeaf15bef812000010 | 7 kyu |
The T9 typing predictor helps with suggestions for possible word combinations on an old-style numeric keypad phone. Each digit in the keypad (2-9) represents a group of 3-4 letters. To type a letter, press once the key which corresponds to the letter group that contains the required letter. Typing words is done by typing letters of the word in sequence.
The letter groups and corresponding digits are as follows:
```
-----------------
| 1 | 2 | 3 |
| | ABC | DEF |
|-----|-----|-----|
| 4 | 5 | 6 |
| GHI | JKL | MNO |
|-----|-----|-----|
| 7 | 8 | 9 |
| PQRS| TUV | WXYZ|
-----------------
```
The prediction algorithm tries to match the input sequence against a predefined dictionary of words. The combinations which appear in the dictionary are considered valid words and are shown as suggestions.
Given a list of words as a reference dictionary, and a non-empty string (of digits 2-9) as input, complete the function which returns suggestions based on the string of digits, which are found in the reference dictionary.
For example:
```python
T9(['hello', 'world'], '43556') returns ['hello']
T9(['good', 'home', 'new'], '4663') returns ['good', 'home']
```
Note that the dictionary must be case-insensitive (`'hello'` and `'Hello'` are same entries). The list returned must contain the word as it appears in the dictionary (along with the case).
Example:
```python
T9(['Hello', 'world'], '43556') returns ['Hello']
```
If there is no prediction available from the given dictionary, then return the string containing first letters of the letter groups, which correspond to the input digits.
For example:
```python
T9([], '43556') returns ['gdjjm']
T9(['gold', 'word'], '4663') returns ['gmmd']
``` | games | FROM = "abc def ghi jkl mno pqrs tuv wxyz" . split()
TO_NUM = "222 333 444 555 666 7777 888 9999" . split()
TABLE_TO_NUM = str . maketrans(* map('' . join, (FROM, TO_NUM)))
TABLE_TO_CHAR = str . maketrans(
* map(lambda lst: '' . join(x[0] for x in lst), (TO_NUM, FROM)))
def T9(words, seq):
return ([w for w in words if seq == w . lower(). translate(TABLE_TO_NUM)]
or [seq . translate(TABLE_TO_CHAR)])
| T9 Predictor | 5b085335abe956c1ef000266 | [
"Puzzles"
]
| https://www.codewars.com/kata/5b085335abe956c1ef000266 | 6 kyu |
Consider the sequence `S(n, z) = (1 - z)(z + z**2 + z**3 + ... + z**n)` where `z` is a complex number
and `n` a positive integer (n > 0).
When `n` goes to infinity and `z` has a correct value (ie `z` is in its domain of convergence `D`), `S(n, z)` goes to a finite limit
`lim` depending on `z`.
Experiment with `S(n, z)` to guess the domain of convergence `D`of `S` and `lim` value when `z` is in `D`.
Then determine the smallest integer `n` such that `abs(S(n, z) - lim) < eps`
where `eps` is a given small real number and `abs(Z)` is the modulus or norm of the complex number Z.
Call `f` the function `f(z, eps)` which returns `n`.
If `z` is such that `S(n, z)` has no finite limit (when `z` is outside of `D`) `f` will return -1.
#### Examples:
I is a complex number such as I * I = -1 (sometimes written `i` or `j`).
`f(0.3 + 0.5 * I, 1e-4) returns 17`
`f(30 + 5 * I, 1e-4) returns -1`
#### Remark:
For languages that don't have complex numbers or "easy" complex numbers, a complex number `z` is represented by two real numbers `x` (real part) and `y` (imaginary part).
`f(0.3, 0.5, 1e-4) returns 17`
`f(30, 5, 1e-4) returns -1`
#### Note:
You pass the tests if `abs(actual - expected) <= 1` | reference | import math
def f(z, eps):
if (abs(z) >= 1.0):
return - 1
return int(math . log(eps) / math . log(abs(z)))
| Experimenting with a sequence of complex numbers | 5b06c990908b7eea73000069 | [
"Fundamentals",
"Puzzles"
]
| https://www.codewars.com/kata/5b06c990908b7eea73000069 | 6 kyu |
*This is the advanced version of the
[Minimum and Maximum Product of k Elements](https://www.codewars.com/kata/minimum-and-maximum-product-of-k-elements/) kata.*
---
Given a list of **integers** and a positive integer `k` (> 0), find the minimum and maximum possible product of `k` elements taken from the list.
If you cannot take enough elements from the list, return `None`/`nil`.
## Examples
```python
numbers = [1, -2, -3, 4, 6, 7]
k = 1 ==> -3, 7
k = 2 ==> -21, 42 # -3*7, 6*7
k = 3 ==> -126, 168 # -3*6*7, 4*6*7
k = 7 ==> None # there are only 6 elements in the list
```
```ruby
numbers = [1, -2, -3, 4, 6, 7]
k = 1 ==> -3, 7
k = 2 ==> -21, 42 # -3*7, 6*7
k = 3 ==> -126, 168 # -3*6*7, 4*6*7
k = 7 ==> nil # there are only 6 elements in the list
```
Note: the test lists can contain up to 500 elements, so a naive approach will not work.
---
## My other katas
If you enjoyed this kata then please try [my other katas](https://www.codewars.com/users/anter69/authored)! :-)
#### *Translations are welcome!*
| algorithms | from functools import reduce
from operator import mul
def find_min_max_product(arr, k):
if k > len(arr):
return None
if k == 1:
return min(arr), max(arr)
if k == len(arr):
prod = reduce(mul, arr)
return prod, prod
arr = sorted(arr)
prods = []
for i in range(k + 1):
nums = arr[: k - i] + (arr[- i:] if i else [])
prods . append(reduce(mul, nums))
return min(prods), max(prods)
| Minimum and Maximum Product of k Elements - Advanced | 5b05867c87566a947a00001c | [
"Arrays",
"Lists",
"Performance",
"Algorithms"
]
| https://www.codewars.com/kata/5b05867c87566a947a00001c | 5 kyu |
# Background:
In Japan, a game called Shiritori is played. The rules are simple, a group of people take turns calling out a word whose beginning syllable is the same as the previous player's ending syllable. For example, the first person would say the word ねこ, and the second player must make a word that starts with こ, like こむぎ. This repeats until a player can not think of a word fast enough or makes a word that ends in ん, because there are no words that begin with ん in the Japanese language.
English Shiritori has the same principle, with the first and last letters of words. That being said the lose condition is saying a word that doesn't start with the previous word's last letter or not saying a word quick enough.
``` For example: apple -> eggs -> salmon -> nut -> turkey ... ```
# Your Task:
You will be given a list of strings, a transcript of an English Shiritori match. Your task is to find out if the game ended early, and return a list that contains every valid string until the mistake. If a list is empty return an empty list. If one of the elements is an empty string, that is invalid and should be handled.
**************************************************************************************
### Examples:
## All elements valid:
The array ```{"dog","goose","elephant","tiger","rhino","orc","cat"}```
should return `{"dog","goose","elephant","tiger","rhino","orc","cat"}`
## An invalid element at index 2:
The array ``` {"dog","goose","tiger","cat", "elephant","rhino","orc"} ```
should return ``` ("dog","goose") ```
since goose ends in `'e'` and tiger starts with `'t'`
## An invalid empty string at index 2:
The array ``` {"ab","bc","","cd"} ```
should return ``` ("ab","bc") ```
## All invalid empty string at index 0:
The array ``` {"","bc","","cd"} ```
should return ``` An Empty List ```
**************************************************************************************
## Resources:
https://en.wikipedia.org/wiki/Shiritori
### Notes:
猫 = ねこ = neko = cat
小麦 = こむぎ = komugi = wheat
| reference | def game(words):
if not words or not words[0]:
return []
for i in range(1, len(words)):
if not words[i] or words[i - 1][- 1] != words[i][0]:
return words[: i]
return words
| An English Twist on a Japanese Classic | 5b04be641839f1a0ab000151 | [
"Fundamentals",
"Algorithms",
"Strings"
]
| https://www.codewars.com/kata/5b04be641839f1a0ab000151 | 7 kyu |
For every string, after every occurrence of `'and'` and/or `'but'`, insert the substring `'apparently'` directly after the occurrence(s).
If input does not contain 'and' or 'but', return the same string. If a blank string, return `''`.
If substring `'apparently'` is already directly after an `'and'` and/or `'but'`, do not add another. (Do not add duplicates).
# Examples:
Input 1
'It was great and I've never been on live television before but sometimes I don't watch this.'
Output 1
'It was great and apparently I've never been on live television before but apparently sometimes I don't watch this.'
Input 2
'but apparently'
Output 2
'but apparently'
(no changes because `'apparently'` is already directly after `'but'` and there should not be a duplicate.)
An occurrence of `'and'` and/or `'but'` only counts when it is at least one space separated. For example `'andd'` and `'bbut'` do not count as occurrences, whereas `'b but'` and `'and d'` does count.
reference that may help:
https://www.youtube.com/watch?v=rz5TGN7eUcM
| reference | import re
def apparently(string):
return re . sub(r'(?<=\b(and|but)\b(?! apparently\b))', ' apparently', string)
| Apparently-Modifying Strings | 5b049d57de4c7f6a6c0001d7 | [
"Strings",
"Fundamentals"
]
| https://www.codewars.com/kata/5b049d57de4c7f6a6c0001d7 | 7 kyu |
Kate and Michael want to buy a pizza and share it. Depending on the price of the pizza, they are going to divide the costs:
* If the pizza is less than €5,- Michael invites Kate, so Michael pays the full price.
* Otherwise Kate will contribute 1/3 of the price, but no more than €10 (she's broke :-) and Michael pays the rest.
How much is Michael going to pay? Calculate the amount with two decimals, if necessary. | reference | def michael_pays(cost):
return round(cost if cost < 5 else max(cost * 2 / 3, cost - 10), 2)
| Pizza Payments | 5b043e3886d0752685000009 | [
"Fundamentals"
]
| https://www.codewars.com/kata/5b043e3886d0752685000009 | 7 kyu |
The input will be an array of dictionaries.
Return the values as a string-seperated sentence in the order of their keys' integer equivalent (increasing order).
The keys are not reoccurring and their range is `-999 < key < 999`.
The dictionaries' keys & values will always be strings and will always not be empty.
## Example
```
Input:
List = [
{'4': 'dog' }, {'2': 'took'}, {'3': 'his'},
{'-2': 'Vatsan'}, {'5': 'for'}, {'6': 'a'}, {'12': 'spin'}
]
Output:
'Vatsan took his dog for a spin'
``` | reference | def sentence(ds):
return ' ' . join(v for _, v in sorted((int(k), v) for d in ds for k, v in d . items()))
| String Reordering | 5b047875de4c7f9af800011b | [
"Fundamentals",
"Strings",
"Lists"
]
| https://www.codewars.com/kata/5b047875de4c7f9af800011b | 7 kyu |
In a secret Mars base, the NASA uses an omni wheel robot. It is a repair robot wich can fix their reactor. Currently there are no astronauts on the Mars because of the low budget, only this robot can save the secret Mars base.
But there is a problem. The the robot's motor controller is a little bit buggy since the last solar flare. The reported bugs are the following:
- You cannot use if statement and create classes
- Eval and exec are useless
- You can call each motor starter functions only once in your source code
- You cannot use the "_" and "\" symbols and the "and" operator
- You can use the "=" operator only once and the "or" word three times (the "north" word contains an "or" word!)
- The robot can turn on maximum 2 motors at the same time
- You cannot turn on the opposite motors at the same time (for example north and south)
- Don't worry about the motors' speed and the direction of their rotation because those are also buggy, so there are only one speed and one direction.
Your task is to write a new motor controller function. The input will be an integer between 0 and 7. This number represents that part of the robot where you have to turn on the motors. For example turn on the north and west motors in that case when you get northwest input.
- east: 0
- west: 1
- north: 2
- south: 3
- northeast: 4
- southwest: 5
- northwest: 6
- southeast: 7
The robot has 4 motors, each of them has a starter function, these are:
- west()
- east()
- north()
- south()
| reference | def controller(Q): return [[east, west, north, south][V]() for V in [
[0], [1], [2], [3], [2, 0], [3, 1], [2, 1], [3, 0]][Q]]
| Fix the robot and save the secret Mars base | 5b029d9dde4c7f01600001ad | [
"Algorithms",
"Mathematics",
"Fundamentals"
]
| https://www.codewars.com/kata/5b029d9dde4c7f01600001ad | 6 kyu |
## Description
Peter enjoys taking risks, and this time he has decided to take it up a notch!
Peter asks his local barman to pour him **n** shots, after which Peter then puts laxatives in **x** of them. He then turns around and lets the barman shuffle the shots. Peter approaches the shots and drinks **a** of them one at a time. Just one shot is enough to give Peter a runny tummy. What is the probability that Peter doesn't need to run to the loo?
## Task
You are given:
**n** - The total number of shots.
**x** - The number of laxative laden shots.
**a** - The number of shots that peter drinks.
return the probability that Peter won't have the trots after drinking. **n** will always be greater than **x**, and **a** will always be less than **n**.
**You must return the probability rounded to two decimal places i.e. 0.05 or 0.81** | games | from functools import reduce
def get_chance(n, x, a):
return round(reduce(lambda m, b: m * (1 - x / (n - b)), range(a), 1), 2)
| Laxative Shot Roulette | 5b02ae6aa2afd8f1b4001ba4 | [
"Probability",
"Puzzles",
"Data Science",
"Statistics"
]
| https://www.codewars.com/kata/5b02ae6aa2afd8f1b4001ba4 | 7 kyu |
My grandfather always predicted how old people would get, and right before he passed away he revealed his secret!
In honor of my grandfather's memory we will write a function using his formula!
* Take a list of ages when each of your great-grandparent died.
* Multiply each number by itself.
* Add them all together.
* Take the square root of the result.
* Divide by two.
## Example
```javascript
predictAge(65, 60, 75, 55, 60, 63, 64, 45) === 86
```
```R
predict_age(65, 60, 75, 55, 60, 63, 64, 45) == 86
```
```python
predict_age(65, 60, 75, 55, 60, 63, 64, 45) == 86
```
```ruby
predict_age(65, 60, 75, 55, 60, 63, 64, 45) == 86
```
```crystal
predict_age(65, 60, 75, 55, 60, 63, 64, 45) == 86
```
```c++
predictAge(65, 60, 75, 55, 60, 63, 64, 45) == 86
```
```php
predictAge(65, 60, 75, 55, 60, 63, 64, 45) == 86
```
```csharp
predictAge(65, 60, 75, 55, 60, 63, 64, 45) == 86
```
```lua
Predicter.predictAge(65, 60, 75, 55, 60, 63, 64, 45) == 86
```
Note: the result should be rounded down to the nearest integer.
Some random tests might fail due to a bug in the JavaScript implementation. Simply resubmit if that happens to you. | reference | def predict_age(* ages):
return sum(a * a for a in ages) * * .5 / / 2
| Predict your age! | 5aff237c578a14752d0035ae | [
"Fundamentals"
]
| https://www.codewars.com/kata/5aff237c578a14752d0035ae | 7 kyu |
Did you watch the famous "Life of Brian" moovie? Pilate could not say letter "r". Try to call callme() in a try block without "r" letter. It means you cannot write the "try" keyword in your source because that contains letter "r". And remember, Pilate was not equal with others, so you cannot use "=" symbol.
Good Luck! :) | reference | exec("t\x72y:callme()\nexcept:0")
| Try without letter "r"! - Pontius Pilate will tly it :) | 5b01e9f73e971587e70001ab | [
"Security",
"Fundamentals"
]
| https://www.codewars.com/kata/5b01e9f73e971587e70001ab | 6 kyu |
You are given a length of string and two thumbtacks. On thumbtack goes into the focus point *F₀* with coordinates *x₀* and *y₀*, and the other does into point *F₁* with points *x₁* and *y₁*. The string is then tied at the ends to the thumbtacks and has length *l* excluding the knots at the ends. If you pull the string taught with a pencil and draw around the plane you'll have an ellipse with focuses at *F₀* and *F₁*. Given a new point *P*, determine if it falls inside of the ellipse.
You must write a function that takes arguments `f0`, `f1`, `l`, and `p` and returns `true` or `false` depending on whether or not `p` falls inside the ellipse.
Each of `f0`, `f1`, and `p` has has properties `x` and `y` for its coordinates.
You will never be given the case where the string is too short to reach between the points. | algorithms | def dis(p1, p2):
return ((p1['x'] - p2['x']) * * 2 + (p1['y'] - p2['y']) * * 2) * * 0.5
def ellipse_contains_point(f0, f1, l, p):
return dis(f0, p) + dis(f1, p) <= l
| Ellipse contains point? | 5b01abb9de4c7f3c22000012 | [
"Geometry",
"Mathematics",
"Algorithms"
]
| https://www.codewars.com/kata/5b01abb9de4c7f3c22000012 | 7 kyu |
Create the hi_all() function without using strings, numbers and booleans. The return value is "Hello World". No, it is not impossible, use the builtin functions. Good luck :) | reference | def hi_all():
one = - ~ len([])
two = one + one
three = one + two
four = two * two
five = three + two
seven = four + three
eight = four * two
ten = pow(three, two) + one
hundred = ten * ten
H = chr((seven * ten) + two)
e = chr(hundred + one)
l = chr(hundred + eight)
o = chr(hundred + ten + one)
sp = chr(eight * four)
W = chr((eight * ten) + seven)
r = chr(hundred + ten + four)
d = chr(hundred)
return H + e + l + l + o + sp + W + o + r + l + d
| Hello World without strings, numbers and booleans | 5b0148133e9715bf6f000154 | [
"Strings",
"Restricted",
"Fundamentals"
]
| https://www.codewars.com/kata/5b0148133e9715bf6f000154 | 6 kyu |
A population of bears consists of black bears, brown bears, and white bears.
The input is an array of two elements.
Determine whether the offspring of the two bears will return `'black'`, `'brown'`, `'white'`, `'dark brown'`, `'grey'`, `'light brown'`, or `'unknown'`.
Elements in the the array will always be a string.
## Examples:
bear_fur(['black', 'black']) returns 'black'
bear_fur(['brown', 'brown']) returns 'brown'
bear_fur(['white', 'white']) returns 'white'
bear_fur(['black', 'brown']) returns 'dark brown'
bear_fur(['black', 'white']) returns 'grey'
bear_fur(['brown', 'white']) returns 'light brown'
bear_fur(['yellow', 'magenta']) returns 'unknown'
| reference | DEFAULT = 'unknown'
COLORS = {'black' + 'brown': 'dark brown',
'black' + 'white': 'grey',
'brown' + 'white': 'light brown'}
def bear_fur(bears):
b1, b2 = sorted(bears)
return b1 if b1 == b2 else COLORS . get(b1 + b2, DEFAULT)
| Offspring Traits | 5b011461de4c7f8d78000052 | [
"Fundamentals",
"Lists",
"Strings"
]
| https://www.codewars.com/kata/5b011461de4c7f8d78000052 | 7 kyu |
### Description
Given a list of **integers** (possibly including duplicates) and a positive integer `k` (> 0), find the minimum and maximum possible product of `k` elements taken from the list.
If you cannot take enough elements from the list (`k` > list size), return `None`/`nil`.
### Examples
```python
numbers = [1, -2, -3, 4, 6, 7]
k = 1 ==> -3, 7
k = 2 ==> -21, 42 # -3*7, 6*7
k = 3 ==> -126, 168 # -3*6*7, 4*6*7
k = 7 ==> None # there are only 6 elements in the list
```
```ruby
numbers = [1, -2, -3, 4, 6, 7]
k = 1 ==> -3, 7
k = 2 ==> -21, 42 # -3*7, 6*7
k = 3 ==> -126, 168 # -3*6*7, 4*6*7
k = 7 ==> nil # there are only 6 elements in the list
```
Note: the test lists are sufficiently small (up to 20 elements) for a simple approach.
There is an [advanced version](https://www.codewars.com/kata/minimum-and-maximum-product-of-k-elements-advanced) of this kata, if you're up to the challenge! :-)
---
### My other katas
If you enjoyed this kata then please try [my other katas](https://www.codewars.com/users/anter69/authored)! :-)
#### *Translations are welcome!* | algorithms | from functools import reduce
from itertools import combinations
from operator import mul
def find_min_max_product(arr, k):
if k <= len(arr):
prods = [reduce(mul, nums) for nums in combinations(arr, k)]
return min(prods), max(prods)
| Minimum and Maximum Product of k Elements | 5afd81d0de4c7f45f4000239 | [
"Arrays",
"Lists",
"Algorithms"
]
| https://www.codewars.com/kata/5afd81d0de4c7f45f4000239 | 7 kyu |
## Task
You must create a class, `Projectile`, which takes in 3 arguments when initialized:
* starting height (`0 ≤ h0 < 200`)
* starting velocity (`0 < v0 < 200`)
* angle of the projectile when it is released (`0° < a < 90°`, measured in degrees).
**All units for distance are feet, and units for time are seconds.**
**Note:** Some solutions were invalidated because I added tests for situations where the starting height is 0, in which case the equation for height would be in the form `h(t) = -16.0t^2 + vt` where `v` represents the initial vertical velocity.
<center>
```math
\large h = -16t^2 + vt + h_0
```
</center>
In the above equation, `h` represents the height of the projectile after `t` seconds; `v` represents the initial vertical velocity; and `h0` represents the starting height.
You need to write the following methods for the `Projectile` class. In Crystal, the arguments passed when the object is initialized will always be of the type `Float64`, and in Java/Scala/Kotlin/Dart/C#, they will be `int`/`Int`s.
1. A `height_eq`, `heightEq`, or `HeightEq` method, which returns the equation for height of the projectile as a function of time. [takes in nothing, returns a `String`]
2. A `horiz_eq`, `horizEq`, or `HeightEq` method, which returns the equation for the horizontal position of the projectile as a function of time. [takes in nothing, returns a `String`]
3. A `height` or `Height` method, which takes in an argument `t` and calculates the height of the projectile in feet. [takes in a `double`, returns a `double`]
4. A `horiz` or `Horiz` method, which also takes in an argument `t` and calculates the horizontal distance that the projectile has traveled. [takes in a `double`, returns a `double`]
5. A `landing` or `Landing` method which returns the point at which the projectile lands on the ground, in the form `[x, y, t]`. (y should always be 0). [takes in nothing, returns an array of `double`s]
EVERYTHING, including values in the equations appearing as coefficients, must be rounded to THREE decimal places. However, if the value is whole, only show one decimal place (for example => -16 becomes -16.0, not -16.000). But ensure that you DO NOT use the three-decimal-place rounded values for calculations. Otherwise, you will find yourself getting answers CLOSE to the correct one but slightly off.
You also need to define instance variables as needed. These will not be tested.
## Examples

This example shows the initial vertical and horizontal velocity when a projectile is fired at 2 ft/s.
```ruby
p = Projectile.new(5, 2, 45) #=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.height_eq #=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horiz_eq #=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(0.2) #=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(0.2) #=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing() #=> [0.856, 0, 0.605] (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```crystal
p = Projectile.new(5.0, 2.0, 45.0) #=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.height_eq #=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horiz_eq #=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(0.2) #=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(0.2) #=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing() #=> [0.856, 0, 0.605] (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```python
p = Projectile(5, 2, 45) #=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.height_eq() #=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horiz_eq() #=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(0.2) #=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(0.2) #=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing() #=> [0.856, 0, 0.605] (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```javascript
p = new Projectile(5, 2, 45) //=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.heightEq() //=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horizEq() //=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(0.2) //=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(0.2) //=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing() //=> [0.856, 0, 0.605] (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```coffeescript
p = new Projectile(5, 2, 45) #=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.heightEq() #=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horizEq() #=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(0.2) #=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(0.2) #=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing() #=> [0.856, 0, 0.605] (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```java
Projectile p = new Projectile(5, 2, 45); //=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.heightEq(); //=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horizEq(); //=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(0.2); //=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(0.2); //=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing(); //=> double[]{ 0.856, 0, 0.605 } (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```typescript
var p = new Projectile(5, 2, 45); //=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.heightEq(); //=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horizEq(); //=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(0.2); //=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(0.2); //=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing(); //=> [0.856, 0, 0.605] (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```scala
var p = new Projectile(5, 2, 45); #=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.heightEq(); //=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horizEq(); //=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(0.2); //=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(0.2); //=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing(); //=> Array(0.856, 0, 0.605) (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```kotlin
var p = Projectile(5, 2, 45); //=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.heightEq(); //=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horizEq(); //=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(0.2); //=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(0.2); //=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing(); //=> doubleArrayOf(0.856, 0, 0.605) (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```dart
Projectile p = new Projectile(5, 2, 45); //=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.heightEq(); //=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horizEq(); //=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(0.2); //=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(0.2); //=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing(); //=> [0.856, 0, 0.605] (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```swift
Projectile p = Projectile(h: 5, v0: 2, a: 45) //=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.heightEq() //=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horizEq() //=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(time: 0.2) //=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(time: 0.2) //=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing() //=> [0.856, 0, 0.605] (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```groovy
Projectile p = new Projectile(5, 2, 45) //=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.heightEq() //=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horizEq() //=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(0.2) //=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(0.2) //=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing() //=> [ 0.856, 0, 0.605 ] (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```csharp
Projectile p = new Projectile(5, 2, 45); //=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.HeightEq(); //=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.HorizEq(); //=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.Height(0.2); //=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.Horiz(0.2); //=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.Landing(); //=> [0.856, 0, 0.605] (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
```rust
let p = Projectile::new(5, 2, 45) //=> a projectile starting at 5 ft above the ground, traveling initially at 2 ft/s, and at an angle of 45 degrees with the horizontal (shown in the triangle above)
p.height_eq() //=> "h(t) = -16.0t^2 + 1.414t + 5.0"
# 1.414 = 2sin(45°)
p.horiz_eq() //=> "x(t) = 1.414t"
# 1.414 = 2cos(45°)
p.height(0.2) //=> 4.643 (Calculation: -16(0.2)^2 + (2sin(45°))(0.2) + 5)
p.horiz(0.2) //=> 0.283 (Calculation: 2cos(45°) * 0.2)
p.landing() //=> [0.856, 0.0, 0.605] (After 0.605 seconds (t = 0.605), the particle has landed on the ground (y = 0.0), and is 0.856 ft horizontally (x = 0.856) away from the release point.)
```
Additionally, note that all coefficients are to be expressed as floats in the string equations, regardless of whether or not they are whole. This means that whole numbers should always be formatted with a ".0" appended. | reference | from math import sin, cos, radians, sqrt
class Projectile:
def __init__(self, h0, v0, a):
self . h = float(h0)
self . x = v0 * cos(radians(a))
self . y = v0 * sin(radians(a))
def height_eq(self):
return f'h(t) = -16.0t^2 + { round ( self . y , 3 )} t' + (self . h > 0) * f' + { round ( self . h , 3 )} '
def horiz_eq(self):
return f'x(t) = { round ( self . x , 3 )} t'
def height(self, t):
return round(- 16 * t * * 2 + self . y * t + self . h, 3)
def horiz(self, t):
return round(self . x * t, 3)
def landing(self):
t = (self . y + sqrt(self . y * * 2 + 64 * self . h)) / 32
return [round(self . x * t, 3), 0, round(t, 3)]
| Projectile Motion | 5af96cea3e9715ec670001dd | [
"Fundamentals"
]
| https://www.codewars.com/kata/5af96cea3e9715ec670001dd | 6 kyu |
Some numbers can be expressed as a difference of two squares, for example, <code>20 = 6<sup>2</sup>-4<sup>2</sup></code> and <code>21 = 5<sup>2</sup>-2<sup>2</sup></code>. Many numbers can be written this way, but not all.
## Your Task
Complete the function that takes a positive integer `n` and returns the amount of numbers between `1` and `n` (inclusive) that can be represented as the difference of two perfect squares.
**Note**: Your code should be able to handle `n` values up to 45000
## Examples
```
n = 4 ==> 3
n = 5 ==> 4
n = 10 ==> 7
n = 20 ==> 15
n = 6427 ==> 4820
``` | algorithms | def count_squareable(n):
return n / / 4 + (n + 1) / / 2
| How Many Differences of Squares? | 5afa08f23e971553170001e0 | [
"Mathematics",
"Algorithms"
]
| https://www.codewars.com/kata/5afa08f23e971553170001e0 | 6 kyu |
### Goal
Given a list of elements [a1, a2, ..., an], with each <i>ai</i> being a string, write a function **majority** that returns the value that appears the most in the list.
If there's no winner, the function should return None, NULL, nil, etc, based on the programming language.
### Example
```python
majority(["A", "B", "A"]) returns "A"
majority(["A", "B", "B", "A"]) returns None
```
```javascript
majority(["A", "B", "A"]) returns "A"
majority(["A", "B", "B", "A"]) returns null
``` | reference | from collections import Counter
def majority(arr):
mc = Counter(arr). most_common(2)
if arr and (len(mc) == 1 or mc[0][1] != mc[1][1]):
return mc[0][0]
| Find the majority | 5af974846bf32304a2000e98 | [
"Fundamentals"
]
| https://www.codewars.com/kata/5af974846bf32304a2000e98 | 7 kyu |
How many times we create a python class and in the __init__ method we just write:
```python
self.name1 = name1
self.name2 = name2
.....
```
for all arguments.....
How boring!!!!
Your task here is to implement a metaclass that let this instantiation be done automatically.
But let's see an example:
```python
class Person(metaclass=LazyInit):
def __init__(self, name, age): pass
```
When we create a Person object like:
```python
a_person = Person('John', 25)
```
The expected behavior will be:
```python
print(a_person.name) # this will print John
print(a_person.age) # this will print 25
```
Obviously the number of arguments might be different from class to class.
Don't worry about **kwargs you will never be given keyword arguments in this kata!!!
A little hint: a decorator could help you out doing the job!!!
Good luck lazy folks..... | reference | class LazyInit (type):
def __call__(self, * args, * * kwargs):
varnames = list(self . __init__ . __code__ . co_varnames)[1:]
for i, name in enumerate(varnames):
setattr(self, name, args[i])
return self
| Lazy Init | 59b7b43b4f98a81b2d00000a | [
"Metaprogramming"
]
| https://www.codewars.com/kata/59b7b43b4f98a81b2d00000a | 4 kyu |
Write a function that returns the `degree` of a polynomial function:
```javascript
degree(x => 42); // 0
degree(x => x); // 1
degree(x => x * x); // 2
degree(x => x * x * x); // 3
degree(x => 2 * x + 3 * x * x + 5); // 2
```
* Assume that the polynomial has a maximum degree of `11`
* The input `x` of the polynomial function
* must be between `-11` and `11`
* use integers to get exact results without rounding errors
| algorithms | def degree(p):
r, d = [p(i) for i in list(range(12))], 0
while r . count(r[0]) != len(r):
r, d = list(map(lambda i: r[i + 1] - r[i], list(range(11 - d)))), d + 1
return d
| What’s the degree? | 55fde83eeccc08d87d0000af | [
"Mathematics",
"Algorithms"
]
| https://www.codewars.com/kata/55fde83eeccc08d87d0000af | 5 kyu |
You are given an array of documents (strings), a term (string), and two booleans finetuning your indexing operation.
Return an array containing the document IDs (`1`-based indices of documents in the array), where the term occurs, sorted in ascending order.
Booleans:
1.
CaseSensitive: `test` matches `test`, but not `Test`
Not CaseSensitive: `test` matches both `test` and `Test`
2.
Exact Match: `test` matches `test` and `.test!`, but not `attest` or `test42`
Not Exact Match: `test` matches both `test` and `attest`
### Example:
```javascript
buildInvertedIndex(["Sign", "sign", "Signature", "Sign-ature"], "Sign", true, true)
return [1,4]
```
```python
build_inverted_index(["Sign", "sign", "Signature", "Sign-ature"], "Sign", True, True)
return [1, 4]
```
___
### NLP-Series:
Part 1:
<a href="">Inverted Index</a href> | reference | import re
def build_inverted_index(coll, term, cS, eM):
return [i + 1 for i, x in enumerate(coll) if re . search(r"{0}{1}{0}" . format('\\b' if eM else '', term), x, flags=not cS and re . I)]
| NLP-Series #1 - Inverted Index | 5af823451839f1768f00009d | [
"Fundamentals",
"Parsing",
"Regular Expressions"
]
| https://www.codewars.com/kata/5af823451839f1768f00009d | 7 kyu |
# Problem
Since table has four corners, there are eight ways to iterate over its' elements ((by rows then by columns | by columns then by rows) * (top left to bottom right | top right to bottom left | bottom left to top right | bottom right to top left)).
Implement forward iterator that can be constucted with two directions as parameters that returns table items in specified order. (`c++`: implement `begin(dir0,dir1)` and `end()` functions, `python`: implement `walk(dir0,dir1)` function)
For example iterator with directions `up` `left` must return (one by one):
```
9, 6, 3, 8, 5, 2, 7, 4, 1
```
for table
```
{{1,2,3},
{4,5,6},
{7,8,9}}
```
For simplicity lets assume that table have at least one row and at least one column and we dont need to test for that.
## C++
Iterator must support assignment.
## Python
Iterator must be lazy (assuming `Table.data` have `__getitem__(key)` and `__len__()` implemented on both dimensions). | algorithms | DIRECTION_UP, DIRECTION_LEFT, DIRECTION_DOWN, DIRECTION_RIGHT = range(1, 5)
class Table:
def __init__(self, data):
self . data = data
def walk(self, dir0, dir1):
horizontal = range(len(self . data[0]))[
:: - 1 if DIRECTION_LEFT in (dir0, dir1) else 1]
vertical = range(len(self . data))[
:: - 1 if DIRECTION_UP in (dir0, dir1) else 1]
if dir0 in (DIRECTION_LEFT, DIRECTION_RIGHT):
return (self . data[j][i] for j in vertical for i in horizontal)
else:
return (self . data[j][i] for i in horizontal for j in vertical)
| Eight ways to iterate over table | 5af5c18786d075cd5e00008b | [
"Iterators",
"Algorithms"
]
| https://www.codewars.com/kata/5af5c18786d075cd5e00008b | 5 kyu |
<!--Amidakuji-->
<p><span style='color:#8df'><a href='https://en.wikipedia.org/wiki/Ghost_Leg' style='color:#9f9;text-decoration:none'>Amidakuji</a></span> is a method of lottery designed to create random pairings between two sets comprised of an equal number of elements.</p>
<p>Your task is to write a function <code>amidakuji</code> that returns the final positions of each element. Note that the elements are an ascending sequence of consecutive integers starting with <code>0</code> (from left to right).</p>
<h2 style='color:#f88'>Input</h2>
<p>Your function will receive an array/list of equal-length strings consisting of <code>0</code> and <code>1</code> characters; this represents the "ladder" structure. The <code>1</code>s represent the rungs of the ladder and the <code>0</code>s represent empty space.<br/><br/>
Each element begins at the top of its corresponding vertical rail, as illustrated in the diagram below.<br/>During the descent of the ladder, whenever a vertical rail intersects a horizontal rung, it swaps values with the adjacent connecting vertical rail.</p>
<h2 style='color:#f88'>Output</h2>
<p>Your function should return an array of integers, with each integer in its final position.</p>
<h2 style='color:#f88'>Test Example</h2>
<img src='https://i.imgur.com/6pJ87vP.png'>
<p>The diagram above is a visual representation of the test example below. The yellow highlighted path shows the path taken by the <code>2</code> value. Each time it encounters a crosspiece, it shifts position.</p>
```javascript
let ladder = [
'001001',
'010000',
'100100',
'001000',
'100101',
'010010',
'101001',
'010100'
];
amidakuji(ladder); // [4, 2, 0, 5, 3, 6, 1]
```
```python
ladder = [
'001001',
'010000',
'100100',
'001000',
'100101',
'010010',
'101001',
'010100'
]
amidakuji(ladder) # [4, 2, 0, 5, 3, 6, 1]
```
```elixir
ladder = [
"001001",
"010000",
"100100",
"001000",
"100101",
"010010",
"101001",
"010100"
]
Banzai.amidakuji(ladder) # [4, 2, 0, 5, 3, 6, 1]
```
```go
ladder := []string{
"001001",
"010000",
"100100",
"001000",
"100101",
"010010",
"101001",
"010100",
}
Amidakuji(ladder) // [4 2 0 5 3 6 1]
```
```csharp
var ladder = new string[]{
"001001",
"010000",
"100100",
"001000",
"100101",
"010010",
"101001",
"010100"
};
Banzai.Amidakuji(ladder) == new int[]{4,2,0,5,3,6,1}; // true
```
<h2 style='color:#f88'>Other Technical Details</h2>
<ul>
<li>A function <code>visualizer</code> is preloaded to help illustrate the structure of the ladder; you can call this function with test inputs</li>
<li>No two rungs will ever be adjacent (so there is no ambiguity about directional path)</li>
<li>Full Test Suite: <code>10</code> fixed tests and <code>100</code> randomly-generated tests</li>
<li>Test input dimension upper bounds:<br/>
<ul>
<li>maximum width: <code>20</code></li>
<li>maximum height: <code>50</code></li>
</ul>
</li>
<li>Inputs will always be valid</li>
</ul>
<p>If you enjoyed this kata, be sure to check out <a href='https://www.codewars.com/users/docgunthrop/authored' style='color:#9f9;text-decoration:none'>my other katas</a></p> | reference | def amidakuji(ar):
numbers = list(range(len(ar[0]) + 1))
for line in ar:
for i, swap in enumerate(line):
if swap == '1':
numbers[i], numbers[i + 1] = numbers[i + 1], numbers[i]
return numbers
| Amidakuji | 5af4119888214326b4000019 | [
"Arrays",
"Fundamentals"
]
| https://www.codewars.com/kata/5af4119888214326b4000019 | 6 kyu |
Our spaceship has crashed on an unknown planet many light years away from earth. Thankfully we were able to send out a distress signal right before the crash. Help will be here shortly but we need to gather as much information about this planet as we can before we're rescued.
Before our control panels were destroyed, we were able to gather the duration of this planet's orbit around it's planetary system's star.
Among other things, we need to determine if a given year is a leap year on this planet.
Your Task:
Given the duration of the planet's orbit (in days) and a specific year on this planet, determine if the given year is a leap year here.
For example:
On Earth, a single rotation around the sun takes 365.25 days. Therefore, each year takes 365 days but every forth year is a leap year and takes 366 days. The next leap year on Earth will occur in 2020.
Notes:
To make things easier, the period of the leap years will always be a power of 2. Good luck! | games | def is_leap_year(d, y):
return (d * y). is_integer()
| We've crashed on a distance planet in our galaxy! When do leap years occur here? | 5af43416882143534300142c | [
"Puzzles"
]
| https://www.codewars.com/kata/5af43416882143534300142c | 7 kyu |
Hello,
I am Jomo Pipi
and today we will be evaluating an expression like this:
(there are an infinite number of radicals)
<!-- Just incase
<img src="https://latex.codecogs.com/gif.latex?\bg_black&space;\LARGE&space;\sqrt{x+\sqrt{x+\sqrt{x+\sqrt{x...}}}}" title="\LARGE \sqrt{x+\sqrt{x+\sqrt{x+\sqrt{x...}}}}" />
-->
``$\sqrt{x + \sqrt{x + \sqrt{x + \sqrt{x + \cdots}}}}$``
for a given value x
<font size="5">Simple!</font>
arguments passed in will be 1 or greater
(Check out my other kata!)
<a title="Matrix Diagonal Sort OMG" href="https://www.codewars.com/kata/5ab1f8d38d28f67410000090">Matrix Diagonal Sort OMG</a>
<a title="String -> N iterations -> String" href="https://www.codewars.com/kata/5ae43ed6252e666a6b0000a4">String -> N iterations -> String</a>
<a title="String -> X iterations -> String" href="https://www.codewars.com/kata/5ae64f28d2ee274164000118">String -> X iterations -> String</a>
<a title="ANTISTRING" href="https://www.codewars.com/kata/5ab349e01aaf060cd0000069">ANTISTRING</a>
<a title="Array - squareUp b!" href="https://www.codewars.com/kata/5a8bcd980025e99381000099">Array - squareUp b!</a>
<a title="Matrix - squareUp b!" href="https://www.codewars.com/kata/5a972f30ba1bb5a2590000a0">Matrix - squareUp b!</a>
<a title="Infinitely Nested Radical Expressions" href="https://www.codewars.com/kata/5af2b240d2ee2764420000a2">Infinitely Nested Radical Expressions</a>
<a title="pipi Numbers!" href="https://www.codewars.com/kata/5af27e3ed2ee278c2c0000e2">pipi Numbers!</a>
| algorithms | def fn(x):
return (1 + (1 + 4 * x) * * 0.5) / 2
| Infinitely Nested Radicals | 5af2b240d2ee2764420000a2 | [
"Mathematics",
"Algorithms",
"Logic"
]
| https://www.codewars.com/kata/5af2b240d2ee2764420000a2 | 7 kyu |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.