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
### Description Let's play the game "Whac-A-Mole". Give you an 2D array: ``` [ [1,1,2,2], [3,3,4,4], [4,8,8,8] ] ``` The meaning of numbers in the array is that the mole will disappear after n seconds(0 means no mole). You are holding a big hammer and every second can hit two moles. Please calculate the maximum number of moles you can hit. In accordance with the above example: ``` [ [1,1,2,2], [3,3,4,4], [4,8,8,8] ] After 1 second(hit 2, total=2) [ [x,x,1,1], [2,2,3,3], [3,7,7,7] ] After 2 seconds(hit 2, total=4) [ [x,x,x,x], [1,1,2,2], [2,6,6,6] ] After 3 seconds(hit 2, total=6) [ [x,x,x,x], [x,x,1,1], [1,5,5,5] ] After 4 seconds(hit 2, total=8) [ [x,x,x,x], [x,x,x,x], [0,4,4,4] ] After 5 seconds(hit 2, total=10) [ [x,x,x,x], [x,x,x,x], [0,x,x,3] ] After 6 seconds(hit 1, total=11) [ [x,x,x,x], [x,x,x,x], [0,x,x,x] ] We hit a total of 11 moles. ``` Another example: ``` [ [6,4,1,1], [4,4,4,4], [1,2,3,3] ] After 1 second(hit 2, total=2) [ [5,3,x,x], [3,3,3,3], [0,1,2,2] ] After 2 second(hit 2, total=4) [ [4,2,x,x], [2,2,2,2], [0,x,x,1] ] After 3 second(hit 2, total=6) [ [3,x,x,x], [1,1,1,1], [0,x,x,x] ] After 4 second(hit 2, total=8) [ [2,x,x,x], [x,x,0,0], [0,x,x,x] ] After 5 second(hit 1, total=9) [ [x,x,x,x], [x,x,0,0], [0,x,x,x] ] We hit a total of 9 moles. ``` OK, that's all. I guess this is a 6kyu kata. If you agree, please rank it as 6kyu and vote `very`;-) If you think this kata is too easy or too hard, please shame me by rank it as you want and vote `somewhat` or `none` :[ ### Task Complete function `whacAMole` that accepts a argument `arr`, return the maximum number of moles you can hit.
reference
def whac_a_mole(a): b = [] for x in a: b . extend(x) b . sort() n = r = h = 0 for x in b: if x - n > 0: r += 1 h ^= 1 n += not h return r
I guess this is a 6kyu kata #5: Whac-A-Mole
57d250e55dc38e288c000081
[ "Puzzles", "Fundamentals" ]
https://www.codewars.com/kata/57d250e55dc38e288c000081
6 kyu
Jon and Joe have received equal marks in the school examination. But, they won't reconcile in peace when equated with each other. To prove his might, Jon challenges Joe to write a program to find all possible number combos that sum to a given number. While unsure whether he would be able to accomplish this feat or not, Joe accpets the challenge. Being Joe's friend, your task is to help him out. # Task Create a function `combos`, that accepts a single positive integer `num` (30 > `num` > 0) and returns an array of arrays of positive integers that sum to `num`. # Notes 1. Sub-arrays may or may not have their elements sorted. 2. The order of sub-arrays inside the main array does not matter. 3. For an optimal solution, the following operation should complete within 6000ms. # Sample ```javascript combos(3) => [ [ 3 ], [ 1, 1, 1 ], [ 1, 2 ] ] combos(10) => [ [ 10 ], [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ], [ 1, 1, 1, 1, 1, 1, 1, 1, 2 ], [ 1, 1, 1, 1, 1, 1, 1, 3 ], [ 1, 1, 1, 1, 1, 1, 4 ], [ 1, 1, 1, 1, 1, 5 ], [ 1, 1, 1, 1, 6 ], [ 1, 1, 1, 7 ], [ 1, 1, 8 ], [ 1, 9 ], [ 1, 1, 1, 1, 1, 1, 2, 2 ], [ 1, 1, 1, 1, 1, 2, 3 ], [ 1, 1, 1, 1, 2, 4 ], [ 1, 1, 1, 1, 2, 2, 2 ], [ 1, 1, 1, 1, 3, 3 ], [ 1, 1, 1, 2, 5 ], [ 1, 1, 1, 2, 2, 3 ], [ 1, 1, 1, 3, 4 ], [ 1, 1, 2, 6 ], [ 1, 1, 2, 2, 4 ], [ 1, 1, 2, 2, 2, 2 ], [ 1, 1, 2, 3, 3 ], [ 1, 1, 3, 5 ], [ 1, 1, 4, 4 ], [ 1, 2, 7 ], [ 1, 2, 2, 5 ], [ 1, 2, 2, 2, 3 ], [ 1, 2, 3, 4 ], [ 1, 3, 6 ], [ 1, 3, 3, 3 ], [ 1, 4, 5 ], [ 2, 8 ], [ 2, 2, 6 ], [ 2, 2, 2, 4 ], [ 2, 2, 2, 2, 2 ], [ 2, 2, 3, 3 ], [ 2, 3, 5 ], [ 2, 4, 4 ], [ 3, 7 ], [ 3, 3, 4 ], [ 4, 6 ], [ 5, 5 ] ] ```
algorithms
def combos(n): if n == 1: return [[1]] if n == 2: return [[1, 1], [2]] if n == 3: return [[1, 1, 1], [1, 2], [3]] if n == 4: return [[1, 1, 1, 1], [1, 1, 2], [1, 3], [2, 2], [4]] if n == 5: return [[1, 1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 3], [1, 2, 2], [1, 4], [2, 3], [5]] if n == 6: return [[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 2], [1, 1, 1, 3], [1, 1, 2, 2], [1, 1, 4], [1, 2, 3], [1, 5], [2, 2, 2], [2, 4], [3, 3], [6]] if n == 7: return [[1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 3], [1, 1, 1, 2, 2], [1, 1, 1, 4], [1, 1, 2, 3], [1, 1, 5], [1, 2, 2, 2], [1, 2, 4], [1, 3, 3], [1, 6], [2, 2, 3], [2, 5], [3, 4], [7]] if n == 8: return [[1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 3], [1, 1, 1, 1, 2, 2], [1, 1, 1, 1, 4], [1, 1, 1, 2, 3], [1, 1, 1, 5], [1, 1, 2, 2, 2], [1, 1, 2, 4], [1, 1, 3, 3], [1, 1, 6], [1, 2, 2, 3], [1, 2, 5], [1, 3, 4], [1, 7], [2, 2, 2, 2], [2, 2, 4], [2, 3, 3], [2, 6], [3, 5], [4, 4], [8]] if n == 9: return [[1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 2, 2], [1, 1, 1, 1, 1, 4], [1, 1, 1, 1, 2, 3], [1, 1, 1, 1, 5], [1, 1, 1, 2, 2, 2], [1, 1, 1, 2, 4], [1, 1, 1, 3, 3], [1, 1, 1, 6], [1, 1, 2, 2, 3], [1, 1, 2, 5], [1, 1, 3, 4], [1, 1, 7], [1, 2, 2, 2, 2], [1, 2, 2, 4], [1, 2, 3, 3], [1, 2, 6], [1, 3, 5], [1, 4, 4], [1, 8], [2, 2, 2, 3], [2, 2, 5], [2, 3, 4], [2, 7], [3, 3, 3], [3, 6], [4, 5], [9]] if n == 10: return [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 1, 2, 2], [1, 1, 1, 1, 1, 1, 4], [1, 1, 1, 1, 1, 2, 3], [1, 1, 1, 1, 1, 5], [1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 2, 4], [1, 1, 1, 1, 3, 3], [1, 1, 1, 1, 6], [1, 1, 1, 2, 2, 3], [1, 1, 1, 2, 5], [1, 1, 1, 3, 4], [1, 1, 1, 7], [1, 1, 2, 2, 2, 2], [1, 1, 2, 2, 4], [1, 1, 2, 3, 3], [1, 1, 2, 6], [1, 1, 3, 5], [1, 1, 4, 4], [1, 1, 8], [1, 2, 2, 2, 3], [1, 2, 2, 5], [1, 2, 3, 4], [1, 2, 7], [1, 3, 3, 3], [1, 3, 6], [1, 4, 5], [1, 9], [2, 2, 2, 2, 2], [2, 2, 2, 4], [2, 2, 3, 3], [2, 2, 6], [2, 3, 5], [2, 4, 4], [2, 8], [3, 3, 4], [3, 7], [4, 6], [5, 5], [10]] if n == 11: return [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 1, 1, 2, 2], [1, 1, 1, 1, 1, 1, 1, 4], [1, 1, 1, 1, 1, 1, 2, 3], [1, 1, 1, 1, 1, 1, 5], [1, 1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 2, 4], [1, 1, 1, 1, 1, 3, 3], [1, 1, 1, 1, 1, 6], [1, 1, 1, 1, 2, 2, 3], [1, 1, 1, 1, 2, 5], [1, 1, 1, 1, 3, 4], [1, 1, 1, 1, 7], [1, 1, 1, 2, 2, 2, 2], [1, 1, 1, 2, 2, 4], [1, 1, 1, 2, 3, 3], [1, 1, 1, 2, 6], [1, 1, 1, 3, 5], [1, 1, 1, 4, 4], [1, 1, 1, 8], [1, 1, 2, 2, 2, 3], [1, 1, 2, 2, 5], [1, 1, 2, 3, 4], [1, 1, 2, 7], [1, 1, 3, 3, 3], [1, 1, 3, 6], [1, 1, 4, 5], [1, 1, 9], [1, 2, 2, 2, 2, 2], [1, 2, 2, 2, 4], [1, 2, 2, 3, 3], [1, 2, 2, 6], [1, 2, 3, 5], [1, 2, 4, 4], [1, 2, 8], [1, 3, 3, 4], [1, 3, 7], [1, 4, 6], [1, 5, 5], [1, 10], [2, 2, 2, 2, 3], [2, 2, 2, 5], [2, 2, 3, 4], [2, 2, 7], [2, 3, 3, 3], [2, 3, 6], [2, 4, 5], [2, 9], [3, 3, 5], [3, 4, 4], [3, 8], [4, 7], [5, 6], [11]] if n == 12: return [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 1, 1, 1, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 4], [1, 1, 1, 1, 1, 1, 1, 2, 3], [1, 1, 1, 1, 1, 1, 1, 5], [1, 1, 1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 1, 2, 4], [1, 1, 1, 1, 1, 1, 3, 3], [1, 1, 1, 1, 1, 1, 6], [1, 1, 1, 1, 1, 2, 2, 3], [1, 1, 1, 1, 1, 2, 5], [1, 1, 1, 1, 1, 3, 4], [1, 1, 1, 1, 1, 7], [1, 1, 1, 1, 2, 2, 2, 2], [1, 1, 1, 1, 2, 2, 4], [1, 1, 1, 1, 2, 3, 3], [1, 1, 1, 1, 2, 6], [1, 1, 1, 1, 3, 5], [1, 1, 1, 1, 4, 4], [1, 1, 1, 1, 8], [1, 1, 1, 2, 2, 2, 3], [1, 1, 1, 2, 2, 5], [1, 1, 1, 2, 3, 4], [1, 1, 1, 2, 7], [1, 1, 1, 3, 3, 3], [1, 1, 1, 3, 6], [1, 1, 1, 4, 5], [1, 1, 1, 9], [1, 1, 2, 2, 2, 2, 2], [1, 1, 2, 2, 2, 4], [1, 1, 2, 2, 3, 3], [1, 1, 2, 2, 6], [1, 1, 2, 3, 5], [1, 1, 2, 4, 4], [1, 1, 2, 8], [1, 1, 3, 3, 4], [1, 1, 3, 7], [1, 1, 4, 6], [1, 1, 5, 5], [1, 1, 10], [1, 2, 2, 2, 2, 3], [1, 2, 2, 2, 5], [1, 2, 2, 3, 4], [1, 2, 2, 7], [1, 2, 3, 3, 3], [1, 2, 3, 6], [1, 2, 4, 5], [1, 2, 9], [1, 3, 3, 5], [1, 3, 4, 4], [1, 3, 8], [1, 4, 7], [1, 5, 6], [1, 11], [2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 4], [2, 2, 2, 3, 3], [2, 2, 2, 6], [2, 2, 3, 5], [2, 2, 4, 4], [2, 2, 8], [2, 3, 3, 4], [2, 3, 7], [2, 4, 6], [2, 5, 5], [2, 10], [3, 3, 3, 3], [3, 3, 6], [3, 4, 5], [3, 9], [4, 4, 4], [4, 8], [5, 7], [6, 6], [12]] if n == 13: return [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 4], [1, 1, 1, 1, 1, 1, 1, 1, 2, 3], [1, 1, 1, 1, 1, 1, 1, 1, 5], [1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 2, 4], [1, 1, 1, 1, 1, 1, 1, 3, 3], [1, 1, 1, 1, 1, 1, 1, 6], [1, 1, 1, 1, 1, 1, 2, 2, 3], [1, 1, 1, 1, 1, 1, 2, 5], [1, 1, 1, 1, 1, 1, 3, 4], [1, 1, 1, 1, 1, 1, 7], [1, 1, 1, 1, 1, 2, 2, 2, 2], [1, 1, 1, 1, 1, 2, 2, 4], [1, 1, 1, 1, 1, 2, 3, 3], [1, 1, 1, 1, 1, 2, 6], [1, 1, 1, 1, 1, 3, 5], [1, 1, 1, 1, 1, 4, 4], [1, 1, 1, 1, 1, 8], [1, 1, 1, 1, 2, 2, 2, 3], [1, 1, 1, 1, 2, 2, 5], [1, 1, 1, 1, 2, 3, 4], [1, 1, 1, 1, 2, 7], [1, 1, 1, 1, 3, 3, 3], [1, 1, 1, 1, 3, 6], [1, 1, 1, 1, 4, 5], [1, 1, 1, 1, 9], [1, 1, 1, 2, 2, 2, 2, 2], [1, 1, 1, 2, 2, 2, 4], [1, 1, 1, 2, 2, 3, 3], [1, 1, 1, 2, 2, 6], [1, 1, 1, 2, 3, 5], [1, 1, 1, 2, 4, 4], [1, 1, 1, 2, 8], [1, 1, 1, 3, 3, 4], [1, 1, 1, 3, 7], [1, 1, 1, 4, 6], [1, 1, 1, 5, 5], [1, 1, 1, 10], [1, 1, 2, 2, 2, 2, 3], [1, 1, 2, 2, 2, 5], [1, 1, 2, 2, 3, 4], [1, 1, 2, 2, 7], [1, 1, 2, 3, 3, 3], [1, 1, 2, 3, 6], [1, 1, 2, 4, 5], [1, 1, 2, 9], [1, 1, 3, 3, 5], [1, 1, 3, 4, 4], [1, 1, 3, 8], [1, 1, 4, 7], [1, 1, 5, 6], [1, 1, 11], [1, 2, 2, 2, 2, 2, 2], [1, 2, 2, 2, 2, 4], [1, 2, 2, 2, 3, 3], [1, 2, 2, 2, 6], [1, 2, 2, 3, 5], [1, 2, 2, 4, 4], [1, 2, 2, 8], [1, 2, 3, 3, 4], [1, 2, 3, 7], [1, 2, 4, 6], [1, 2, 5, 5], [1, 2, 10], [1, 3, 3, 3, 3], [1, 3, 3, 6], [1, 3, 4, 5], [1, 3, 9], [1, 4, 4, 4], [1, 4, 8], [1, 5, 7], [1, 6, 6], [1, 12], [2, 2, 2, 2, 2, 3], [2, 2, 2, 2, 5], [2, 2, 2, 3, 4], [2, 2, 2, 7], [2, 2, 3, 3, 3], [2, 2, 3, 6], [2, 2, 4, 5], [2, 2, 9], [2, 3, 3, 5], [2, 3, 4, 4], [2, 3, 8], [2, 4, 7], [2, 5, 6], [2, 11], [3, 3, 3, 4], [3, 3, 7], [3, 4, 6], [3, 5, 5], [3, 10], [4, 4, 5], [4, 9], [5, 8], [6, 7], [13]] if n == 14: return [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 5], [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 2, 4], [1, 1, 1, 1, 1, 1, 1, 1, 3, 3], [1, 1, 1, 1, 1, 1, 1, 1, 6], [1, 1, 1, 1, 1, 1, 1, 2, 2, 3], [1, 1, 1, 1, 1, 1, 1, 2, 5], [1, 1, 1, 1, 1, 1, 1, 3, 4], [1, 1, 1, 1, 1, 1, 1, 7], [1, 1, 1, 1, 1, 1, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1, 2, 2, 4], [1, 1, 1, 1, 1, 1, 2, 3, 3], [1, 1, 1, 1, 1, 1, 2, 6], [1, 1, 1, 1, 1, 1, 3, 5], [1, 1, 1, 1, 1, 1, 4, 4], [1, 1, 1, 1, 1, 1, 8], [1, 1, 1, 1, 1, 2, 2, 2, 3], [1, 1, 1, 1, 1, 2, 2, 5], [1, 1, 1, 1, 1, 2, 3, 4], [1, 1, 1, 1, 1, 2, 7], [1, 1, 1, 1, 1, 3, 3, 3], [1, 1, 1, 1, 1, 3, 6], [1, 1, 1, 1, 1, 4, 5], [1, 1, 1, 1, 1, 9], [1, 1, 1, 1, 2, 2, 2, 2, 2], [1, 1, 1, 1, 2, 2, 2, 4], [1, 1, 1, 1, 2, 2, 3, 3], [1, 1, 1, 1, 2, 2, 6], [1, 1, 1, 1, 2, 3, 5], [1, 1, 1, 1, 2, 4, 4], [1, 1, 1, 1, 2, 8], [1, 1, 1, 1, 3, 3, 4], [1, 1, 1, 1, 3, 7], [1, 1, 1, 1, 4, 6], [1, 1, 1, 1, 5, 5], [1, 1, 1, 1, 10], [1, 1, 1, 2, 2, 2, 2, 3], [1, 1, 1, 2, 2, 2, 5], [1, 1, 1, 2, 2, 3, 4], [1, 1, 1, 2, 2, 7], [1, 1, 1, 2, 3, 3, 3], [1, 1, 1, 2, 3, 6], [1, 1, 1, 2, 4, 5], [1, 1, 1, 2, 9], [1, 1, 1, 3, 3, 5], [1, 1, 1, 3, 4, 4], [1, 1, 1, 3, 8], [1, 1, 1, 4, 7], [1, 1, 1, 5, 6], [1, 1, 1, 11], [1, 1, 2, 2, 2, 2, 2, 2], [1, 1, 2, 2, 2, 2, 4], [1, 1, 2, 2, 2, 3, 3], [1, 1, 2, 2, 2, 6], [1, 1, 2, 2, 3, 5], [1, 1, 2, 2, 4, 4], [1, 1, 2, 2, 8], [1, 1, 2, 3, 3, 4], [1, 1, 2, 3, 7], [1, 1, 2, 4, 6], [1, 1, 2, 5, 5], [1, 1, 2, 10], [1, 1, 3, 3, 3, 3], [1, 1, 3, 3, 6], [1, 1, 3, 4, 5], [1, 1, 3, 9], [1, 1, 4, 4, 4], [1, 1, 4, 8], [1, 1, 5, 7], [1, 1, 6, 6], [1, 1, 12], [1, 2, 2, 2, 2, 2, 3], [1, 2, 2, 2, 2, 5], [1, 2, 2, 2, 3, 4], [1, 2, 2, 2, 7], [1, 2, 2, 3, 3, 3], [1, 2, 2, 3, 6], [1, 2, 2, 4, 5], [1, 2, 2, 9], [1, 2, 3, 3, 5], [1, 2, 3, 4, 4], [1, 2, 3, 8], [1, 2, 4, 7], [1, 2, 5, 6], [1, 2, 11], [1, 3, 3, 3, 4], [1, 3, 3, 7], [1, 3, 4, 6], [1, 3, 5, 5], [1, 3, 10], [1, 4, 4, 5], [1, 4, 9], [1, 5, 8], [1, 6, 7], [1, 13], [2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 4], [2, 2, 2, 2, 3, 3], [2, 2, 2, 2, 6], [2, 2, 2, 3, 5], [2, 2, 2, 4, 4], [2, 2, 2, 8], [2, 2, 3, 3, 4], [2, 2, 3, 7], [2, 2, 4, 6], [2, 2, 5, 5], [2, 2, 10], [2, 3, 3, 3, 3], [2, 3, 3, 6], [2, 3, 4, 5], [2, 3, 9], [2, 4, 4, 4], [2, 4, 8], [2, 5, 7], [2, 6, 6], [2, 12], [3, 3, 3, 5], [3, 3, 4, 4], [3, 3, 8], [3, 4, 7], [3, 5, 6], [3, 11], [4, 4, 6], [4, 5, 5], [4, 10], [5, 9], [6, 8], [7, 7], [14]] if n == 15: return [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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5], [1, 1, 1, 1, 2, 2, 3, 4], [1, 1, 1, 1, 2, 2, 7], [1, 1, 1, 1, 2, 3, 3, 3], [1, 1, 1, 1, 2, 3, 6], [1, 1, 1, 1, 2, 4, 5], [1, 1, 1, 1, 2, 9], [1, 1, 1, 1, 3, 3, 5], [1, 1, 1, 1, 3, 4, 4], [1, 1, 1, 1, 3, 8], [1, 1, 1, 1, 4, 7], [1, 1, 1, 1, 5, 6], [1, 1, 1, 1, 11], [1, 1, 1, 2, 2, 2, 2, 2, 2], [1, 1, 1, 2, 2, 2, 2, 4], [1, 1, 1, 2, 2, 2, 3, 3], [1, 1, 1, 2, 2, 2, 6], [1, 1, 1, 2, 2, 3, 5], [1, 1, 1, 2, 2, 4, 4], [1, 1, 1, 2, 2, 8], [1, 1, 1, 2, 3, 3, 4], [1, 1, 1, 2, 3, 7], [1, 1, 1, 2, 4, 6], [1, 1, 1, 2, 5, 5], [1, 1, 1, 2, 10], [1, 1, 1, 3, 3, 3, 3], [1, 1, 1, 3, 3, 6], [1, 1, 1, 3, 4, 5], [1, 1, 1, 3, 9], [1, 1, 1, 4, 4, 4], [1, 1, 1, 4, 8], [1, 1, 1, 5, 7], [1, 1, 1, 6, 6], [1, 1, 1, 12], [1, 1, 2, 2, 2, 2, 2, 3], [1, 1, 2, 2, 2, 2, 5], [1, 1, 2, 2, 2, 3, 4], [1, 1, 2, 2, 2, 7], [1, 1, 2, 2, 3, 3, 3], [1, 1, 2, 2, 3, 6], [1, 1, 2, 2, 4, 5], [1, 1, 2, 2, 9], [1, 1, 2, 3, 3, 5], [1, 1, 2, 3, 4, 4], [1, 1, 2, 3, 8], [1, 1, 2, 4, 7], [1, 1, 2, 5, 6], [1, 1, 2, 11], [1, 1, 3, 3, 3, 4], [1, 1, 3, 3, 7], [1, 1, 3, 4, 6], [1, 1, 3, 5, 5], [1, 1, 3, 10], [1, 1, 4, 4, 5], [1, 1, 4, 9], [1, 1, 5, 8], [1, 1, 6, 7], [1, 1, 13], [1, 2, 2, 2, 2, 2, 2, 2], [1, 2, 2, 2, 2, 2, 4], [1, 2, 2, 2, 2, 3, 3], [1, 2, 2, 2, 2, 6], [1, 2, 2, 2, 3, 5], [1, 2, 2, 2, 4, 4], [1, 2, 2, 2, 8], [1, 2, 2, 3, 3, 4], [1, 2, 2, 3, 7], [1, 2, 2, 4, 6], [1, 2, 2, 5, 5], [1, 2, 2, 10], [1, 2, 3, 3, 3, 3], [1, 2, 3, 3, 6], [1, 2, 3, 4, 5], [1, 2, 3, 9], [1, 2, 4, 4, 4], [1, 2, 4, 8], [1, 2, 5, 7], [1, 2, 6, 6], [1, 2, 12], [1, 3, 3, 3, 5], [1, 3, 3, 4, 4], [1, 3, 3, 8], [1, 3, 4, 7], [1, 3, 5, 6], [1, 3, 11], [1, 4, 4, 6], [1, 4, 5, 5], [1, 4, 10], [1, 5, 9], [1, 6, 8], [1, 7, 7], [1, 14], [2, 2, 2, 2, 2, 2, 3], [2, 2, 2, 2, 2, 5], [2, 2, 2, 2, 3, 4], [2, 2, 2, 2, 7], [2, 2, 2, 3, 3, 3], [2, 2, 2, 3, 6], [2, 2, 2, 4, 5], [2, 2, 2, 9], [2, 2, 3, 3, 5], [2, 2, 3, 4, 4], [2, 2, 3, 8], [2, 2, 4, 7], [2, 2, 5, 6], [2, 2, 11], [2, 3, 3, 3, 4], [2, 3, 3, 7], [2, 3, 4, 6], [2, 3, 5, 5], [2, 3, 10], [2, 4, 4, 5], [2, 4, 9], [2, 5, 8], [2, 6, 7], [2, 13], [3, 3, 3, 3, 3], [3, 3, 3, 6], [3, 3, 4, 5], [3, 3, 9], [3, 4, 4, 4], [3, 4, 8], [3, 5, 7], [3, 6, 6], [3, 12], [4, 4, 7], [4, 5, 6], [4, 11], [5, 5, 5], [5, 10], [6, 9], [7, 8], [15]] if n == 16: return [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 2, 2, 3], [1, 1, 1, 2, 2, 2, 2, 5], [1, 1, 1, 2, 2, 2, 3, 4], [1, 1, 1, 2, 2, 2, 7], [1, 1, 1, 2, 2, 3, 3, 3], [1, 1, 1, 2, 2, 3, 6], [1, 1, 1, 2, 2, 4, 5], [1, 1, 1, 2, 2, 9], [1, 1, 1, 2, 3, 3, 5], [1, 1, 1, 2, 3, 4, 4], [1, 1, 1, 2, 3, 8], [1, 1, 1, 2, 4, 7], [1, 1, 1, 2, 5, 6], [1, 1, 1, 2, 11], [1, 1, 1, 3, 3, 3, 4], [1, 1, 1, 3, 3, 7], [1, 1, 1, 3, 4, 6], [1, 1, 1, 3, 5, 5], [1, 1, 1, 3, 10], [1, 1, 1, 4, 4, 5], [1, 1, 1, 4, 9], [1, 1, 1, 5, 8], [1, 1, 1, 6, 7], [1, 1, 1, 13], [1, 1, 2, 2, 2, 2, 2, 2, 2], [1, 1, 2, 2, 2, 2, 2, 4], [1, 1, 2, 2, 2, 2, 3, 3], [1, 1, 2, 2, 2, 2, 6], [1, 1, 2, 2, 2, 3, 5], [1, 1, 2, 2, 2, 4, 4], [1, 1, 2, 2, 2, 8], [1, 1, 2, 2, 3, 3, 4], [1, 1, 2, 2, 3, 7], [1, 1, 2, 2, 4, 6], [1, 1, 2, 2, 5, 5], [1, 1, 2, 2, 10], [1, 1, 2, 3, 3, 3, 3], [1, 1, 2, 3, 3, 6], [1, 1, 2, 3, 4, 5], [1, 1, 2, 3, 9], [1, 1, 2, 4, 4, 4], [1, 1, 2, 4, 8], [1, 1, 2, 5, 7], [1, 1, 2, 6, 6], [1, 1, 2, 12], [1, 1, 3, 3, 3, 5], [1, 1, 3, 3, 4, 4], [1, 1, 3, 3, 8], [1, 1, 3, 4, 7], [1, 1, 3, 5, 6], [1, 1, 3, 11], [1, 1, 4, 4, 6], [1, 1, 4, 5, 5], [1, 1, 4, 10], [1, 1, 5, 9], [1, 1, 6, 8], [1, 1, 7, 7], [1, 1, 14], [1, 2, 2, 2, 2, 2, 2, 3], [1, 2, 2, 2, 2, 2, 5], [1, 2, 2, 2, 2, 3, 4], [1, 2, 2, 2, 2, 7], [1, 2, 2, 2, 3, 3, 3], [1, 2, 2, 2, 3, 6], [1, 2, 2, 2, 4, 5], [1, 2, 2, 2, 9], [1, 2, 2, 3, 3, 5], [1, 2, 2, 3, 4, 4], [1, 2, 2, 3, 8], [1, 2, 2, 4, 7], [1, 2, 2, 5, 6], [1, 2, 2, 11], [1, 2, 3, 3, 3, 4], [1, 2, 3, 3, 7], [1, 2, 3, 4, 6], [1, 2, 3, 5, 5], [1, 2, 3, 10], [1, 2, 4, 4, 5], [1, 2, 4, 9], [1, 2, 5, 8], [1, 2, 6, 7], [1, 2, 13], [1, 3, 3, 3, 3, 3], [1, 3, 3, 3, 6], [1, 3, 3, 4, 5], [1, 3, 3, 9], [1, 3, 4, 4, 4], [1, 3, 4, 8], [1, 3, 5, 7], [1, 3, 6, 6], [1, 3, 12], [1, 4, 4, 7], [1, 4, 5, 6], [1, 4, 11], [1, 5, 5, 5], [1, 5, 10], [1, 6, 9], [1, 7, 8], [1, 15], [2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 4], [2, 2, 2, 2, 2, 3, 3], [2, 2, 2, 2, 2, 6], [2, 2, 2, 2, 3, 5], [2, 2, 2, 2, 4, 4], [2, 2, 2, 2, 8], [2, 2, 2, 3, 3, 4], [2, 2, 2, 3, 7], [2, 2, 2, 4, 6], [2, 2, 2, 5, 5], [2, 2, 2, 10], [2, 2, 3, 3, 3, 3], [2, 2, 3, 3, 6], [2, 2, 3, 4, 5], [2, 2, 3, 9], [2, 2, 4, 4, 4], [2, 2, 4, 8], [2, 2, 5, 7], [2, 2, 6, 6], [2, 2, 12], [2, 3, 3, 3, 5], [2, 3, 3, 4, 4], [2, 3, 3, 8], [2, 3, 4, 7], [2, 3, 5, 6], [2, 3, 11], [2, 4, 4, 6], [2, 4, 5, 5], [2, 4, 10], [2, 5, 9], [2, 6, 8], [2, 7, 7], [2, 14], [3, 3, 3, 3, 4], [3, 3, 3, 7], [3, 3, 4, 6], [3, 3, 5, 5], [3, 3, 10], [3, 4, 4, 5], [3, 4, 9], [3, 5, 8], [3, 6, 7], [3, 13], [4, 4, 4, 4], [4, 4, 8], [4, 5, 7], [4, 6, 6], [4, 12], [5, 5, 6], [5, 11], [6, 10], [7, 9], [8, 8], [16]] if n == 17: return [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 5], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 4], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 6], [1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 5], [1, 1, 1, 1, 1, 1, 1, 1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6, 7], [1, 1, 1, 1, 13], [1, 1, 1, 2, 2, 2, 2, 2, 2, 2], [1, 1, 1, 2, 2, 2, 2, 2, 4], [1, 1, 1, 2, 2, 2, 2, 3, 3], [1, 1, 1, 2, 2, 2, 2, 6], [1, 1, 1, 2, 2, 2, 3, 5], [1, 1, 1, 2, 2, 2, 4, 4], [1, 1, 1, 2, 2, 2, 8], [1, 1, 1, 2, 2, 3, 3, 4], [1, 1, 1, 2, 2, 3, 7], [1, 1, 1, 2, 2, 4, 6], [1, 1, 1, 2, 2, 5, 5], [1, 1, 1, 2, 2, 10], [1, 1, 1, 2, 3, 3, 3, 3], [1, 1, 1, 2, 3, 3, 6], [1, 1, 1, 2, 3, 4, 5], [1, 1, 1, 2, 3, 9], [1, 1, 1, 2, 4, 4, 4], [1, 1, 1, 2, 4, 8], [1, 1, 1, 2, 5, 7], [1, 1, 1, 2, 6, 6], [1, 1, 1, 2, 12], [1, 1, 1, 3, 3, 3, 5], [1, 1, 1, 3, 3, 4, 4], [1, 1, 1, 3, 3, 8], [1, 1, 1, 3, 4, 7], [1, 1, 1, 3, 5, 6], [1, 1, 1, 3, 11], [1, 1, 1, 4, 4, 6], [1, 1, 1, 4, 5, 5], [1, 1, 1, 4, 10], [1, 1, 1, 5, 9], [1, 1, 1, 6, 8], [1, 1, 1, 7, 7], [1, 1, 1, 14], [1, 1, 2, 2, 2, 2, 2, 2, 3], [1, 1, 2, 2, 2, 2, 2, 5], [1, 1, 2, 2, 2, 2, 3, 4], [1, 1, 2, 2, 2, 2, 7], [1, 1, 2, 2, 2, 3, 3, 3], [1, 1, 2, 2, 2, 3, 6], [1, 1, 2, 2, 2, 4, 5], [1, 1, 2, 2, 2, 9], [1, 1, 2, 2, 3, 3, 5], [1, 1, 2, 2, 3, 4, 4], [1, 1, 2, 2, 3, 8], [1, 1, 2, 2, 4, 7], [1, 1, 2, 2, 5, 6], [1, 1, 2, 2, 11], [1, 1, 2, 3, 3, 3, 4], [1, 1, 2, 3, 3, 7], [1, 1, 2, 3, 4, 6], [1, 1, 2, 3, 5, 5], [1, 1, 2, 3, 10], [1, 1, 2, 4, 4, 5], [1, 1, 2, 4, 9], [1, 1, 2, 5, 8], [1, 1, 2, 6, 7], [1, 1, 2, 13], [1, 1, 3, 3, 3, 3, 3], [1, 1, 3, 3, 3, 6], [1, 1, 3, 3, 4, 5], [1, 1, 3, 3, 9], [1, 1, 3, 4, 4, 4], [1, 1, 3, 4, 8], [1, 1, 3, 5, 7], [1, 1, 3, 6, 6], [1, 1, 3, 12], [1, 1, 4, 4, 7], [1, 1, 4, 5, 6], [1, 1, 4, 11], [1, 1, 5, 5, 5], [1, 1, 5, 10], [1, 1, 6, 9], [1, 1, 7, 8], [1, 1, 15], [1, 2, 2, 2, 2, 2, 2, 2, 2], [1, 2, 2, 2, 2, 2, 2, 4], [1, 2, 2, 2, 2, 2, 3, 3], [1, 2, 2, 2, 2, 2, 6], [1, 2, 2, 2, 2, 3, 5], [1, 2, 2, 2, 2, 4, 4], [1, 2, 2, 2, 2, 8], [1, 2, 2, 2, 3, 3, 4], [1, 2, 2, 2, 3, 7], [1, 2, 2, 2, 4, 6], [1, 2, 2, 2, 5, 5], [1, 2, 2, 2, 10], [1, 2, 2, 3, 3, 3, 3], [1, 2, 2, 3, 3, 6], [1, 2, 2, 3, 4, 5], [1, 2, 2, 3, 9], [1, 2, 2, 4, 4, 4], [1, 2, 2, 4, 8], [1, 2, 2, 5, 7], [1, 2, 2, 6, 6], [1, 2, 2, 12], [1, 2, 3, 3, 3, 5], [1, 2, 3, 3, 4, 4], [1, 2, 3, 3, 8], [1, 2, 3, 4, 7], [1, 2, 3, 5, 6], [1, 2, 3, 11], [1, 2, 4, 4, 6], [1, 2, 4, 5, 5], [1, 2, 4, 10], [1, 2, 5, 9], [1, 2, 6, 8], [1, 2, 7, 7], [1, 2, 14], [1, 3, 3, 3, 3, 4], [1, 3, 3, 3, 7], [1, 3, 3, 4, 6], [1, 3, 3, 5, 5], [1, 3, 3, 10], [1, 3, 4, 4, 5], [1, 3, 4, 9], [1, 3, 5, 8], [1, 3, 6, 7], [1, 3, 13], [1, 4, 4, 4, 4], [1, 4, 4, 8], [1, 4, 5, 7], [1, 4, 6, 6], [1, 4, 12], [1, 5, 5, 6], [1, 5, 11], [1, 6, 10], [1, 7, 9], [1, 8, 8], [1, 16], [2, 2, 2, 2, 2, 2, 2, 3], [2, 2, 2, 2, 2, 2, 5], [2, 2, 2, 2, 2, 3, 4], [2, 2, 2, 2, 2, 7], [2, 2, 2, 2, 3, 3, 3], [2, 2, 2, 2, 3, 6], [2, 2, 2, 2, 4, 5], [2, 2, 2, 2, 9], [2, 2, 2, 3, 3, 5], [2, 2, 2, 3, 4, 4], [2, 2, 2, 3, 8], [2, 2, 2, 4, 7], [2, 2, 2, 5, 6], [2, 2, 2, 11], [2, 2, 3, 3, 3, 4], [2, 2, 3, 3, 7], [2, 2, 3, 4, 6], [2, 2, 3, 5, 5], [2, 2, 3, 10], [2, 2, 4, 4, 5], [2, 2, 4, 9], [2, 2, 5, 8], [2, 2, 6, 7], [2, 2, 13], [2, 3, 3, 3, 3, 3], [2, 3, 3, 3, 6], [2, 3, 3, 4, 5], [2, 3, 3, 9], [2, 3, 4, 4, 4], [2, 3, 4, 8], [2, 3, 5, 7], [2, 3, 6, 6], [2, 3, 12], [2, 4, 4, 7], [2, 4, 5, 6], [2, 4, 11], [2, 5, 5, 5], [2, 5, 10], [2, 6, 9], [2, 7, 8], [2, 15], [3, 3, 3, 3, 5], [3, 3, 3, 4, 4], [3, 3, 3, 8], [3, 3, 4, 7], [3, 3, 5, 6], [3, 3, 11], [3, 4, 4, 6], [3, 4, 5, 5], [3, 4, 10], [3, 5, 9], [3, 6, 8], [3, 7, 7], [3, 14], [4, 4, 4, 5], [4, 4, 9], [4, 5, 8], [4, 6, 7], [4, 13], [5, 5, 7], [5, 6, 6], [5, 12], [6, 11], [7, 10], [8, 9], [17]] if n == 18: return [[1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 1, 2, 2, 2, 4, 5], [1, 1, 1, 2, 2, 2, 9], [1, 1, 1, 2, 2, 3, 3, 5], [1, 1, 1, 2, 2, 3, 4, 4], [1, 1, 1, 2, 2, 3, 8], [1, 1, 1, 2, 2, 4, 7], [1, 1, 1, 2, 2, 5, 6], [1, 1, 1, 2, 2, 11], [1, 1, 1, 2, 3, 3, 3, 4], [1, 1, 1, 2, 3, 3, 7], [1, 1, 1, 2, 3, 4, 6], [1, 1, 1, 2, 3, 5, 5], [1, 1, 1, 2, 3, 10], [1, 1, 1, 2, 4, 4, 5], [1, 1, 1, 2, 4, 9], [1, 1, 1, 2, 5, 8], [1, 1, 1, 2, 6, 7], [1, 1, 1, 2, 13], [1, 1, 1, 3, 3, 3, 3, 3], [1, 1, 1, 3, 3, 3, 6], [1, 1, 1, 3, 3, 4, 5], [1, 1, 1, 3, 3, 9], [1, 1, 1, 3, 4, 4, 4], [1, 1, 1, 3, 4, 8], [1, 1, 1, 3, 5, 7], [1, 1, 1, 3, 6, 6], [1, 1, 1, 3, 12], [1, 1, 1, 4, 4, 7], [1, 1, 1, 4, 5, 6], [1, 1, 1, 4, 11], [1, 1, 1, 5, 5, 5], [1, 1, 1, 5, 10], [1, 1, 1, 6, 9], [1, 1, 1, 7, 8], [1, 1, 1, 15], [1, 1, 2, 2, 2, 2, 2, 2, 2, 2], [1, 1, 2, 2, 2, 2, 2, 2, 4], [1, 1, 2, 2, 2, 2, 2, 3, 3], [1, 1, 2, 2, 2, 2, 2, 6], [1, 1, 2, 2, 2, 2, 3, 5], [1, 1, 2, 2, 2, 2, 4, 4], [1, 1, 2, 2, 2, 2, 8], [1, 1, 2, 2, 2, 3, 3, 4], [1, 1, 2, 2, 2, 3, 7], [1, 1, 2, 2, 2, 4, 6], [1, 1, 2, 2, 2, 5, 5], [1, 1, 2, 2, 2, 10], [1, 1, 2, 2, 3, 3, 3, 3], [1, 1, 2, 2, 3, 3, 6], [1, 1, 2, 2, 3, 4, 5], [1, 1, 2, 2, 3, 9], [1, 1, 2, 2, 4, 4, 4], [1, 1, 2, 2, 4, 8], [1, 1, 2, 2, 5, 7], [1, 1, 2, 2, 6, 6], [1, 1, 2, 2, 12], [1, 1, 2, 3, 3, 3, 5], [1, 1, 2, 3, 3, 4, 4], [1, 1, 2, 3, 3, 8], [1, 1, 2, 3, 4, 7], [1, 1, 2, 3, 5, 6], [1, 1, 2, 3, 11], [1, 1, 2, 4, 4, 6], [1, 1, 2, 4, 5, 5], [1, 1, 2, 4, 10], [1, 1, 2, 5, 9], [1, 1, 2, 6, 8], [1, 1, 2, 7, 7], [1, 1, 2, 14], [1, 1, 3, 3, 3, 3, 4], [1, 1, 3, 3, 3, 7], [1, 1, 3, 3, 4, 6], [1, 1, 3, 3, 5, 5], [1, 1, 3, 3, 10], [1, 1, 3, 4, 4, 5], [1, 1, 3, 4, 9], [1, 1, 3, 5, 8], [1, 1, 3, 6, 7], [1, 1, 3, 13], [1, 1, 4, 4, 4, 4], [1, 1, 4, 4, 8], [1, 1, 4, 5, 7], [1, 1, 4, 6, 6], [1, 1, 4, 12], [1, 1, 5, 5, 6], [1, 1, 5, 11], [1, 1, 6, 10], [1, 1, 7, 9], [1, 1, 8, 8], [1, 1, 16], [1, 2, 2, 2, 2, 2, 2, 2, 3], [1, 2, 2, 2, 2, 2, 2, 5], [1, 2, 2, 2, 2, 2, 3, 4], [1, 2, 2, 2, 2, 2, 7], [1, 2, 2, 2, 2, 3, 3, 3], [1, 2, 2, 2, 2, 3, 6], [1, 2, 2, 2, 2, 4, 5], [1, 2, 2, 2, 2, 9], [1, 2, 2, 2, 3, 3, 5], [1, 2, 2, 2, 3, 4, 4], [1, 2, 2, 2, 3, 8], [1, 2, 2, 2, 4, 7], [1, 2, 2, 2, 5, 6], [1, 2, 2, 2, 11], [1, 2, 2, 3, 3, 3, 4], [1, 2, 2, 3, 3, 7], [1, 2, 2, 3, 4, 6], [1, 2, 2, 3, 5, 5], [1, 2, 2, 3, 10], [1, 2, 2, 4, 4, 5], [1, 2, 2, 4, 9], [1, 2, 2, 5, 8], [1, 2, 2, 6, 7], [1, 2, 2, 13], [1, 2, 3, 3, 3, 3, 3], [1, 2, 3, 3, 3, 6], [1, 2, 3, 3, 4, 5], [1, 2, 3, 3, 9], [1, 2, 3, 4, 4, 4], [1, 2, 3, 4, 8], [1, 2, 3, 5, 7], [1, 2, 3, 6, 6], [1, 2, 3, 12], [1, 2, 4, 4, 7], [1, 2, 4, 5, 6], [1, 2, 4, 11], [1, 2, 5, 5, 5], [1, 2, 5, 10], [1, 2, 6, 9], [1, 2, 7, 8], [1, 2, 15], [1, 3, 3, 3, 3, 5], [1, 3, 3, 3, 4, 4], [1, 3, 3, 3, 8], [1, 3, 3, 4, 7], [1, 3, 3, 5, 6], [1, 3, 3, 11], [1, 3, 4, 4, 6], [1, 3, 4, 5, 5], [1, 3, 4, 10], [1, 3, 5, 9], [1, 3, 6, 8], [1, 3, 7, 7], [1, 3, 14], [1, 4, 4, 4, 5], [1, 4, 4, 9], [1, 4, 5, 8], [1, 4, 6, 7], [1, 4, 13], [1, 5, 5, 7], [1, 5, 6, 6], [1, 5, 12], [1, 6, 11], [1, 7, 10], [1, 8, 9], [1, 17], [2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 4], [2, 2, 2, 2, 2, 2, 3, 3], [2, 2, 2, 2, 2, 2, 6], [2, 2, 2, 2, 2, 3, 5], [2, 2, 2, 2, 2, 4, 4], [2, 2, 2, 2, 2, 8], [2, 2, 2, 2, 3, 3, 4], [2, 2, 2, 2, 3, 7], [2, 2, 2, 2, 4, 6], [2, 2, 2, 2, 5, 5], [2, 2, 2, 2, 10], [2, 2, 2, 3, 3, 3, 3], [2, 2, 2, 3, 3, 6], [2, 2, 2, 3, 4, 5], [2, 2, 2, 3, 9], [2, 2, 2, 4, 4, 4], [2, 2, 2, 4, 8], [2, 2, 2, 5, 7], [2, 2, 2, 6, 6], [2, 2, 2, 12], [2, 2, 3, 3, 3, 5], [2, 2, 3, 3, 4, 4], [2, 2, 3, 3, 8], [2, 2, 3, 4, 7], [2, 2, 3, 5, 6], [2, 2, 3, 11], [2, 2, 4, 4, 6], [2, 2, 4, 5, 5], [2, 2, 4, 10], [2, 2, 5, 9], [2, 2, 6, 8], [2, 2, 7, 7], [2, 2, 14], [2, 3, 3, 3, 3, 4], [2, 3, 3, 3, 7], [2, 3, 3, 4, 6], [2, 3, 3, 5, 5], [2, 3, 3, 10], [2, 3, 4, 4, 5], [2, 3, 4, 9], [2, 3, 5, 8], [2, 3, 6, 7], [2, 3, 13], [2, 4, 4, 4, 4], [2, 4, 4, 8], [2, 4, 5, 7], [2, 4, 6, 6], [2, 4, 12], [2, 5, 5, 6], [2, 5, 11], [2, 6, 10], [2, 7, 9], [2, 8, 8], [2, 16], [3, 3, 3, 3, 3, 3], [3, 3, 3, 3, 6], [3, 3, 3, 4, 5], [3, 3, 3, 9], [3, 3, 4, 4, 4], [3, 3, 4, 8], [3, 3, 5, 7], [3, 3, 6, 6], [3, 3, 12], [3, 4, 4, 7], [3, 4, 5, 6], [3, 4, 11], [3, 5, 5, 5], [3, 5, 10], [3, 6, 9], [3, 7, 8], [3, 15], [4, 4, 4, 6], [4, 4, 5, 5], [4, 4, 10], [4, 5, 9], [4, 6, 8], [4, 7, 7], [4, 14], [5, 5, 8], [5, 6, 7], [5, 13], [6, 6, 6], [6, 12], [7, 11], [8, 10], [9, 9], [18]] if n == 19: return [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4], [1, 1, 1, 1, 1, 1,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, 2, 3, 3], [1, 1, 1, 2, 2, 2, 2, 2, 6], [1, 1, 1, 2, 2, 2, 2, 3, 5], [1, 1, 1, 2, 2, 2, 2, 4, 4], [1, 1, 1, 2, 2, 2, 2, 8], [1, 1, 1, 2, 2, 2, 3, 3, 4], [1, 1, 1, 2, 2, 2, 3, 7], [1, 1, 1, 2, 2, 2, 4, 6], [1, 1, 1, 2, 2, 2, 5, 5], [1, 1, 1, 2, 2, 2, 10], [1, 1, 1, 2, 2, 3, 3, 3, 3], [1, 1, 1, 2, 2, 3, 3, 6], [1, 1, 1, 2, 2, 3, 4, 5], [1, 1, 1, 2, 2, 3, 9], [1, 1, 1, 2, 2, 4, 4, 4], [1, 1, 1, 2, 2, 4, 8], [1, 1, 1, 2, 2, 5, 7], [1, 1, 1, 2, 2, 6, 6], [1, 1, 1, 2, 2, 12], [1, 1, 1, 2, 3, 3, 3, 5], [1, 1, 1, 2, 3, 3, 4, 4], [1, 1, 1, 2, 3, 3, 8], [1, 1, 1, 2, 3, 4, 7], [1, 1, 1, 2, 3, 5, 6], [1, 1, 1, 2, 3, 11], [1, 1, 1, 2, 4, 4, 6], [1, 1, 1, 2, 4, 5, 5], [1, 1, 1, 2, 4, 10], [1, 1, 1, 2, 5, 9], [1, 1, 1, 2, 6, 8], [1, 1, 1, 2, 7, 7], [1, 1, 1, 2, 14], [1, 1, 1, 3, 3, 3, 3, 4], [1, 1, 1, 3, 3, 3, 7], [1, 1, 1, 3, 3, 4, 6], [1, 1, 1, 3, 3, 5, 5], [1, 1, 1, 3, 3, 10], [1, 1, 1, 3, 4, 4, 5], [1, 1, 1, 3, 4, 9], [1, 1, 1, 3, 5, 8], [1, 1, 1, 3, 6, 7], [1, 1, 1, 3, 13], [1, 1, 1, 4, 4, 4, 4], [1, 1, 1, 4, 4, 8], [1, 1, 1, 4, 5, 7], [1, 1, 1, 4, 6, 6], [1, 1, 1, 4, 12], [1, 1, 1, 5, 5, 6], [1, 1, 1, 5, 11], [1, 1, 1, 6, 10], [1, 1, 1, 7, 9], [1, 1, 1, 8, 8], [1, 1, 1, 16], [1, 1, 2, 2, 2, 2, 2, 2, 2, 3], [1, 1, 2, 2, 2, 2, 2, 2, 5], [1, 1, 2, 2, 2, 2, 2, 3, 4], [1, 1, 2, 2, 2, 2, 2, 7], [1, 1, 2, 2, 2, 2, 3, 3, 3], [1, 1, 2, 2, 2, 2, 3, 6], [1, 1, 2, 2, 2, 2, 4, 5], [1, 1, 2, 2, 2, 2, 9], [1, 1, 2, 2, 2, 3, 3, 5], [1, 1, 2, 2, 2, 3, 4, 4], [1, 1, 2, 2, 2, 3, 8], [1, 1, 2, 2, 2, 4, 7], [1, 1, 2, 2, 2, 5, 6], [1, 1, 2, 2, 2, 11], [1, 1, 2, 2, 3, 3, 3, 4], [1, 1, 2, 2, 3, 3, 7], [1, 1, 2, 2, 3, 4, 6], [1, 1, 2, 2, 3, 5, 5], [1, 1, 2, 2, 3, 10], [1, 1, 2, 2, 4, 4, 5], [1, 1, 2, 2, 4, 9], [1, 1, 2, 2, 5, 8], [1, 1, 2, 2, 6, 7], [1, 1, 2, 2, 13], [1, 1, 2, 3, 3, 3, 3, 3], [1, 1, 2, 3, 3, 3, 6], [1, 1, 2, 3, 3, 4, 5], [1, 1, 2, 3, 3, 9], [1, 1, 2, 3, 4, 4, 4], [1, 1, 2, 3, 4, 8], [1, 1, 2, 3, 5, 7], [1, 1, 2, 3, 6, 6], [1, 1, 2, 3, 12], [1, 1, 2, 4, 4, 7], [1, 1, 2, 4, 5, 6], [1, 1, 2, 4, 11], [1, 1, 2, 5, 5, 5], [1, 1, 2, 5, 10], [1, 1, 2, 6, 9], [1, 1, 2, 7, 8], [1, 1, 2, 15], [1, 1, 3, 3, 3, 3, 5], [1, 1, 3, 3, 3, 4, 4], [1, 1, 3, 3, 3, 8], [1, 1, 3, 3, 4, 7], [1, 1, 3, 3, 5, 6], [1, 1, 3, 3, 11], [1, 1, 3, 4, 4, 6], [1, 1, 3, 4, 5, 5], [1, 1, 3, 4, 10], [1, 1, 3, 5, 9], [1, 1, 3, 6, 8], [1, 1, 3, 7, 7], [1, 1, 3, 14], [1, 1, 4, 4, 4, 5], [1, 1, 4, 4, 9], [1, 1, 4, 5, 8], [1, 1, 4, 6, 7], [1, 1, 4, 13], [1, 1, 5, 5, 7], [1, 1, 5, 6, 6], [1, 1, 5, 12], [1, 1, 6, 11], [1, 1, 7, 10], [1, 1, 8, 9], [1, 1, 17], [1, 2, 2, 2, 2, 2, 2, 2, 2, 2], [1, 2, 2, 2, 2, 2, 2, 2, 4], [1, 2, 2, 2, 2, 2, 2, 3, 3], [1, 2, 2, 2, 2, 2, 2, 6], [1, 2, 2, 2, 2, 2, 3, 5], [1, 2, 2, 2, 2, 2, 4, 4], [1, 2, 2, 2, 2, 2, 8], [1, 2, 2, 2, 2, 3, 3, 4], [1, 2, 2, 2, 2, 3, 7], [1, 2, 2, 2, 2, 4, 6], [1, 2, 2, 2, 2, 5, 5], [1, 2, 2, 2, 2, 10], [1, 2, 2, 2, 3, 3, 3, 3], [1, 2, 2, 2, 3, 3, 6], [1, 2, 2, 2, 3, 4, 5], [1, 2, 2, 2, 3, 9], [1, 2, 2, 2, 4, 4, 4], [1, 2, 2, 2, 4, 8], [1, 2, 2, 2, 5, 7], [1, 2, 2, 2, 6, 6], [1, 2, 2, 2, 12], [1, 2, 2, 3, 3, 3, 5], [1, 2, 2, 3, 3, 4, 4], [1, 2, 2, 3, 3, 8], [1, 2, 2, 3, 4, 7], [1, 2, 2, 3, 5, 6], [1, 2, 2, 3, 11], [1, 2, 2, 4, 4, 6], [1, 2, 2, 4, 5, 5], [1, 2, 2, 4, 10], [1, 2, 2, 5, 9], [1, 2, 2, 6, 8], [1, 2, 2, 7, 7], [1, 2, 2, 14], [1, 2, 3, 3, 3, 3, 4], [1, 2, 3, 3, 3, 7], [1, 2, 3, 3, 4, 6], [1, 2, 3, 3, 5, 5], [1, 2, 3, 3, 10], [1, 2, 3, 4, 4, 5], [1, 2, 3, 4, 9], [1, 2, 3, 5, 8], [1, 2, 3, 6, 7], [1, 2, 3, 13], [1, 2, 4, 4, 4, 4], [1, 2, 4, 4, 8], [1, 2, 4, 5, 7], [1, 2, 4, 6, 6], [1, 2, 4, 12], [1, 2, 5, 5, 6], [1, 2, 5, 11], [1, 2, 6, 10], [1, 2, 7, 9], [1, 2, 8, 8], [1, 2, 16], [1, 3, 3, 3, 3, 3, 3], [1, 3, 3, 3, 3, 6], [1, 3, 3, 3, 4, 5], [1, 3, 3, 3, 9], [1, 3, 3, 4, 4, 4], [1, 3, 3, 4, 8], [1, 3, 3, 5, 7], [1, 3, 3, 6, 6], [1, 3, 3, 12], [1, 3, 4, 4, 7], [1, 3, 4, 5, 6], [1, 3, 4, 11], [1, 3, 5, 5, 5], [1, 3, 5, 10], [1, 3, 6, 9], [1, 3, 7, 8], [1, 3, 15], [1, 4, 4, 4, 6], [1, 4, 4, 5, 5], [1, 4, 4, 10], [1, 4, 5, 9], [1, 4, 6, 8], [1, 4, 7, 7], [1, 4, 14], [1, 5, 5, 8], [1, 5, 6, 7], [1, 5, 13], [1, 6, 6, 6], [1, 6, 12], [1, 7, 11], [1, 8, 10], [1, 9, 9], [1, 18], [2, 2, 2, 2, 2, 2, 2, 2, 3], [2, 2, 2, 2, 2, 2, 2, 5], [2, 2, 2, 2, 2, 2, 3, 4], [2, 2, 2, 2, 2, 2, 7], [2, 2, 2, 2, 2, 3, 3, 3], [2, 2, 2, 2, 2, 3, 6], [2, 2, 2, 2, 2, 4, 5], [2, 2, 2, 2, 2, 9], [2, 2, 2, 2, 3, 3, 5], [2, 2, 2, 2, 3, 4, 4], [2, 2, 2, 2, 3, 8], [2, 2, 2, 2, 4, 7], [2, 2, 2, 2, 5, 6], [2, 2, 2, 2, 11], [2, 2, 2, 3, 3, 3, 4], [2, 2, 2, 3, 3, 7], [2, 2, 2, 3, 4, 6], [2, 2, 2, 3, 5, 5], [2, 2, 2, 3, 10], [2, 2, 2, 4, 4, 5], [2, 2, 2, 4, 9], [2, 2, 2, 5, 8], [2, 2, 2, 6, 7], [2, 2, 2, 13], [2, 2, 3, 3, 3, 3, 3], [2, 2, 3, 3, 3, 6], [2, 2, 3, 3, 4, 5], [2, 2, 3, 3, 9], [2, 2, 3, 4, 4, 4], [2, 2, 3, 4, 8], [2, 2, 3, 5, 7], [2, 2, 3, 6, 6], [2, 2, 3, 12], [2, 2, 4, 4, 7], [2, 2, 4, 5, 6], [2, 2, 4, 11], [2, 2, 5, 5, 5], [2, 2, 5, 10], [2, 2, 6, 9], [2, 2, 7, 8], [2, 2, 15], [2, 3, 3, 3, 3, 5], [2, 3, 3, 3, 4, 4], [2, 3, 3, 3, 8], [2, 3, 3, 4, 7], [2, 3, 3, 5, 6], [2, 3, 3, 11], [2, 3, 4, 4, 6], [2, 3, 4, 5, 5], [2, 3, 4, 10], [2, 3, 5, 9], [2, 3, 6, 8], [2, 3, 7, 7], [2, 3, 14], [2, 4, 4, 4, 5], [2, 4, 4, 9], [2, 4, 5, 8], [2, 4, 6, 7], [2, 4, 13], [2, 5, 5, 7], [2, 5, 6, 6], [2, 5, 12], [2, 6, 11], [2, 7, 10], [2, 8, 9], [2, 17], [3, 3, 3, 3, 3, 4], [3, 3, 3, 3, 7], [3, 3, 3, 4, 6], [3, 3, 3, 5, 5], [3, 3, 3, 10], [3, 3, 4, 4, 5], [3, 3, 4, 9], [3, 3, 5, 8], [3, 3, 6, 7], [3, 3, 13], [3, 4, 4, 4, 4], [3, 4, 4, 8], [3, 4, 5, 7], [3, 4, 6, 6], [3, 4, 12], [3, 5, 5, 6], [3, 5, 11], [3, 6, 10], [3, 7, 9], [3, 8, 8], [3, 16], [4, 4, 4, 7], [4, 4, 5, 6], [4, 4, 11], [4, 5, 5, 5], [4, 5, 10], [4, 6, 9], [4, 7, 8], [4, 15], [5, 5, 9], [5, 6, 8], [5, 7, 7], [5, 14], [6, 6, 7], [6, 13], [7, 12], [8, 11], [9, 10], [19]] if n == 20: return [[1, 1, 1, 1, 1, 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 1, 3, 3, 5, 6], [1, 1, 1, 3, 3, 11], [1, 1, 1, 3, 4, 4, 6], [1, 1, 1, 3, 4, 5, 5], [1, 1, 1, 3, 4, 10], [1, 1, 1, 3, 5, 9], [1, 1, 1, 3, 6, 8], [1, 1, 1, 3, 7, 7], [1, 1, 1, 3, 14], [1, 1, 1, 4, 4, 4, 5], [1, 1, 1, 4, 4, 9], [1, 1, 1, 4, 5, 8], [1, 1, 1, 4, 6, 7], [1, 1, 1, 4, 13], [1, 1, 1, 5, 5, 7], [1, 1, 1, 5, 6, 6], [1, 1, 1, 5, 12], [1, 1, 1, 6, 11], [1, 1, 1, 7, 10], [1, 1, 1, 8, 9], [1, 1, 1, 17], [1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2], [1, 1, 2, 2, 2, 2, 2, 2, 2, 4], [1, 1, 2, 2, 2, 2, 2, 2, 3, 3], [1, 1, 2, 2, 2, 2, 2, 2, 6], [1, 1, 2, 2, 2, 2, 2, 3, 5], [1, 1, 2, 2, 2, 2, 2, 4, 4], [1, 1, 2, 2, 2, 2, 2, 8], [1, 1, 2, 2, 2, 2, 3, 3, 4], [1, 1, 2, 2, 2, 2, 3, 7], [1, 1, 2, 2, 2, 2, 4, 6], [1, 1, 2, 2, 2, 2, 5, 5], [1, 1, 2, 2, 2, 2, 10], [1, 1, 2, 2, 2, 3, 3, 3, 3], [1, 1, 2, 2, 2, 3, 3, 6], [1, 1, 2, 2, 2, 3, 4, 5], [1, 1, 2, 2, 2, 3, 9], [1, 1, 2, 2, 2, 4, 4, 4], [1, 1, 2, 2, 2, 4, 8], [1, 1, 2, 2, 2, 5, 7], [1, 1, 2, 2, 2, 6, 6], [1, 1, 2, 2, 2, 12], [1, 1, 2, 2, 3, 3, 3, 5], [1, 1, 2, 2, 3, 3, 4, 4], [1, 1, 2, 2, 3, 3, 8], [1, 1, 2, 2, 3, 4, 7], [1, 1, 2, 2, 3, 5, 6], [1, 1, 2, 2, 3, 11], [1, 1, 2, 2, 4, 4, 6], [1, 1, 2, 2, 4, 5, 5], [1, 1, 2, 2, 4, 10], [1, 1, 2, 2, 5, 9], [1, 1, 2, 2, 6, 8], [1, 1, 2, 2, 7, 7], [1, 1, 2, 2, 14], [1, 1, 2, 3, 3, 3, 3, 4], [1, 1, 2, 3, 3, 3, 7], [1, 1, 2, 3, 3, 4, 6], [1, 1, 2, 3, 3, 5, 5], [1, 1, 2, 3, 3, 10], [1, 1, 2, 3, 4, 4, 5], [1, 1, 2, 3, 4, 9], [1, 1, 2, 3, 5, 8], [1, 1, 2, 3, 6, 7], [1, 1, 2, 3, 13], [1, 1, 2, 4, 4, 4, 4], [1, 1, 2, 4, 4, 8], [1, 1, 2, 4, 5, 7], [1, 1, 2, 4, 6, 6], [1, 1, 2, 4, 12], [1, 1, 2, 5, 5, 6], [1, 1, 2, 5, 11], [1, 1, 2, 6, 10], [1, 1, 2, 7, 9], [1, 1, 2, 8, 8], [1, 1, 2, 16], [1, 1, 3, 3, 3, 3, 3, 3], [1, 1, 3, 3, 3, 3, 6], [1, 1, 3, 3, 3, 4, 5], [1, 1, 3, 3, 3, 9], [1, 1, 3, 3, 4, 4, 4], [1, 1, 3, 3, 4, 8], [1, 1, 3, 3, 5, 7], [1, 1, 3, 3, 6, 6], [1, 1, 3, 3, 12], [1, 1, 3, 4, 4, 7], [1, 1, 3, 4, 5, 6], [1, 1, 3, 4, 11], [1, 1, 3, 5, 5, 5], [1, 1, 3, 5, 10], [1, 1, 3, 6, 9], [1, 1, 3, 7, 8], [1, 1, 3, 15], [1, 1, 4, 4, 4, 6], [1, 1, 4, 4, 5, 5], [1, 1, 4, 4, 10], [1, 1, 4, 5, 9], [1, 1, 4, 6, 8], [1, 1, 4, 7, 7], [1, 1, 4, 14], [1, 1, 5, 5, 8], [1, 1, 5, 6, 7], [1, 1, 5, 13], [1, 1, 6, 6, 6], [1, 1, 6, 12], [1, 1, 7, 11], [1, 1, 8, 10], [1, 1, 9, 9], [1, 1, 18], [1, 2, 2, 2, 2, 2, 2, 2, 2, 3], [1, 2, 2, 2, 2, 2, 2, 2, 5], [1, 2, 2, 2, 2, 2, 2, 3, 4], [1, 2, 2, 2, 2, 2, 2, 7], [1, 2, 2, 2, 2, 2, 3, 3, 3], [1, 2, 2, 2, 2, 2, 3, 6], [1, 2, 2, 2, 2, 2, 4, 5], [1, 2, 2, 2, 2, 2, 9], [1, 2, 2, 2, 2, 3, 3, 5], [1, 2, 2, 2, 2, 3, 4, 4], [1, 2, 2, 2, 2, 3, 8], [1, 2, 2, 2, 2, 4, 7], [1, 2, 2, 2, 2, 5, 6], [1, 2, 2, 2, 2, 11], [1, 2, 2, 2, 3, 3, 3, 4], [1, 2, 2, 2, 3, 3, 7], [1, 2, 2, 2, 3, 4, 6], [1, 2, 2, 2, 3, 5, 5], [1, 2, 2, 2, 3, 10], [1, 2, 2, 2, 4, 4, 5], [1, 2, 2, 2, 4, 9], [1, 2, 2, 2, 5, 8], [1, 2, 2, 2, 6, 7], [1, 2, 2, 2, 13], [1, 2, 2, 3, 3, 3, 3, 3], [1, 2, 2, 3, 3, 3, 6], [1, 2, 2, 3, 3, 4, 5], [1, 2, 2, 3, 3, 9], [1, 2, 2, 3, 4, 4, 4], [1, 2, 2, 3, 4, 8], [1, 2, 2, 3, 5, 7], [1, 2, 2, 3, 6, 6], [1, 2, 2, 3, 12], [1, 2, 2, 4, 4, 7], [1, 2, 2, 4, 5, 6], [1, 2, 2, 4, 11], [1, 2, 2, 5, 5, 5], [1, 2, 2, 5, 10], [1, 2, 2, 6, 9], [1, 2, 2, 7, 8], [1, 2, 2, 15], [1, 2, 3, 3, 3, 3, 5], [1, 2, 3, 3, 3, 4, 4], [1, 2, 3, 3, 3, 8], [1, 2, 3, 3, 4, 7], [1, 2, 3, 3, 5, 6], [1, 2, 3, 3, 11], [1, 2, 3, 4, 4, 6], [1, 2, 3, 4, 5, 5], [1, 2, 3, 4, 10], [1, 2, 3, 5, 9], [1, 2, 3, 6, 8], [1, 2, 3, 7, 7], [1, 2, 3, 14], [1, 2, 4, 4, 4, 5], [1, 2, 4, 4, 9], [1, 2, 4, 5, 8], [1, 2, 4, 6, 7], [1, 2, 4, 13], [1, 2, 5, 5, 7], [1, 2, 5, 6, 6], [1, 2, 5, 12], [1, 2, 6, 11], [1, 2, 7, 10], [1, 2, 8, 9], [1, 2, 17], [1, 3, 3, 3, 3, 3, 4], [1, 3, 3, 3, 3, 7], [1, 3, 3, 3, 4, 6], [1, 3, 3, 3, 5, 5], [1, 3, 3, 3, 10], [1, 3, 3, 4, 4, 5], [1, 3, 3, 4, 9], [1, 3, 3, 5, 8], [1, 3, 3, 6, 7], [1, 3, 3, 13], [1, 3, 4, 4, 4, 4], [1, 3, 4, 4, 8], [1, 3, 4, 5, 7], [1, 3, 4, 6, 6], [1, 3, 4, 12], [1, 3, 5, 5, 6], [1, 3, 5, 11], [1, 3, 6, 10], [1, 3, 7, 9], [1, 3, 8, 8], [1, 3, 16], [1, 4, 4, 4, 7], [1, 4, 4, 5, 6], [1, 4, 4, 11], [1, 4, 5, 5, 5], [1, 4, 5, 10], [1, 4, 6, 9], [1, 4, 7, 8], [1, 4, 15], [1, 5, 5, 9], [1, 5, 6, 8], [1, 5, 7, 7], [1, 5, 14], [1, 6, 6, 7], [1, 6, 13], [1, 7, 12], [1, 8, 11], [1, 9, 10], [1, 19], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 4], [2, 2, 2, 2, 2, 2, 2, 3, 3], [2, 2, 2, 2, 2, 2, 2, 6], [2, 2, 2, 2, 2, 2, 3, 5], [2, 2, 2, 2, 2, 2, 4, 4], [2, 2, 2, 2, 2, 2, 8], [2, 2, 2, 2, 2, 3, 3, 4], [2, 2, 2, 2, 2, 3, 7], [2, 2, 2, 2, 2, 4, 6], [2, 2, 2, 2, 2, 5, 5], [2, 2, 2, 2, 2, 10], [2, 2, 2, 2, 3, 3, 3, 3], [2, 2, 2, 2, 3, 3, 6], [2, 2, 2, 2, 3, 4, 5], [2, 2, 2, 2, 3, 9], [2, 2, 2, 2, 4, 4, 4], [2, 2, 2, 2, 4, 8], [2, 2, 2, 2, 5, 7], [2, 2, 2, 2, 6, 6], [2, 2, 2, 2, 12], [2, 2, 2, 3, 3, 3, 5], [2, 2, 2, 3, 3, 4, 4], [2, 2, 2, 3, 3, 8], [2, 2, 2, 3, 4, 7], [2, 2, 2, 3, 5, 6], [2, 2, 2, 3, 11], [2, 2, 2, 4, 4, 6], [2, 2, 2, 4, 5, 5], [2, 2, 2, 4, 10], [2, 2, 2, 5, 9], [2, 2, 2, 6, 8], [2, 2, 2, 7, 7], [2, 2, 2, 14], [2, 2, 3, 3, 3, 3, 4], [2, 2, 3, 3, 3, 7], [2, 2, 3, 3, 4, 6], [2, 2, 3, 3, 5, 5], [2, 2, 3, 3, 10], [2, 2, 3, 4, 4, 5], [2, 2, 3, 4, 9], [2, 2, 3, 5, 8], [2, 2, 3, 6, 7], [2, 2, 3, 13], [2, 2, 4, 4, 4, 4], [2, 2, 4, 4, 8], [2, 2, 4, 5, 7], [2, 2, 4, 6, 6], [2, 2, 4, 12], [2, 2, 5, 5, 6], [2, 2, 5, 11], [2, 2, 6, 10], [2, 2, 7, 9], [2, 2, 8, 8], [2, 2, 16], [2, 3, 3, 3, 3, 3, 3], [2, 3, 3, 3, 3, 6], [2, 3, 3, 3, 4, 5], [2, 3, 3, 3, 9], [2, 3, 3, 4, 4, 4], [2, 3, 3, 4, 8], [2, 3, 3, 5, 7], [2, 3, 3, 6, 6], [2, 3, 3, 12], [2, 3, 4, 4, 7], [2, 3, 4, 5, 6], [2, 3, 4, 11], [2, 3, 5, 5, 5], [2, 3, 5, 10], [2, 3, 6, 9], [2, 3, 7, 8], [2, 3, 15], [2, 4, 4, 4, 6], [2, 4, 4, 5, 5], [2, 4, 4, 10], [2, 4, 5, 9], [2, 4, 6, 8], [2, 4, 7, 7], [2, 4, 14], [2, 5, 5, 8], [2, 5, 6, 7], [2, 5, 13], [2, 6, 6, 6], [2, 6, 12], [2, 7, 11], [2, 8, 10], [2, 9, 9], [2, 18], [3, 3, 3, 3, 3, 5], [3, 3, 3, 3, 4, 4], [3, 3, 3, 3, 8], [3, 3, 3, 4, 7], [3, 3, 3, 5, 6], [3, 3, 3, 11], [3, 3, 4, 4, 6], [3, 3, 4, 5, 5], [3, 3, 4, 10], [3, 3, 5, 9], [3, 3, 6, 8], [3, 3, 7, 7], [3, 3, 14], [3, 4, 4, 4, 5], [3, 4, 4, 9], [3, 4, 5, 8], [3, 4, 6, 7], [3, 4, 13], [3, 5, 5, 7], [3, 5, 6, 6], [3, 5, 12], [3, 6, 11], [3, 7, 10], [3, 8, 9], [3, 17], [4, 4, 4, 4, 4], [4, 4, 4, 8], [4, 4, 5, 7], [4, 4, 6, 6], [4, 4, 12], [4, 5, 5, 6], [4, 5, 11], [4, 6, 10], [4, 7, 9], [4, 8, 8], [4, 16], [5, 5, 5, 5], [5, 5, 10], [5, 6, 9], [5, 7, 8], [5, 15], [6, 6, 8], [6, 7, 7], [6, 14], [7, 13], [8, 12], [9, 11], [10, 10], [20]] if n == 21: return [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [1,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1, 1, 2, 5, 11], [1, 1, 1, 2, 6, 10], [1, 1, 1, 2, 7, 9], [1, 1, 1, 2, 8, 8], [1, 1, 1, 2, 16], [1, 1, 1, 3, 3, 3, 3, 3, 3], [1, 1, 1, 3, 3, 3, 3, 6], [1, 1, 1, 3, 3, 3, 4, 5], [1, 1, 1, 3, 3, 3, 9], [1, 1, 1, 3, 3, 4, 4, 4], [1, 1, 1, 3, 3, 4, 8], [1, 1, 1, 3, 3, 5, 7], [1, 1, 1, 3, 3, 6, 6], [1, 1, 1, 3, 3, 12], [1, 1, 1, 3, 4, 4, 7], [1, 1, 1, 3, 4, 5, 6], [1, 1, 1, 3, 4, 11], [1, 1, 1, 3, 5, 5, 5], [1, 1, 1, 3, 5, 10], [1, 1, 1, 3, 6, 9], [1, 1, 1, 3, 7, 8], [1, 1, 1, 3, 15], [1, 1, 1, 4, 4, 4, 6], [1, 1, 1, 4, 4, 5, 5], [1, 1, 1, 4, 4, 10], [1, 1, 1, 4, 5, 9], [1, 1, 1, 4, 6, 8], [1, 1, 1, 4, 7, 7], [1, 1, 1, 4, 14], [1, 1, 1, 5, 5, 8], [1, 1, 1, 5, 6, 7], [1, 1, 1, 5, 13], [1, 1, 1, 6, 6, 6], [1, 1, 1, 6, 12], [1, 1, 1, 7, 11], [1, 1, 1, 8, 10], [1, 1, 1, 9, 9], [1, 1, 1, 18], [1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3], [1, 1, 2, 2, 2, 2, 2, 2, 2, 5], [1, 1, 2, 2, 2, 2, 2, 2, 3, 4], [1, 1, 2, 2, 2, 2, 2, 2, 7], [1, 1, 2, 2, 2, 2, 2, 3, 3, 3], [1, 1, 2, 2, 2, 2, 2, 3, 6], [1, 1, 2, 2, 2, 2, 2, 4, 5], [1, 1, 2, 2, 2, 2, 2, 9], [1, 1, 2, 2, 2, 2, 3, 3, 5], [1, 1, 2, 2, 2, 2, 3, 4, 4], [1, 1, 2, 2, 2, 2, 3, 8], [1, 1, 2, 2, 2, 2, 4, 7], [1, 1, 2, 2, 2, 2, 5, 6], [1, 1, 2, 2, 2, 2, 11], [1, 1, 2, 2, 2, 3, 3, 3, 4], [1, 1, 2, 2, 2, 3, 3, 7], [1, 1, 2, 2, 2, 3, 4, 6], [1, 1, 2, 2, 2, 3, 5, 5], [1, 1, 2, 2, 2, 3, 10], [1, 1, 2, 2, 2, 4, 4, 5], [1, 1, 2, 2, 2, 4, 9], [1, 1, 2, 2, 2, 5, 8], [1, 1, 2, 2, 2, 6, 7], [1, 1, 2, 2, 2, 13], [1, 1, 2, 2, 3, 3, 3, 3, 3], [1, 1, 2, 2, 3, 3, 3, 6], [1, 1, 2, 2, 3, 3, 4, 5], [1, 1, 2, 2, 3, 3, 9], [1, 1, 2, 2, 3, 4, 4, 4], [1, 1, 2, 2, 3, 4, 8], [1, 1, 2, 2, 3, 5, 7], [1, 1, 2, 2, 3, 6, 6], [1, 1, 2, 2, 3, 12], [1, 1, 2, 2, 4, 4, 7], [1, 1, 2, 2, 4, 5, 6], [1, 1, 2, 2, 4, 11], [1, 1, 2, 2, 5, 5, 5], [1, 1, 2, 2, 5, 10], [1, 1, 2, 2, 6, 9], [1, 1, 2, 2, 7, 8], [1, 1, 2, 2, 15], [1, 1, 2, 3, 3, 3, 3, 5], [1, 1, 2, 3, 3, 3, 4, 4], [1, 1, 2, 3, 3, 3, 8], [1, 1, 2, 3, 3, 4, 7], [1, 1, 2, 3, 3, 5, 6], [1, 1, 2, 3, 3, 11], [1, 1, 2, 3, 4, 4, 6], [1, 1, 2, 3, 4, 5, 5], [1, 1, 2, 3, 4, 10], [1, 1, 2, 3, 5, 9], [1, 1, 2, 3, 6, 8], [1, 1, 2, 3, 7, 7], [1, 1, 2, 3, 14], [1, 1, 2, 4, 4, 4, 5], [1, 1, 2, 4, 4, 9], [1, 1, 2, 4, 5, 8], [1, 1, 2, 4, 6, 7], [1, 1, 2, 4, 13], [1, 1, 2, 5, 5, 7], [1, 1, 2, 5, 6, 6], [1, 1, 2, 5, 12], [1, 1, 2, 6, 11], [1, 1, 2, 7, 10], [1, 1, 2, 8, 9], [1, 1, 2, 17], [1, 1, 3, 3, 3, 3, 3, 4], [1, 1, 3, 3, 3, 3, 7], [1, 1, 3, 3, 3, 4, 6], [1, 1, 3, 3, 3, 5, 5], [1, 1, 3, 3, 3, 10], [1, 1, 3, 3, 4, 4, 5], [1, 1, 3, 3, 4, 9], [1, 1, 3, 3, 5, 8], [1, 1, 3, 3, 6, 7], [1, 1, 3, 3, 13], [1, 1, 3, 4, 4, 4, 4], [1, 1, 3, 4, 4, 8], [1, 1, 3, 4, 5, 7], [1, 1, 3, 4, 6, 6], [1, 1, 3, 4, 12], [1, 1, 3, 5, 5, 6], [1, 1, 3, 5, 11], [1, 1, 3, 6, 10], [1, 1, 3, 7, 9], [1, 1, 3, 8, 8], [1, 1, 3, 16], [1, 1, 4, 4, 4, 7], [1, 1, 4, 4, 5, 6], [1, 1, 4, 4, 11], [1, 1, 4, 5, 5, 5], [1, 1, 4, 5, 10], [1, 1, 4, 6, 9], [1, 1, 4, 7, 8], [1, 1, 4, 15], [1, 1, 5, 5, 9], [1, 1, 5, 6, 8], [1, 1, 5, 7, 7], [1, 1, 5, 14], [1, 1, 6, 6, 7], [1, 1, 6, 13], [1, 1, 7, 12], [1, 1, 8, 11], [1, 1, 9, 10], [1, 1, 19], [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [1, 2, 2, 2, 2, 2, 2, 2, 2, 4], [1, 2, 2, 2, 2, 2, 2, 2, 3, 3], [1, 2, 2, 2, 2, 2, 2, 2, 6], [1, 2, 2, 2, 2, 2, 2, 3, 5], [1, 2, 2, 2, 2, 2, 2, 4, 4], [1, 2, 2, 2, 2, 2, 2, 8], [1, 2, 2, 2, 2, 2, 3, 3, 4], [1, 2, 2, 2, 2, 2, 3, 7], [1, 2, 2, 2, 2, 2, 4, 6], [1, 2, 2, 2, 2, 2, 5, 5], [1, 2, 2, 2, 2, 2, 10], [1, 2, 2, 2, 2, 3, 3, 3, 3], [1, 2, 2, 2, 2, 3, 3, 6], [1, 2, 2, 2, 2, 3, 4, 5], [1, 2, 2, 2, 2, 3, 9], [1, 2, 2, 2, 2, 4, 4, 4], [1, 2, 2, 2, 2, 4, 8], [1, 2, 2, 2, 2, 5, 7], [1, 2, 2, 2, 2, 6, 6], [1, 2, 2, 2, 2, 12], [1, 2, 2, 2, 3, 3, 3, 5], [1, 2, 2, 2, 3, 3, 4, 4], [1, 2, 2, 2, 3, 3, 8], [1, 2, 2, 2, 3, 4, 7], [1, 2, 2, 2, 3, 5, 6], [1, 2, 2, 2, 3, 11], [1, 2, 2, 2, 4, 4, 6], [1, 2, 2, 2, 4, 5, 5], [1, 2, 2, 2, 4, 10], [1, 2, 2, 2, 5, 9], [1, 2, 2, 2, 6, 8], [1, 2, 2, 2, 7, 7], [1, 2, 2, 2, 14], [1, 2, 2, 3, 3, 3, 3, 4], [1, 2, 2, 3, 3, 3, 7], [1, 2, 2, 3, 3, 4, 6], [1, 2, 2, 3, 3, 5, 5], [1, 2, 2, 3, 3, 10], [1, 2, 2, 3, 4, 4, 5], [1, 2, 2, 3, 4, 9], [1, 2, 2, 3, 5, 8], [1, 2, 2, 3, 6, 7], [1, 2, 2, 3, 13], [1, 2, 2, 4, 4, 4, 4], [1, 2, 2, 4, 4, 8], [1, 2, 2, 4, 5, 7], [1, 2, 2, 4, 6, 6], [1, 2, 2, 4, 12], [1, 2, 2, 5, 5, 6], [1, 2, 2, 5, 11], [1, 2, 2, 6, 10], [1, 2, 2, 7, 9], [1, 2, 2, 8, 8], [1, 2, 2, 16], [1, 2, 3, 3, 3, 3, 3, 3], [1, 2, 3, 3, 3, 3, 6], [1, 2, 3, 3, 3, 4, 5], [1, 2, 3, 3, 3, 9], [1, 2, 3, 3, 4, 4, 4], [1, 2, 3, 3, 4, 8], [1, 2, 3, 3, 5, 7], [1, 2, 3, 3, 6, 6], [1, 2, 3, 3, 12], [1, 2, 3, 4, 4, 7], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 11], [1, 2, 3, 5, 5, 5], [1, 2, 3, 5, 10], [1, 2, 3, 6, 9], [1, 2, 3, 7, 8], [1, 2, 3, 15], [1, 2, 4, 4, 4, 6], [1, 2, 4, 4, 5, 5], [1, 2, 4, 4, 10], [1, 2, 4, 5, 9], [1, 2, 4, 6, 8], [1, 2, 4, 7, 7], [1, 2, 4, 14], [1, 2, 5, 5, 8], [1, 2, 5, 6, 7], [1, 2, 5, 13], [1, 2, 6, 6, 6], [1, 2, 6, 12], [1, 2, 7, 11], [1, 2, 8, 10], [1, 2, 9, 9], [1, 2, 18], [1, 3, 3, 3, 3, 3, 5], [1, 3, 3, 3, 3, 4, 4], [1, 3, 3, 3, 3, 8], [1, 3, 3, 3, 4, 7], [1, 3, 3, 3, 5, 6], [1, 3, 3, 3, 11], [1, 3, 3, 4, 4, 6], [1, 3, 3, 4, 5, 5], [1, 3, 3, 4, 10], [1, 3, 3, 5, 9], [1, 3, 3, 6, 8], [1, 3, 3, 7, 7], [1, 3, 3, 14], [1, 3, 4, 4, 4, 5], [1, 3, 4, 4, 9], [1, 3, 4, 5, 8], [1, 3, 4, 6, 7], [1, 3, 4, 13], [1, 3, 5, 5, 7], [1, 3, 5, 6, 6], [1, 3, 5, 12], [1, 3, 6, 11], [1, 3, 7, 10], [1, 3, 8, 9], [1, 3, 17], [1, 4, 4, 4, 4, 4], [1, 4, 4, 4, 8], [1, 4, 4, 5, 7], [1, 4, 4, 6, 6], [1, 4, 4, 12], [1, 4, 5, 5, 6], [1, 4, 5, 11], [1, 4, 6, 10], [1, 4, 7, 9], [1, 4, 8, 8], [1, 4, 16], [1, 5, 5, 5, 5], [1, 5, 5, 10], [1, 5, 6, 9], [1, 5, 7, 8], [1, 5, 15], [1, 6, 6, 8], [1, 6, 7, 7], [1, 6, 14], [1, 7, 13], [1, 8, 12], [1, 9, 11], [1, 10, 10], [1, 20], [2, 2, 2, 2, 2, 2, 2, 2, 2, 3], [2, 2, 2, 2, 2, 2, 2, 2, 5], [2, 2, 2, 2, 2, 2, 2, 3, 4], [2, 2, 2, 2, 2, 2, 2, 7], [2, 2, 2, 2, 2, 2, 3, 3, 3], [2, 2, 2, 2, 2, 2, 3, 6], [2, 2, 2, 2, 2, 2, 4, 5], [2, 2, 2, 2, 2, 2, 9], [2, 2, 2, 2, 2, 3, 3, 5], [2, 2, 2, 2, 2, 3, 4, 4], [2, 2, 2, 2, 2, 3, 8], [2, 2, 2, 2, 2, 4, 7], [2, 2, 2, 2, 2, 5, 6], [2, 2, 2, 2, 2, 11], [2, 2, 2, 2, 3, 3, 3, 4], [2, 2, 2, 2, 3, 3, 7], [2, 2, 2, 2, 3, 4, 6], [2, 2, 2, 2, 3, 5, 5], [2, 2, 2, 2, 3, 10], [2, 2, 2, 2, 4, 4, 5], [2, 2, 2, 2, 4, 9], [2, 2, 2, 2, 5, 8], [2, 2, 2, 2, 6, 7], [2, 2, 2, 2, 13], [2, 2, 2, 3, 3, 3, 3, 3], [2, 2, 2, 3, 3, 3, 6], [2, 2, 2, 3, 3, 4, 5], [2, 2, 2, 3, 3, 9], [2, 2, 2, 3, 4, 4, 4], [2, 2, 2, 3, 4, 8], [2, 2, 2, 3, 5, 7], [2, 2, 2, 3, 6, 6], [2, 2, 2, 3, 12], [2, 2, 2, 4, 4, 7], [2, 2, 2, 4, 5, 6], [2, 2, 2, 4, 11], [2, 2, 2, 5, 5, 5], [2, 2, 2, 5, 10], [2, 2, 2, 6, 9], [2, 2, 2, 7, 8], [2, 2, 2, 15], [2, 2, 3, 3, 3, 3, 5], [2, 2, 3, 3, 3, 4, 4], [2, 2, 3, 3, 3, 8], [2, 2, 3, 3, 4, 7], [2, 2, 3, 3, 5, 6], [2, 2, 3, 3, 11], [2, 2, 3, 4, 4, 6], [2, 2, 3, 4, 5, 5], [2, 2, 3, 4, 10], [2, 2, 3, 5, 9], [2, 2, 3, 6, 8], [2, 2, 3, 7, 7], [2, 2, 3, 14], [2, 2, 4, 4, 4, 5], [2, 2, 4, 4, 9], [2, 2, 4, 5, 8], [2, 2, 4, 6, 7], [2, 2, 4, 13], [2, 2, 5, 5, 7], [2, 2, 5, 6, 6], [2, 2, 5, 12], [2, 2, 6, 11], [2, 2, 7, 10], [2, 2, 8, 9], [2, 2, 17], [2, 3, 3, 3, 3, 3, 4], [2, 3, 3, 3, 3, 7], [2, 3, 3, 3, 4, 6], [2, 3, 3, 3, 5, 5], [2, 3, 3, 3, 10], [2, 3, 3, 4, 4, 5], [2, 3, 3, 4, 9], [2, 3, 3, 5, 8], [2, 3, 3, 6, 7], [2, 3, 3, 13], [2, 3, 4, 4, 4, 4], [2, 3, 4, 4, 8], [2, 3, 4, 5, 7], [2, 3, 4, 6, 6], [2, 3, 4, 12], [2, 3, 5, 5, 6], [2, 3, 5, 11], [2, 3, 6, 10], [2, 3, 7, 9], [2, 3, 8, 8], [2, 3, 16], [2, 4, 4, 4, 7], [2, 4, 4, 5, 6], [2, 4, 4, 11], [2, 4, 5, 5, 5], [2, 4, 5, 10], [2, 4, 6, 9], [2, 4, 7, 8], [2, 4, 15], [2, 5, 5, 9], [2, 5, 6, 8], [2, 5, 7, 7], [2, 5, 14], [2, 6, 6, 7], [2, 6, 13], [2, 7, 12], [2, 8, 11], [2, 9, 10], [2, 19], [3, 3, 3, 3, 3, 3, 3], [3, 3, 3, 3, 3, 6], [3, 3, 3, 3, 4, 5], [3, 3, 3, 3, 9], [3, 3, 3, 4, 4, 4], [3, 3, 3, 4, 8], [3, 3, 3, 5, 7], [3, 3, 3, 6, 6], [3, 3, 3, 12], [3, 3, 4, 4, 7], [3, 3, 4, 5, 6], [3, 3, 4, 11], [3, 3, 5, 5, 5], [3, 3, 5, 10], [3, 3, 6, 9], [3, 3, 7, 8], [3, 3, 15], [3, 4, 4, 4, 6], [3, 4, 4, 5, 5], [3, 4, 4, 10], [3, 4, 5, 9], [3, 4, 6, 8], [3, 4, 7, 7], [3, 4, 14], [3, 5, 5, 8], [3, 5, 6, 7], [3, 5, 13], [3, 6, 6, 6], [3, 6, 12], [3, 7, 11], [3, 8, 10], [3, 9, 9], [3, 18], [4, 4, 4, 4, 5], [4, 4, 4, 9], [4, 4, 5, 8], [4, 4, 6, 7], [4, 4, 13], [4, 5, 5, 7], [4, 5, 6, 6], [4, 5, 12], [4, 6, 11], [4, 7, 10], [4, 8, 9], [4, 17], [5, 5, 5, 6], [5, 5, 11], [5, 6, 10], [5, 7, 9], [5, 8, 8], [5, 16], [6, 6, 9], [6, 7, 8], [6, 15], [7, 7, 7], [7, 14], [8, 13], [9, 12], [10, 11], [21]]
Find all possible number combos that sum to a number
555b1890a75b930e63000023
[ "Fundamentals", "Mathematics", "Recursion", "Algorithms" ]
https://www.codewars.com/kata/555b1890a75b930e63000023
4 kyu
Remember the game 2048? http://gabrielecirulli.github.io/2048/ The main part of this game is merging identical tiles in a row. * Implement a function that models the process of merging all of the tile values in a single row. * This function takes the array line as a parameter and returns a new array with the tile values from line slid towards the front of the array (index 0) and merged. * A given tile can only merge once. * Empty grid squares are represented as zeros. * Your function should work on arrays containing arbitrary number of elements. ## Examples ``` merge([2,0,2,2]) --> [4,2,0,0] ``` Another example with repeated merges: ``` merge([4,4,8,16]) --> [8,8,16,0] merge([8,8,16,0]) --> [16,16,0,0] merge([16,16,0,0]) --> [32,0,0,0] ```
algorithms
from itertools import groupby def merge(line): merged = [] for k, g in groupby(v for v in line if v): g = list(g) n, r = divmod(len(g), 2) if n: merged . extend([k * 2] * n) if r: merged . append(k) return merged + [0] * (len(line) - len(merged))
Merge in 2048
55e1990978c60e5052000011
[ "Games", "Arrays", "Algorithms" ]
https://www.codewars.com/kata/55e1990978c60e5052000011
6 kyu
Create a function `isAlt()` that accepts a string as an argument and validates whether the vowels (a, e, i, o, u) and consonants are in alternate order. ```javascript isAlt("amazon") // true isAlt("apple") // false isAlt("banana") // true ``` ```haskell isAlt "amazon" -> True isAlt "apple" -> False isAlt "banana" -> True ``` ```python is_alt("amazon") # True is_alt("apple") # False is_alt("banana") # True ``` ```csharp Kata.IsAlt("amazon") // true Kata.IsAlt("apple") // false Kata.IsAlt("banana") // true ``` ```coffeescript isAlt 'amazon' # true isAlt 'apple' # false isAlt 'banana' # true ``` Arguments consist of only lowercase letters.
algorithms
import re def is_alt(s): return not re . search('[aeiou]{2}|[^aeiou]{2}', s)
Are we alternate?
59325dc15dbb44b2440000af
[ "Algorithms", "Strings" ]
https://www.codewars.com/kata/59325dc15dbb44b2440000af
6 kyu
In mathematics, an n<sup>th</sup> root of a number `x`, where `n` is usually assumed to be a positive integer, is a number `r` which, when raised to the power `n`, yields `x`: ``` r^n=x, ``` Given number `n`, such that `n > 1`, find if its 2<sup>nd</sup> root, 4<sup>th</sup> root and 8<sup>th</sup> root are all integers (fractional part is `0`), return `true` if it exists, `false` if not. ```javascript // 2nd root of 256 is 16 // 4th root of 256 is 4 // 8th root of 256 is 2 perfectRoots(256) // returns true ``` ```python # 2nd root of 256 is 16 # 4th root of 256 is 4 # 8th root of 256 is 2 perfect_roots(256) # returns True ``` ```ruby # 2nd root of 256 is 16 # 4th root of 256 is 4 # 8th root of 256 is 2 perfect_roots(256) # returns true ``` ```crystal # 2nd root of 256 is 16 # 4th root of 256 is 4 # 8th root of 256 is 2 perfect_roots(256) # returns true ```
algorithms
def perfect_roots(n): return (n * * 0.125) % 1 == 0
number with 3 roots.
5932c94f6aa4d1d786000028
[ "Algorithms" ]
https://www.codewars.com/kata/5932c94f6aa4d1d786000028
7 kyu
A core idea of several left-wing ideologies is that the wealthiest should *support* the poorest, no matter what and that is exactly what you are called to do using this kata (which, on a side note, was born out of the necessity to redistribute the width of `div`s into a given container). You will be given two parameters, `population` and `minimum`: your goal is to give to each one according to his own needs (which we assume to be equal to `minimum` for everyone, no matter what), taking from the richest (bigger numbers) first. For example, assuming a population `[2,3,5,15,75]` and `5` as a minimum, the expected result should be `[5,5,5,15,70]`. Let's punish those filthy capitalists, as we all know that being rich has to be somehow a fault and a shame! If you happen to have few people as the richest, just take from the ones with the lowest index (the closest to the left, in few words) in the array first, on a 1:1 based heroic proletarian redistribution, until everyone is satisfied. To clarify this rule, assuming a population `[2,3,5,45,45]` and `5` as `minimum`, the expected result should be `[5,5,5,42,43]`. If you want to see it in steps, consider removing `minimum` from every member of the population, then iteratively (or recursively) adding 1 to the poorest while removing 1 from the richest. Pick the element most at left if more elements exist with the same level of minimal poverty, as they are certainly even more aligned with the party will than other poor people; similarly, it is ok to take from the richest one on the left first, so they can learn their lesson and be more kind, possibly giving more *gifts* to the inspectors of the State! In steps: ``` [ 2, 3, 5,45,45] becomes [-3,-2, 0,40,40] that then becomes [-2,-2, 0,39,40] that then becomes [-1,-2, 0,39,39] that then becomes [-1,-1, 0,38,39] that then becomes [ 0,-1, 0,38,38] that then becomes [ 0, 0, 0,37,38] that then finally becomes (adding the minimum again, as no value is no longer under the poverty threshold [ 5, 5, 5,42,43] ``` If giving `minimum` is unfeasable with the current resources (as it often comes to be the case in socialist communities...), for example if the above starting population had set a goal of giving anyone at least `30`, just return an empty array `[]`.
algorithms
def socialist_distribution(population, minimum): if minimum > sum(population) / / len(population): return [] while min(population) < minimum: population[population . index(min(population))] += 1 population[population . index(max(population))] -= 1 return population
Socialist distribution
58cfa5bd1c694fe474000146
[ "Arrays", "Lists", "Statistics", "Algorithms" ]
https://www.codewars.com/kata/58cfa5bd1c694fe474000146
6 kyu
# Task The number is considered to be `unlucky` if it does not have digits `4` and `7` and is divisible by `13`. Please count all unlucky numbers not greater than `n`. # Example For `n = 20`, the result should be `2` (numbers `0 and 13`). For `n = 100`, the result should be `7` (numbers `0, 13, 26, 39, 52, 65, and 91`) # Input/Output - `[input]` integer `n` `1 ≤ n ≤ 10^8(10^6 in Python)` - `[output]` an integer
games
def unlucky_number(n): return sum(not ('4' in s or '7' in s) for s in map(str, range(0, n + 1, 13)))
Simple Fun #174: Unlucky Number
58b65c5e8b98b2e4fa000034
[ "Puzzles" ]
https://www.codewars.com/kata/58b65c5e8b98b2e4fa000034
6 kyu
Your task is to write a function which cuts cancer cells from the body. ### Cancer cells are divided into two types: * <span style="color:red">Advance</span> stage,described as letter <span style="color:red">C</span> * <span style="color:Tomato">Initial</span> stage,described as letter <span style="color:Tomato">c</span> Rest cells are divided as follows: * <span style="color:PaleGoldenRod">Normal</span> cell,described as <span style="color:PaleGoldenRod">lowercase</span> letter * <span style="color:orange">Important</span> cell,described as <span style="color:orange">uppercase</span> letter ### Prerequisites: * <span style="color:orange">Important</span> cell,cannot be cut out. * <span style="color:red">Advance</span> cancer cell,should be cut out with adjacent cells if it can be done. Function input is a string (representing a body), remove "cancer" characters (based on the described rules) and return the body cured of those "cancer" characters.
reference
import re reg = re . compile(r"c|[a-z]?C[a-z]?") def cut_cancer_cells(s): return reg . sub("", s)
Cancer cells
5931614bb2f657c18c0001c3
[ "Regular Expressions", "Fundamentals" ]
https://www.codewars.com/kata/5931614bb2f657c18c0001c3
6 kyu
*** No Loops Allowed *** You will be given an array `a` and a value `x`. All you need to do is check whether the provided array contains the value, without using a loop. Array can contain numbers or strings. `x` can be either. Return `true` if the array contains the value, `false` if not. With strings you will need to account for case. Looking for more, loop-restrained fun? Check out the other kata in the series: [No Loops 1 - Small enough?](https://www.codewars.com/kata/no-loops-1-small-enough)
reference
def check(a, x): return x in a
No Loops 2 - You only need one
57cc40b2f8392dbf2a0003ce
[ "Fundamentals", "Arrays" ]
https://www.codewars.com/kata/57cc40b2f8392dbf2a0003ce
8 kyu
# Introduction Digital Cypher assigns a unique number to each letter of the alphabet: ``` a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ``` In the encrypted word we write the corresponding numbers instead of the letters. For example, the word `scout` becomes: ``` s c o u t 19 3 15 21 20 ``` Then we add to each number a digit from the key (repeated if necessary). For example if the key is `1939`: ``` s c o u t 19 3 15 21 20 + 1 9 3 9 1 --------------- 20 12 18 30 21 m a s t e r p i e c e 13 1 19 20 5 18 16 9 5 3 5 + 1 9 3 9 1 9 3 9 1 9 3 -------------------------------- 14 10 22 29 6 27 19 18 6 12 8 ``` # Task Write a function that accepts a `message` string and an array of integers `code`. As the result, return the `key` that was used to encrypt the `message`. The `key` has to be shortest of all possible keys that can be used to code the `message`: i.e. when the possible keys are `12` , `1212`, `121212`, your solution should return `12`. #### Input / Output: * The `message` is a string containing only lowercase letters.<br/> * The `code` is an array of positive integers.<br/> * The `key` output is a positive integer. # Examples ```javascript findTheKey("scout", [20, 12, 18, 30, 21]); => 1939 findTheKey("masterpiece", [14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8]); => 1939 findTheKey("nomoretears", [15, 17, 14, 17, 19, 7, 21, 7, 2, 20, 20]); => 12 ``` ```csharp FindTheKey("scout", new int[]{20, 12, 18, 30, 21}); => 1939 FindTheKey("masterpiece", new int[]{14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8}); => 1939 FindTheKey("nomoretears", new int[]{15, 17, 14, 17, 19, 7, 21, 7, 2, 20, 20}); => 12 ``` ```go FindTheKey("scout", []int{20, 12, 18, 30, 21}) => 1939 FindTheKey("masterpiece", []int{14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8}) => 1939 FindTheKey("nomoretears", []int{15, 17, 14, 17, 19, 7, 21, 7, 2, 20, 20}) => 12 ``` ```ruby find_the_key("scout", [20, 12, 18, 30, 21]) # --> 1939 find_the_key("masterpiece", [14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8]) # --> 1939 find_the_key("nomoretears", [15, 17, 14, 17, 19, 7, 21, 7, 2, 20, 20]) # --> 12 ``` ```python find_the_key("scout", [20, 12, 18, 30, 21]) # --> 1939 find_the_key("masterpiece", [14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8]) # --> 1939 find_the_key("nomoretears", [15, 17, 14, 17, 19, 7, 21, 7, 2, 20, 20]) # --> 12 ``` ```nasm msg: db `scout\0` code: db 20, 12, 18, 30, 21 mov rdi, msg mov rsi, code mov rdx, 5 call find_the_key ; EAX <- 1939 msg: db `masterpiece\0` code: db 14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8 mov rdi, msg mov rsi, code mov rdx, 11 call find_the_key ; EAX <- 1939 msg: db `nomoretears\0` code: db 15, 17, 14, 17, 19, 7, 21, 7, 2, 20, 20 mov rdi, msg mov rsi, code mov rdx, 11 call find_the_key ; EAX <- 12 ``` ```c find_the_key("scout", (const unsigned char[]){20, 12, 18, 30, 21}, 5) /* --> 1939 */ find_the_key("masterpiece", (const unsigned char[]){14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8}, 11) /* --> 1939 */ find_the_key("nomoretears", (const unsigned char[]){15, 17, 14, 17, 19, 7, 21, 7, 2, 20, 20}, 11) /* --> 12 */ ``` # Digital cypher series - [Digital cypher vol 1](https://www.codewars.com/kata/592e830e043b99888600002d) - [Digital cypher vol 2](https://www.codewars.com/kata/592edfda5be407b9640000b2) - [Digital cypher vol 3 - missing key](https://www.codewars.com/kata/5930d8a4b8c2d9e11500002a)
reference
def find_the_key(message, code): diffs = "" . join(str(c - ord(m) + 96) for c, m in zip(code, message)) for size in range(1, len(code) + 1): key = diffs[: size] if (key * len(code))[: len(code)] == diffs: return int(key)
Digital cypher vol 3 - missing key
5930d8a4b8c2d9e11500002a
[ "Fundamentals", "Ciphers", "Cryptography" ]
https://www.codewars.com/kata/5930d8a4b8c2d9e11500002a
6 kyu
```if:java ___Note for Java users:___ Due to type checking in Java, inputs and outputs are formated quite differently in this language. See the footnotes of the description. <hr> ``` You have the following lattice points with their corresponding coordinates and each one with an specific colour. ``` Point [x , y] Colour ---------------------------- A [ 3, -4] Blue B [-7, -1] Red C [ 7, -6] Yellow D [ 2, 5] Yellow E [ 1, -5] Red F [-1, 4] Red G [ 1, 7] Red H [-3, 5] Red I [-3, -5] Blue J [ 4, 1] Blue ``` We want to count the triangles that have the three vertices with the same colour. The following picture shows the distribution of the points in the plane with the required triangles. ![source: imgur.com](http://i.imgur.com/sP0l1i1.png) The input that we will have for the field of lattice points described above is: ``` [[[3, -4], "blue"], [[-7, -1], "red"], [[7, -6], "yellow"], [[2, 5], "yellow"], [[1, -5], "red"], [[-1, 4], "red"], [[1, 7], "red"], [[-3, 5], "red"], [[-3, -5], "blue"], [[4, 1], "blue"] ] ``` We see the following result from it: ``` Colour Amount of Triangles Triangles Yellow 0 ------- Blue 1 AIJ Red 10 BEF,BEG,BEH,BFG,BFH,BGH,EFG,EFH,EHG,FGH ``` As we have 5 different points in red and each combination of 3 points that are not aligned. We need a code that may give us the following information in order: ``` 1) Total given points 2) Total number of colours 3) Total number of possible triangles 4) and 5) The colour (or colours, sorted alphabetically) with the highest amount of triangles ``` In Python our function will work like: ``` [10, 3, 11, ["red",10]]) == count_col_triang([[[3, -4], "blue"], [[-7, -1], "red"], [[7, -6], "yellow"], [[2, 5], "yellow"], [[1, -5], "red"], [[-1, 4], "red"], [[1, 7], "red"], [[-3, 5], "red"], [[-3, -5], "blue"], [[4, 1], "blue"] ]) ``` In the following case we have some points that are aligned and we have less triangles that can be formed: ``` [10, 3, 7, ["red", 6]] == count_col_triang([[[3, -4], "blue"], [[-7, -1], "red"], [[7, -6], "yellow"], [[2, 5], "yellow"], [[1, -5], "red"], [[1, 1], "red"], [[1, 7], "red"], [[1, 4], "red"], [[-3, -5], "blue"], [[4, 1], "blue"] ]) ``` Just to see the change with the previous case we have this: ![source: imgur.com](http://i.imgur.com/cCgO7ql.png) In the special case that the list of points does not generate an even single triangle, the output will be like this case: ``` [9, 3, 0, []] == count_col_triang([[[1, -2], "red"], [[7, -6], "yellow"], [[2, 5], "yellow"], [[1, -5], "red"], [[1, 1], "red"], [[1, 7], "red"], [[1, 4], "red"], [[-3, -5], "blue"], [[4, 1], "blue"] ]) ``` It will be this case: ![source: imgur.com](http://i.imgur.com/VB7t7Ij.png) If in the result we have two or more colours with the same maximum amount of triangles, the last list should be like (e.g) ``` [35, 6, 35, ["blue", "red", "yellow", 23]] # having the names of the colours sorted alphabetically ``` For the condition of three algined points A, B, C, you should know that the the following determinant should be 0. ``` | xA yA 1| | xB yB 1| = 0 | xC yC 1| ``` Assumptions: - In the list you have unique points, so a point can have only one colour. - All the inputs are valid Enjoy it! ````if:java --- ___For java users:___ Two immutable objects, `ColouredPoint` and `TriangleResult`, have been designed for you in the preloaded part. You will receive inputs as lists of ColouredPoint objects and will return a TriangleResult object. For the last one, you may note the organization of the arguments of the constructor which differs a bit from the description above. You may find below the signatures of the available methods of these objects: ```java class ColouredPoint { public ColouredPoint(final int[] pos, final String color) public int[] getPosition() public String getColour() @Override public boolean equals(Object other) @Override public int hashCode() @Override public String toString() // String representation formated as "[[x, y], red]" } class TriangleResult { public TriangleResult() public TriangleResult(final int nGivenPoints, final int nGivenColours, final int nTriangles, final List<String> colours, final int maxFromColour) @Override public boolean equals(Object other) @Override public int hashCode() @Override public String toString() // String representation formated as "[nGivenPoints, nGivenColours, nTriangles, [red, blue], maxFromColour]" } ``` ````
reference
from itertools import combinations def count_col_triang(a): p, r = {}, {} for xy, col in a: p[col] = p . get(col, []) + [xy] for k in p: r[k] = sum(1 for c in combinations(p[k], 3) if triangle(* c)) mx = max(r . values()) return [len(a), len(p), sum(r . values()), sorted(k for k in r if r[k] == mx) + [mx] if mx else []] def triangle(a, b, c): return area(* [((p[0] - q[0]) * * 2 + (p[1] - q[1]) * * 2) * * 0.5 for p, q in [(a, b), (a, c), (b, c)]]) > 0.0 def area(a, b, c): s = 0.5 * (a + b + c) return round(max((s * ((s - a) * (s - b) * (s - c))), 0.0) * * 0.5, 4)
Coloured Lattice Points Forming Coloured Triangles
57cebf1472f98327760003cd
[ "Fundamentals", "Data Structures", "Algorithms", "Geometry", "Mathematics", "Logic", "Strings" ]
https://www.codewars.com/kata/57cebf1472f98327760003cd
4 kyu
# Covfefe Your are given a string. You must replace any occurence of the sequence `coverage` by `covfefe`, however, if you don't find the word `coverage` in the string, you must add `covfefe` at the end of the string with a leading space. For the languages where the string is mutable (such as ruby), don't modify the given string, otherwise this will break the test cases.
games
def covfefe(s): return s . replace("coverage", "covfefe") if "coverage" in s else s + " covfefe"
Covfefe
592fd8f752ee71ac7e00008a
[ "Strings" ]
https://www.codewars.com/kata/592fd8f752ee71ac7e00008a
7 kyu
# Introduction <pre style="white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;"> Dots and Boxes is a pencil-and-paper game for two players (sometimes more). It was first published in the 19th century by Édouard Lucas, who called it la pipopipette. It has gone by many other names, including the game of dots, boxes, dot to dot grid, and pigs in a pen. Starting with an empty grid of dots, two players take turns adding a single horizontal or vertical line between two unjoined adjacent dots. The player who completes the fourth side of a 1×1 box earns one point and takes another turn only if another box can be made. (A point is typically recorded by placing a mark that identifies the player in the box, such as an initial). The game ends when no more lines can be placed. The winner is the player with the most points. The board may be of any size. When short on time, a 2×2 board (a square of 9 dots) is good for beginners. A 5×5 is good for experts. (Source <a href="https://en.wikipedia.org/wiki/Dots_and_Boxes">Wikipedia</a>) </pre> <center><img src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/squares_banner.jpg" alt="Squares"></center> # Task <pre style="white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;"> Your task is to complete the class called <font color="#A1A85E">Game</font>. You will be given the board size as an integer <font color="#A1A85E">board</font> that will be between <font color="#A1A85E">1</font> and <font color="#A1A85E">26</font>, therefore the game size will be <font color="#A1A85E">board x board</font>. You will be given an array of lines that have already been taken, so you must complete all possible squares. </pre> # Rules <pre style="white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;"> 1.&nbsp; The integer <font color="#A1A85E">board</font> will be passed when the class is initialised. 2.&nbsp; <font color="#A1A85E">board</font> will be between <font color="#A1A85E">1</font> and <font color="#A1A85E">26</font>. 3.&nbsp; The <font color="#A1A85E">lines</font> array maybe empty or contain a list of line integers. 4.&nbsp; You can only complete a square if <font color="#A1A85E">3</font> out of the <font color="#A1A85E">4</font> sides are already complete. 5.&nbsp; The <font color="#A1A85E">lines</font> array that is passed into the <font color="#A1A85E">play()</font> function may not be sorted numerically! </pre> # Returns <pre style="white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;"> Return an array of all the lines filled in including the original lines. Return array must be sorted numerically. Return array must <b>not</b> contain duplicate integers. </pre> # Example 1 ## Initialise Initialise a board of 2 squares by 2 squares where ```board = 2```<br> <img src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/Square1.png"><br> ## Line Numbering<br> <img src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/Square2.png"> ## Line Input<br> So for the line input of `[1, 3, 4]` the below lines would be complete<br> <img src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/Square3.png"><br> to complete the square line `6` is needed ## Game Play ```ruby board = 2 lines = [1, 3, 4] game = Game.new(board) game.play(lines) => [1, 3, 4, 6] ``` ```python board = 2 lines = [1, 3, 4] game = Game(board) game.play(lines) => [1, 3, 4, 6] ``` ```javascript board = 2; lines = [1, 3, 4]; game = new Game(board); game.play(lines) => [1, 3, 4, 6] ``` ```csharp int board = 2; List<int> lines = new List<int> { 1, 3, 4 }; Game game = new Game(board); game.play(lines) => { 1, 3, 4, 6 } ``` # Example 2 ## Initialise ```ruby board = 2 lines = [1, 2, 3, 4, 5, 8, 10, 11, 12] game = Game.new(board) game.play(lines) => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] ``` ```python board = 2 lines = [1, 2, 3, 4, 5, 8, 10, 11, 12] game = Game.new(board) game.play(lines) => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] ``` ```javascript board = 2; lines = [1, 2, 3, 4, 5, 8, 10, 11, 12]; game = Game.new(board); game.play(lines) => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] ``` ```csharp int board = 2; List<int> lines = new List<int> { 1, 2, 3, 4, 5, 8, 10, 11, 12 }; Game game = new Game(board); game.play(lines) => { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } ``` ## Solution <img src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/SquareExample.png"><br> Good luck and enjoy! # Kata Series If you enjoyed this, then please try one of my other Katas. Any feedback, translations and grading of beta Katas are greatly appreciated. Thank you. <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58663693b359c4a6560001d6" target="_blank">Maze Runner</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58693bbfd7da144164000d05" target="_blank">Scooby Doo Puzzle</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/7KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/586a1af1c66d18ad81000134" target="_blank">Driving License</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/586c0909c1923fdb89002031" target="_blank">Connect 4</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/586e6d4cb98de09e3800014f" target="_blank">Vending Machine</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/587136ba2eefcb92a9000027" target="_blank">Snakes and Ladders</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58a848258a6909dd35000003" target="_blank">Mastermind</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58b2c5de4cf8b90723000051" target="_blank">Guess Who?</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58f5c63f1e26ecda7e000029" target="_blank">Am I safe to drive?</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58f5c63f1e26ecda7e000029" target="_blank">Mexican Wave</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58fdcc51b4f81a0b1e00003e" target="_blank">Pigs in a Pen</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/590300eb378a9282ba000095" target="_blank">Hungry Hippos</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/5904be220881cb68be00007d" target="_blank">Plenty of Fish in the Pond</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/590adadea658017d90000039" target="_blank">Fruit Machine</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/591eab1d192fe0435e000014" target="_blank">Car Park Escape</a></span>
reference
class Game (): def __init__(self, n): k = 2 * n + 1 self . board = {frozenset(k * r + 1 + c + d for d in (0, n, n + 1, k)) for r in range(n) for c in range(n)} def play(self, lines): lines = set(lines) while 1: for cell in self . board: stick = cell - lines if len(stick) <= 1: lines |= stick self . board . remove(cell) break else: break return sorted(lines)
Pigs in a Pen
58fdcc51b4f81a0b1e00003e
[ "Puzzles", "Arrays", "Fundamentals" ]
https://www.codewars.com/kata/58fdcc51b4f81a0b1e00003e
5 kyu
You will receive an uncertain amount of integers in a certain order ```k1, k2, ..., kn```. You form a new number of n digits in the following way: you take one of the possible digits of the first given number, ```k1```, then the same with the given number ```k2```, repeating the same process up to ```kn``` and you concatenate these obtained digits(in the order that were taken) obtaining the new number. As you can see, we have many possibilities. Let's see the process above explained with three given numbers: ``` k1 = 23, k2 = 17, k3 = 89 Digits Combinations Obtained Number ('2', '1', '8') 218 <---- Minimum ('2', '1', '9') 219 ('2', '7', '8') 278 ('2', '7', '9') 279 ('3', '1', '8') 318 ('3', '1', '9') 319 ('3', '7', '8') 378 ('3', '7', '9') 379 <---- Maximum Total Sum = 2388 (8 different values) ``` We need the function that may work in this way: ```python proc_seq(23, 17, 89) == [8, 218, 379, 2388] ``` ```javascript procSeq(23, 17, 89) ---> [8, 218, 379, 2388] ``` See this special case and deduce how the function should handle the cases which have many repetitions. ```python proc_seq(22, 22, 22, 22) == [1, 2222] # we have only one obtained number, the minimum, maximum and total sum coincide ``` ```javascript procSeq(22, 22, 22, 22) ---> [1, 2222] /* we have only one obtained number, the minimum, maximum and total sum coincide*/ ``` The sequence of numbers will have numbers of n digits only. Numbers formed by leading zeroes will be discarded. ```python proc_seq(230, 15, 8) == [4, 218, 358, 1152] ``` ```javascript procSeq(230, 15, 8) ---> [4, 218, 358, 1152] ``` Enjoy it!! You will never receive the number 0 and all the numbers will be in valid format.
reference
from itertools import product def proc_seq(* args): nums = set(int('' . join(l)) for l in product(* (str(a) for a in args)) if l[0] != '0') if len(nums) == 1: return [1, nums . pop()] return [len(nums), min(nums), max(nums), sum(nums)]
Building a Sequence Cocatenating Digits with a Given Order.
5717924a1c2734e78f000430
[ "Fundamentals", "Data Structures", "Algorithms", "Mathematics", "Logic", "Strings" ]
https://www.codewars.com/kata/5717924a1c2734e78f000430
5 kyu
<p>This is the second part of this kata series. First part is <a href="https://www.codewars.com/kata/adding-words-part-i/">here</a> and the third is <a href="https://www.codewars.com/kata/adding-words-part-iii/">here</a></p> <p>Add two English words together!</p> <p>Implement a class <code>Arith</code> such that</p> ```javscript var k = new Arith("three"); k.add("one hundred and two"); //this should return "one hundred and five" ``` <p><b>Input</b> - Will be between <code>zero</code> and <code>five hundred</code> and will always be in lower case. This input range applies to both the initial value upon object instantiation as well as the input for the <code>add</code> method.</p> <p><b>Output</b> - Word representation of the result of the addition. Should be in lower case</p> <p><b>Word format</b> - Both input and output shall be in the format <code>123 = one hundred and twenty three</code>. No hyphen is needed in numbers 21-99. Words should also be separated with one space and no space padding is allowed.
reference
class Arith (object): # Constant names and associated ranges for natural numbers zero_nine = ("zero,one,two,three,four,five,six,seven,eight,nine", 0, 10, 1) ten_nineteen = ( "ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen", 10, 20, 1) tens = ("twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety", 20, 91, 10) hundreds = ("one hundred,two hundred,three hundred,four hundred,five hundred,six hundred,seven hundred,eight hundred,nine hundred,one thousand", 100, 1001, 100) @ classmethod def gen_vals(cls): """Generates a tuple of name and value for each value from largest to smallest""" for target in [cls . hundreds, cls . tens, cls . ten_nineteen, cls . zero_nine]: for name, value in zip(reversed(target[0]. split(",")), reversed(range(* target[1:]))): yield name, value @ classmethod def extract(cls, s): """Extracts the numerical value of s""" total = 0 for name, value in cls . gen_vals(): if name in s: total += value s = s . replace(name, "") return total @ classmethod def encode(cls, n): """Encodes the string value of n""" s = [] for name, value in cls . gen_vals(): if n >= value: s . append(name) n -= value if len(s) > 0 and s[- 1] == "zero": # Remove trailing zeros s = s[: - 1] if len(s) > 1: if " " in s[0]: # Found a hundred or thousand marker s = [s[0]] + ["and"] + s[1:] return " " . join(s) def __init__(self, s): self . value = self . extract(s) def add(self, s): return self . encode(self . value + self . extract(s))
Adding words - Part II
592eccf7d6a5403edf000aa1
[ "Mathematics" ]
https://www.codewars.com/kata/592eccf7d6a5403edf000aa1
5 kyu
From wikipedia <https://en.wikipedia.org/wiki/Partition_(number_theory)> In number theory and combinatorics, a partition of a positive integer n, also called an integer partition, is a way of writing n as a sum of positive integers. Two sums that differ only in the order of their summands are considered the **same** partition. For example, 4 can be partitioned in five distinct ways: `4, 3 + 1, 2 + 2, 2 + 1 + 1, 1 + 1 + 1 + 1`. We can write: `enum(4) -> [[4],[3,1],[2,2],[2,1,1],[1,1,1,1]]` and `enum(5) -> [[5],[4,1],[3,2],[3,1,1],[2,2,1],[2,1,1,1],[1,1,1,1,1]]`. The number of parts in a partition grows very fast. For n = 50 number of parts is `204226`, for 80 it is `15,796,476` It would be too long to tests answers with arrays of such size. So our task is the following: 1 - n being given (n integer, 1 <= n <= 50) calculate enum(n) ie the partition of n. We will obtain something like that: `enum(n) -> [[n],[n-1,1],[n-2,2],...,[1,1,...,1]]` (order of array and sub-arrays doesn't matter). This part is not tested. 2 - For each sub-array of enum(n) calculate its product. If n = 5 we'll obtain **after removing duplicates and sorting**: `prod(5) -> [1,2,3,4,5,6]` `prod(8) -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 16, 18]` If n = 40 prod(n) has a length of `2699` hence the tests will not verify such arrays. Instead our task number 3 is: 3 - return the range, the average and the median of prod(n) in the following form (example for n = 5): `"Range: 5 Average: 3.50 Median: 3.50"` Range is an integer, Average and Median are float numbers rounded to two decimal places (".2f" in some languages). #### Notes: `Range` : difference between the highest and lowest values. `Mean or Average` : To calculate mean, add together all of the numbers in a set and then divide the sum by the total count of numbers. `Median` : The median is the number separating the higher half of a data sample from the lower half. (https://en.wikipedia.org/wiki/Median) #### Hints: Try to optimize your program to avoid timing out. Memoization can be helpful but it is not mandatory for being successful.
reference
def prod(n): ret = [{1.}] for i in range(1, n + 1): ret . append({(i - x) * j for x, s in enumerate(ret) for j in s}) return ret[- 1] def part(n): p = sorted(prod(n)) return "Range: %d Average: %.2f Median: %.2f" % \ (p[- 1] - p[0], sum(p) / len(p), (p[len(p) / / 2] + p[~ len(p) / / 2]) / 2)
Getting along with Integer Partitions
55cf3b567fc0e02b0b00000b
[ "Fundamentals", "Algorithms" ]
https://www.codewars.com/kata/55cf3b567fc0e02b0b00000b
4 kyu
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Sydney_-_Newcastle_freeway_north_bound_at_Berowra.jpg/500px-Sydney_-_Newcastle_freeway_north_bound_at_Berowra.jpg"> # Back-Story Every day I travel on the freeway. When I am more bored than usual I sometimes like to play the following counting game I made up: * As I join the freeway my count is ```0``` * Add ```1``` for every car that I overtake * Subtract ```1``` for every car that overtakes me * Stop counting when I reach my exit What an easy game! What fun! # Kata Task You will be given * The distance to my exit (km) * How fast I am going (kph) * Information about a lot of other cars * Their time (relative to me) as I join the freeway. For example, * ```-1.5``` means they already passed my starting point ```1.5``` minutes ago * ```2.2``` means they will pass my starting point ```2.2``` minutes from now * How fast they are going (kph) Find what is my "score" as I exit the freeway! # Notes * Assume all cars travel at a constant speeds <span style='font-size:25px;font-weight:bold;color:red;background:yellow;border:solid orange 5px;'>&nbsp;Safety Warning&nbsp;</span> If you plan to play this "game" remember that it is not really a game. You are in a **real** car. There may be a temptation to try to beat your previous best score. Please don't do that...
algorithms
def freeway_game(km, kph, cars): t = km / kph c = 0 for dt, speed in cars: d = km - (t - dt / 60) * speed if dt <= 0: c += d > 0 else: c -= d < 0 return c
The Freeway Game
59279aea8270cc30080000df
[ "Algorithms" ]
https://www.codewars.com/kata/59279aea8270cc30080000df
6 kyu
In this Kata, we use the Euler method for integrating a function (see [wiki](https://en.wikipedia.org/wiki/Euler_method)). Remember that integrating a function basically means 'calculating the area under a curve'. One way to approximate the area is to chop it up into rectangles (whose area is just height * width) and sum them (see [this other wiki page](https://en.wikipedia.org/wiki/Rectangle_method) which has a nice gif illustrating this point). We are going to do just this. Let `y = 5 + 2 * x + 3 * x^2`. Write a function ```def euler(stop, step_size)``` that calculates the integral of y between `x = 0` and `x = stop`. For the sake of simplicity, `stop > 0`. As the example test shows, the code will be verified by using a `step_size of 0.0001`, then rounding the output to the nearest integer.
algorithms
def euler(stop, step_size): def f(x): return 5 + 2 * x + 3 * x * * 2 n = int(stop / / step_size) prev = 0 for i in range(n + 1): prev += step_size * f(step_size * i) return prev
Euler method for numerical integration
587c0d396d360f3cc600003f
[ "Algorithms" ]
https://www.codewars.com/kata/587c0d396d360f3cc600003f
6 kyu
<a href="http://imgur.com/RTBtOMl"><img src="http://i.imgur.com/RTBtOMl.jpg" title="source: imgur.com" /></a> In this kata we will see a method, not so accurate but a different one to estimate number Pi. You will be given a list of random points contained in a cube of side of length 2l. The center of the cube coincides with the center of the coordinates system xyz, the point (0, 0, 0). You can see the above image to understand that the radius of the spehere is half of the side of the cube. To estimate Pi we should count the amount of points that are contained in the sphere inscribed in the cube. The function ``` mCarlo3D_pi() ```, will receive a list of numeruous points. An estimation of the length side of the cube, and of course, the radius of the sphere, has to be deduced from this list. The function ``` mCarlo3D_pi() ``` , will output in a list ``` [(1), (2), (3), (4), (5), (6)] ``` (1) - Total amount of points. (2) - Estimated radius of the inscribed sphere. (3) - Number of points contained in the sphere(including the ones in its surphace). (4) - Estimation of Pi as a float with a maximum of four decimals (rounded result). (5) - Relative error, ```relError= abs(real Val of Pi - estmimated Val of Pi) / (real Val of Pi) * 100``` rounded with two decimals and expressed as a string with the symbol "%" (6) - A boolean variable according to the constraints bellow: ```python if relError ≥ 5 % -----> False if relError < 5 % ------> True ``` Let's see some cases: ```python list1 = [(-5, 3, -5), (3, 5, -6), (-5, 6, 0), (-5, 3, -6), (4, -3, -1), (5, 4, -3), (6, 4, -1), (5, 3, 2), (1, -2, 5), (-5, 0, -2)] (10 points) mCarlo3D_pi(list1) -----> [10, 6, 3, 1.8, '42.7%', False] ) /// What? An estimation of pi equals to 1.8? mmm.... Let's try with a list with more points. We're too far from its real value. A relative error of 42.7% is too high!/// list2 = [(1, 4, 6), (0, 4, 5), (1, 3, -5), (1, 5, -2), (0, 5, 6), (-5, 2, 5), (6, 2, 6), (5, 2, 2), (0, 1, 5), (2, 0, 3), (2, 4, 0), (-3, -6, 3), (-6, 6, -6), (-5, -3, -1), (1, -5, 2), (4, 5, -4), (3, 1, -2), (-4, 0, 3), (3, -6, 5), (5, 4, -4), (5, 5, -6), (2, -3, 3), (5, 2, -4), (-2, 3, -3), (2, -4, 6), (-6, -5, 4), (1, -2, 0), (-4, -4, 3), (1, -1, -4), (-2, -5, -2)] (30 points) mCarlo3D_pi(list2) -----> [30, 6, 15, 3.0, '4.51%', True] /// Well, a bit better. This result gives us hope to try with larger lists and higher sizes for the cubes. ``` Before coding, you have to relate the quotient (points in sphere) / (total points in the cube) to the number pi. (Hint: Monte Carlo2D -------> Monte Carlo3D.) Enjoy it!! (Relative Error should be evaluated (```≥ 5 or < 5```) with all the decimals that Python gives to floats. It should be rounded only for the result as a string)
reference
import math def mCarlo3D_pi(lst): R = max(abs(r) for pt in lst for r in pt) inPts = sum(sum(r * * 2 for r in pt) <= R * * 2 for pt in lst) approxPi = 6.0 * inPts / len(lst) relError = abs(approxPi - math . pi) / math . pi * 100 return [len(lst), R, inPts, round(approxPi, 4), "{}%" . format(round(relError, 2)), relError < 5]
MONTE CARLO 3D
55f9ee4d8f3bbabf2200000c
[ "Fundamentals", "Mathematics", "Data Structures" ]
https://www.codewars.com/kata/55f9ee4d8f3bbabf2200000c
5 kyu
# Introduction Digital Cypher assigns to each letter of the alphabet unique number. For example: ``` a b c d e f g h i j k l m 1 2 3 4 5 6 7 8 9 10 11 12 13 n o p q r s t u v w x y z 14 15 16 17 18 19 20 21 22 23 24 25 26 ``` Instead of letters in encrypted word we write the corresponding number, eg. The word scout: ``` s c o u t 19 3 15 21 20 ``` Then we add to each obtained digit consecutive digits from the key. For example. In case of key equal to `1939` : ``` s c o u t 19 3 15 21 20 + 1 9 3 9 1 --------------- 20 12 18 30 21 m a s t e r p i e c e 13 1 19 20 5 18 16 9 5 3 5 + 1 9 3 9 1 9 3 9 1 9 3 -------------------------------- 14 10 22 29 6 27 19 18 6 12 8 ``` # Task Write a function that accepts an array of integers `code` and a `key` number. As the result, it should return string containg a decoded message from the `code`. # Input / Output The `code` is a array of positive integers.<br/> The `key` input is a nonnegative integer. # Example ``` javascript decode([ 20, 12, 18, 30, 21],1939); ==> "scout" decode([ 14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8],1939); ==> "masterpiece" ``` ```csharp Decode(new int[]{ 20, 12, 18, 30, 21},1939); ==> "scout" Decode(new int[]{ 14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8},1939); ==> "masterpiece" ``` ```go Decode([]int{20, 12, 18, 30, 21}, 1939) ==> "scout" Decode([]int{14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8}, 1939) ==> "masterpiece" ``` # Digital cypher series - [Digital cypher vol 1](https://www.codewars.com/kata/592e830e043b99888600002d) - [Digital cypher vol 2](https://www.codewars.com/kata/592edfda5be407b9640000b2) - [Digital cypher vol 3 - missing key](https://www.codewars.com/kata/5930d8a4b8c2d9e11500002a)
reference
from itertools import cycle from string import ascii_lowercase def decode(code, key): keys = cycle(map(int, str(key))) return '' . join(ascii_lowercase[n - next(keys) - 1] for n in code)
Digital cypher vol 2
592edfda5be407b9640000b2
[ "Fundamentals", "Ciphers", "Cryptography" ]
https://www.codewars.com/kata/592edfda5be407b9640000b2
7 kyu
Learning to code around your full time job is taking over your life. You realise that in order to make significant steps quickly, it would help to go to a coding bootcamp in London. Problem is, many of them cost a fortune, and those that don't still involve a significant amount of time off work - who will pay your mortgage?! To offset this risk, you decide that rather than leaving work totally, you will request a sabbatical so that you can go back to work post bootcamp and be paid while you look for your next role. You need to approach your boss. Her decision will be based on three parameters:<br> `val` = your value to the organisation<br> `happiness` = her happiness level at the time of asking and finally<br> The numbers of letters from 'sabbatical' that are present in string `s`. Note that if `s` contains three instances of the letter 'l', that still scores three points, even though there is only one in the word sabbatical. If the sum of the three parameters (as described above) is > 22, return 'Sabbatical! Boom!', else return 'Back to your desk, boy.'. ~~~if:c NOTE: For the C translation you should return a string literal. ~~~
reference
def sabb(stg, value, happiness): sabbatical = (value + happiness + sum(1 for c in stg if c in "sabbatical")) > 22 return "Sabbatical! Boom!" if sabbatical else "Back to your desk, boy."
The Office VI - Sabbatical
57fe50d000d05166720000b1
[ "Fundamentals", "Strings", "Arrays", "Mathematics" ]
https://www.codewars.com/kata/57fe50d000d05166720000b1
7 kyu
<p>This is the first part of this kata series. Second part is <a href="https://www.codewars.com/kata/adding-words-part-ii/">here</a> and third part is <a href="https://www.codewars.com/kata/adding-words-part-iii/">here</a></p> <p>Add two English words together!</p> <p>Implement a class <code>Arith</code> (struct <code>struct Arith{value : &'static str,}</code> in Rust) such that</p> ```javscript //javascript var k = new Arith("three"); k.add("seven"); //this should return "ten" ``` ```c++ //c++ Arith* k = new Arith("three"); k->add("seven"); //this should return string "ten" ``` ```Rust //Rust let c = Arith{value: "three"}; c.add("seven") // this should return &str "ten" ``` <p><b>Input</b> - Will be between zero and ten and will always be in lower case</p> <p><b>Output</b> - Word representation of the result of the addition. Should be in lower case</p>
reference
class Arith (): def __init__(self, first): self . NUMS = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"] self . first = first def add(self, second): return self . NUMS[self . NUMS . index(self . first) + self . NUMS . index(second)]
Adding words - Part I
592eaf848c91f248ca000012
[ "Mathematics", "Fundamentals" ]
https://www.codewars.com/kata/592eaf848c91f248ca000012
7 kyu
# Introduction Digital Cypher assigns to each letter of the alphabet unique number. For example: ``` a b c d e f g h i j k l m 1 2 3 4 5 6 7 8 9 10 11 12 13 n o p q r s t u v w x y z 14 15 16 17 18 19 20 21 22 23 24 25 26 ``` Instead of letters in encrypted word we write the corresponding number, eg. The word scout: ``` s c o u t 19 3 15 21 20 ``` Then we add to each obtained digit consecutive digits from the key. For example. In case of key equal to `1939` : ``` s c o u t 19 3 15 21 20 + 1 9 3 9 1 --------------- 20 12 18 30 21 m a s t e r p i e c e 13 1 19 20 5 18 16 9 5 3 5 + 1 9 3 9 1 9 3 9 1 9 3 -------------------------------- 14 10 22 29 6 27 19 18 6 12 8 ``` # Task Write a function that accepts `str` string and `key` number and returns an array of integers representing encoded `str`. # Input / Output The `str` input string consists of lowercase characters only.<br/> The `key` input number is a positive integer. # Example ``` Encode("scout",1939); ==> [ 20, 12, 18, 30, 21] Encode("masterpiece",1939); ==> [ 14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8] ``` # Digital cypher series - [Digital cypher vol 1](https://www.codewars.com/kata/592e830e043b99888600002d) - [Digital cypher vol 2](https://www.codewars.com/kata/592edfda5be407b9640000b2) - [Digital cypher vol 3 - missing key](https://www.codewars.com/kata/5930d8a4b8c2d9e11500002a)
reference
from itertools import cycle def encode(message, key): return [ord(a) - 96 + int(b) for a, b in zip(message, cycle(str(key)))]
Digital cypher
592e830e043b99888600002d
[ "Fundamentals", "Ciphers", "Cryptography" ]
https://www.codewars.com/kata/592e830e043b99888600002d
7 kyu
[comment]: # (Hello Contributors, the following guidelines in order of importance should help you write new translations and squash any pesky unintended bugs.) [//]: # (The epsilon of all floating point test case comparisons is 0.01.) [//]: # (Each test case shall pass if the statement "a^2 + b^2 = c^2" is true of the returned object.) [//]: # (The test suite should contain 3 fixed test and exactly 512 random tests.) [//]: # ( The following fixed test shall be used in the test suite as well as the example test suite:) [//]: # ( {a: 3, b: 4, c: 5} from input {a: 3, b: 4}) [//]: # ( {a: 5, c: 13, b: 12} from input {a: 5, c: 13}) [//]: # ( {b: 2, c: 3, a: 2.236} from input {b: 2, c: 3}) [//]: # ( Random tests shall assign float values of a random range between 0.1-10.1 to properties a and b, and 14.5-114.5 to property c, after which, one of the properties is removed at random if target language allows for property insertions and deletions, or has its value replaced with either NaN if possible, or 0 if not.) [//]: # (The test suite should not be sensitive to property insertion or placement order of the returned object.) [//]: # (Validation attempts should not produce any errors outside the solution scope regardless of solution content.) My tired eyes surveyed the horizon to spot a right triangle, made of an unknown material that sparkles in the endless void I have trekked thus far. I hurried towards it. However far it seemed, it can't compare to the uncounted days I have been trapped here in this endless void. To break the monotony, it shall do nicely. Reaching the triangle, I inspected it. It is even more spectacular up close than a far, like a piece of the heavens, just as grand as the best Hubble photo I've ever seen. Adorned onto its striking surface were two numbers, each hugging a side of the triangle in white chalk. ```javascript {a: 3, b: 4} ``` ```coffeescript {a: 3, b: 4} ``` ```csharp Triangle(3, 4, NaN) ``` ```python {'a': 3, 'b': 4} ``` ```ruby {:a => 3, :b => 4} ``` Almost unconsciously, I grabbed at the misshapen chalk piece in my pocket, a small stone shaped calcium oddity I found among the void. I am hit with the sudden urge to write on the cosmic shape, to complete the numbers by filling in the missing side. The shear burning desire scares me, but I did it anyway. With a bit of internal head math, I wrote down my solution. ```javascript {a: 3, b: 4, c: 5} ``` ```coffeescript {a: 3, b: 4, c: 5} ``` ```csharp Triangle(3, 4, 5) ``` ```python {'a': 3, 'b': 4, 'c': 5} ``` ```ruby {:a => 3, :b => 4, :c =>5} ``` The triangle glowed white, contrasting almost blindingly against the surrounding darkness around me. Could it be, that solving this shape would be my salvation, my escape from this dark and empty place? I stared at the shining geometry for what felt like ever, before, with a disappointed sigh, I glanced away from the mesmerizing false hope. Only to catch the sight of two more triangles of right angles. ```javascript {a: 5, c: 13} {b: 2, c: 3} ``` ```coffeescript {a: 5, c: 13} {b: 2, c: 3} ``` ```csharp Triangle(5, NaN, 13) Triangle(NaN, 2, 3) ``` ```python {'a': 5, 'c': 13} {'b': 2, 'c': 3} ``` ```ruby {:a => 5, :c => 13} {:b => 2, :c => 3} ``` Somehow, I knew the third triangle had its first side unmarked, rather than its second, I'll have to take that into account were I to do this right. I idly solved them both, looking on in wonder as they too turned white. ```javascript {a: 5, c: 13, b: 12} {b: 2, c: 3, a: 2.236} ``` ```coffeescript {a: 5, c: 13, b: 12} {b: 2, c: 3, a: 2.236} ``` ```csharp Triangle(5, 12, 13) Triangle(2.236, 2, 3) ``` ```python {'a': 5, 'b': 12, 'c': 13} {'a': 2.236, 'b': 2, 'c': 3} ``` ```ruby {:a => 5, :c => 13, :b => 12} {:b => 2, :c => 3, :a => 2.236} ``` Something on the edge of my peripheral vision moved. I looked up, to be greeted with hundreds of right triangles, like angels from the heavens, coming down right at me. I might need a better solution to turn them all shining white...
reference
def how_to_find_them(rt): return {d: rt[d] if d in rt else (rt["a"] * * 2 + rt["b"] * * 2) * * .5 if d == "c" else (rt["c"] * * 2 - rt[(set("ab") - {d}). pop()] * * 2) * * .5 for d in "abc"}
Markings to White Triangles and How to Find Them
592dcbfedc403be22f00018f
[ "Mathematics", "Fundamentals" ]
https://www.codewars.com/kata/592dcbfedc403be22f00018f
6 kyu
# Task Given an integer array `arr`. Your task is to remove one element, maximize the product of elements. The result is the element which should be removed. If more than one valid results exist, return the smallest one. # Input/Output `[input]` integer array `arr` non-empty unsorted integer array. It contains positive integer, negative integer or zero. `3 ≤ arr.length ≤ 15` `-10 ≤ arr[i] ≤ 10` `[output]` an integer The element that should be removed. # Example For `arr = [1, 2, 3]`, the output should be `1`. For `arr = [-1, 2, -3]`, the output should be `2`. For `arr = [-1, -2, -3]`, the output should be `-1`. For `arr = [-1, -2, -3, -4]`, the output should be `-4`.
reference
from operator import mul from functools import reduce def maximum_product(arr): prod_dct = {x: reduce(mul, arr[: i] + arr[i + 1:], 1) for i, x in enumerate(arr)} return max(arr, key=lambda x: (prod_dct[x], - x))
Simple Fun #312: Maximum Product
592e2446dc403b132d0000be
[ "Fundamentals" ]
https://www.codewars.com/kata/592e2446dc403b132d0000be
7 kyu
The special score(ssc) of an array of integers will be the sum of each integer multiplied by its corresponding index plus one in the array. E.g.: with the array ```[6, 12, -1]``` ``` arr = [6, 12, -1 ] ssc = 1*6 + 2*12 + 3*(-1) = 6 + 24 - 3 = 27 ``` The array given in the example has six(6) permutations and are with the corresponding ssc: ``` Permutations Special Score (ssc) [6, 12, -1] 1*6 + 2*12 + 3*(-1) = 27 [6, -1, 12] 1*6 + 2*(-1) + 3*12 = 40 [-1, 6, 12] 1*(-1) + 2*6 + 3*12 = 47 [-1, 12, 6] 1*(-1) + 2*12 + 3*6 = 41 [12, -1, 6] 1*12 + 2*(-1) + 3*6 = 28 [12, 6, -1] 1*12 + 2*6 + 3*(-1) = 21 ``` The total sum of the ```ssc's``` of all the possible permutations is: ```27 + 40 + 47 + 41 + 28 + 21 = 204``` The maximum value for the ```ssc``` is ```47```. The minimum value for the ```ssc``` is ```21```. We need a special function ```ssc_forperm()``` that receives an array of uncertain number of elements (the elements may occur more than once) and may output a list of dictionaries with the following data: ``` [{"total perm":__}, {"total ssc": ___}, {"max ssc": __}, {"min ssc": __}] ``` For the example we have above will be: ```python ssc_forperm([6, 12, -1]) = [{"total perm":6}, {"total ssc:204}, {"max ssc":47}, {"min ssc":21}] ``` You may assume that you will never receive an empty array. Also you will never receive an array with the same element in all the positions like [1, 1, 1, 1 ,1], but you may have elements occuring twice or more like [1, 1, 1, 2, 3] Enjoy it!!
reference
from itertools import permutations def ssc_forperm(arr): perms = set(p for p in permutations(arr)) values = [sum((x + 1) * y for x, y in enumerate(i)) for i in perms] return [{"total perm": len(perms)}, {"total ssc": sum(values)}, {"max ssc": max(values)}, {"min ssc": min(values)}]
Permutations Of An Array And Associated Values
562c5ea7b5fe27d303000054
[ "Fundamentals", "Mathematics", "Data Structures", "Permutations", "Algorithms" ]
https://www.codewars.com/kata/562c5ea7b5fe27d303000054
6 kyu
If we have an integer of n digits, ```d1d2d3d4d5....dn```, we define the following scores: score_prod = 1d<sub>1</sub> + 2d<sub>2</sub> + 3d<sub>3</sub> + 4d<sub>4</sub> + 5d<sub>5</sub> + .... + nd<sub>n</sub> score_pow = 1<sup>d1</sup> + 2<sup>d2</sup> + 3<sup>d3</sup> + 4<sup>d4</sup> + 5<sup>d5</sup> + .... + n<sup>dn</sup> We want to find the integers that its ```score_pow``` multiplied by a certain integer ```k ``` is divisible by the sum of the divisors of ```score_prod ``` In the sum of the divisors, ```1``` and the ```score_prod``` themselves are addens. In this kata you have to create the function ```find_int()```, that will receive three arguments: - The extreme values of a range (a, b), ```a``` as a start value and ```b``` as an upper limit, both included. - An integer ```k``` such that ```1 <= k <= 100 ``` The function will output a tuple with the amount of found integers and an array with the sorted integers that fulfill the above condition. Let's see some cases: ```python test.describe("Basic Tests") a = 100 b = 200 k = 1 find_int(a, b, k) == (7, [100, 110, 120, 135, 195, 197, 200]) a = 500 b = 700 k = 2 find_int(a, b, k) == (18, [500, 510, 531, 532, 535, 553, 570, 611, 612, 614, 617, 625, 627, 631, 634, 671, 695, 699]) a = 500 b = 700 k = 3 find_int(a, b, k) == (16, [501, 511, 532, 535, 553, 560, 571, 581, 613, 614, 617, 620, 625, 644, 645, 674]) a = 500 b = 700 k = 4 find_int(a, b, k) == (30, [500, 510, 531, 532, 534, 535, 553, 558, 570, 600, 611, 612, 614, 615, 617, 625, 627, 631, 634, 636, 637, 640, 671, 675, 679, 682, 692, 693, 695, 699]) ``` For the tests always ```a < b```. Enjoy it!!
reference
from functools import lru_cache def score_pow(n): return sum(i * * int(d) for i, d in enumerate(str(n), 1)) def score_prod(n): return sum(i * int(d) for i, d in enumerate(str(n), 1)) @ lru_cache(None) def div_sum(n): total = 0 for div in range(1, n / / 2 + 1): if n % div == 0: total += div return total + n def find_int(a, b, k): res = [n for n in range(a, b + 1) if score_pow(n) * k % div_sum(score_prod(n)) == 0] return len(res), res
Check a Curious Divisibility. (Brute force version)
5681e4ff81ba1b0cdb000031
[ "Fundamentals", "Mathematics" ]
https://www.codewars.com/kata/5681e4ff81ba1b0cdb000031
6 kyu
<p>Bleatrix Trotter the sheep has devised a strategy that helps her fall asleep faster. First, she picks a number <code>N</code>. Then she starts naming <code>N</code>, <code>2 × N</code>, <code>3 × N</code>, and so on.</p> <p>Whenever she names a number, she thinks about all of the digits in that number. She keeps track of which digits <code>(0, 1, 2, 3, 4, 5, 6, 7, 8, and 9)</code> she has seen <em>at least once</em> so far as part of any number she has named. <u>Once she has seen each of the ten digits at least once, she will fall asleep.</u></p> <p>Bleatrix must start with <code>N</code> and must always name <code>(i + 1) × N</code> directly after <code>i × N</code>.</p> <p>For example, suppose that Bleatrix picks <code>N = 1692</code>. She would count as follows: <ul> <li>N = 1692. Now she has seen the digits 1, 2, 6, and 9. <li>2N = 3384. Now she has seen the digits 1, 2, 3, 4, 6, 8, and 9. <li>3N = 5076. Now she has seen all ten digits, and falls asleep. </ul> <p>The purpose of this kata is to return the last number Bleatrix Trotter sees before falling asleep.</p> <h5>Input</h5> Will always be positive integer or zero <h5>Output</h5> The last number Bleatrix Trotter sees or "INSOMNIA" <b>(-1 in Rust, C++ and COBOL)</b> if she will count forever <p><em>Please note, this challenge is not my idea. It's from <a href="https://code.google.com/codejam/contest/6254486/dashboard">Google Code Jam 2016</a></em></p>
reference
def trotter(n): i, numStr, numList = 0, '', [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] if n == 0: return ('INSOMNIA') while all([i in numStr for i in numList]) != True: i += 1 numStr = numStr + str(n * i) return (i * n)
Bleatrix Trotter (The Counting Sheep)
59245b3c794d54b06600002a
[ "Fundamentals", "Algorithms" ]
https://www.codewars.com/kata/59245b3c794d54b06600002a
6 kyu
A carpet shop sells carpets in different varieties. Each carpet can come in a different roll width and can have a different price per square meter. Write a function `cost_of_carpet` which calculates the cost (rounded to 2 decimal places) of carpeting a room, following these constraints: * The carpeting has to be done in one unique piece. If not possible, retrun `"error"`. * The shop sells any length of a roll of carpets, but always with a full width. * The cost has to be minimal. * The length of the room passed as argument can sometimes be shorter than its width (because we define these relatively to the position of the door in the room). * A length or width equal to zero is considered invalid, return `"error"` if it occurs. <hr> <h1>INPUTS: `room_width`, `room_length`, `roll_width`, `roll_cost` as floats. <h1>OUTPUT: `"error"` or the minimal cost of the room carpeting, rounded to two decimal places.
algorithms
def cost_of_carpet(l, w, r, c): w, l = sorted((w, l)) return "error" if r < w or w == 0 else round((l if r < l else w) * r * c, 2)
Carpet shop
592c6d71d2c6d91643000009
[ "Algorithms" ]
https://www.codewars.com/kata/592c6d71d2c6d91643000009
6 kyu
<p>We have 3 equations with 3 unknowns <code>x, y, and z</code> and we are to solve for these unknowns.</p> <p>Equations <code>4x -3y +z = -10</code>, <code>2x +y +3z = 0</code>, and <code>-x +2y -5z = 17</code> will be passed in as an array of <code>[[4, -3, 1, -10], [2, 1, 3, 0], [-1, 2, -5, 17]]</code> and the result should be returned as an array like <code>[1, 4, -2]</code> (i.e. <code>[x, y, z]</code>).</p> Note: In C++ do not use <code>new</code> or <code>malloc</code> to allocate memory for the returned variable as allocated memory will not be freed in the Test Cases. Setting the variable as <code>static</code> will do.
reference
import numpy as np def solve_eq(eq): a = np . array([arr[: 3] for arr in eq]) b = np . array([arr[- 1] for arr in eq]) return [round(x) for x in np . linalg . solve(a, b)]
Simultaneous Equations - Three Variables
59280c056d6c5a74ca000149
[ "Mathematics" ]
https://www.codewars.com/kata/59280c056d6c5a74ca000149
5 kyu
The goal is to write a pair of functions the first of which will take a string of binary along with a specification of bits, which will return a numeric, signed complement in two's complement format. The second will do the reverse. It will take in an integer along with a number of bits, and return a binary string. https://en.wikipedia.org/wiki/Two's_complement Thus, to_twos_complement should take the parameters binary = "0000 0001", bits = 8 should return 1. And, binary = "11111111", bits = 8 should return -1 . While, from_twos_complement should return "00000000" from the parameters n = 0, bits = 8 . And, "11111111" from n = -1, bits = 8. You should account for some edge cases.
games
def to_twos_complement(binary, bits): return int(binary . replace(' ', ''), 2) - 2 * * bits * int(binary[0]) def from_twos_complement(n, bits): return '{:0{}b}' . format(n & 2 * * bits - 1, bits)
Two's Complement
58d4785a2285e7795c00013b
[ "Binary", "Puzzles" ]
https://www.codewars.com/kata/58d4785a2285e7795c00013b
6 kyu
Here's another staple for the functional programmer. You have a sequence of values and some predicate for those values. You want to get the longest prefix of elements such that the predicate is true for each element. We'll call this the `takeWhile` function. It accepts two arguments. The first is the sequence of values, and the second is the predicate function. The function does not change the value of the original sequence. ### Example: ``` sequence : [2,4,6,8,1,2,5,4,3,2] predicate: is an even number result : [2,4,6,8] ``` Your task is to implement the takeWhile function. If you've got a [span function](http://www.codewars.com/kata/the-span-function) lying around, this is a one-liner! Also, if you liked this problem, you'll surely love [the dropWhile function](http://www.codewars.com/kata/the-dropwhile-function). ~~~if:lambdacalc ### Encodings purity: `LetRec` numEncoding: `BinaryScott` export constructors `nil, cons` and deconstructor `foldl` for your `List` encoding export constructors `False, True` for your `Boolean` encoding ~~~
algorithms
from itertools import takewhile def take_while(arr, pred_fun): return list(takewhile(pred_fun, arr))
The takeWhile Function
54f9173aa58bce9031001548
[ "Functional Programming", "Arrays", "Algorithms", "Lists", "Data Structures" ]
https://www.codewars.com/kata/54f9173aa58bce9031001548
6 kyu
The integer `64` is the first integer that has all of its digits even and furthermore, is a perfect square. The second one is `400` and the third one `484`. Give the numbers of this sequence that are in the range `[a,b]` (both values inclusive) Examples: ``` Even digit squares between 100 to 1000: [400, 484] (the output should be sorted) Even digit squares between 1000 to 4000: [] ``` Features of the random tests: ``` number of tests = 167 maximum value for a = 1e10 maximum value for b = 1e12 ``` You do not have to check the entries; `a` and `b` are always positive integers and `a < b`. Happy coding!!
reference
def is_even(x): return all(int(i) % 2 == 0 for i in str(x)) def even_digit_squares(a, b): first = int(a * * (1 / 2)) + 1 last = int(b * * (1 / 2)) + 1 return sorted([x * x for x in range(first, last) if is_even(x * x)])
#1 Sequences: Pure Even Digit Perfect Squares (P.E.D.P.S)
59290e641a640c53d000002c
[ "Mathematics", "Algorithms" ]
https://www.codewars.com/kata/59290e641a640c53d000002c
6 kyu
You will be given an array of positive integers. The array should be sorted by the amount of distinct perfect squares and reversed, that can be generated from each number permuting its digits. E.g.: ```arr = [715, 112, 136, 169, 144]``` ``` Number Perfect Squares w/ its Digits Amount 715 - 0 112 121 1 136 361 1 169 169, 196, 961 3 144 144, 441 2 ``` So the output will have the following order: ```[169, 144, 112, 136, 715]``` When we have two or more numbers with the same amount of perfect squares in their permutations, we sorted by their values. In the example given above, we can see that 112 and 136 both generate a perfect square. So 112 comes first. Examples for this kata: ```python sort_by_perfsq([715, 112, 136, 169, 144]) == [169, 144, 112, 136, 715] # number of perfect squares: 3 2 1 1 0 ``` We may have in the array numbers that belongs to the same set of permutations. ```python sort_by_perfsq([234, 61, 16, 441, 144, 728]) == [144, 441, 16, 61, 234, 728] # number of perfect squares: 2 2 1 0 0 0 ``` Features of the random tests: ~~~if:ruby,python,d,rust,go - Number of tests: 80 - Arrays between 4 and 20 elements - Integers having from 1 to 7 digits included ~~~ ~~~if:javascript, - Number of tests: 30 - Arrays between 4 and 16 elements - Integers having from 1 to 7 digits included ~~~ Enjoy it!!
reference
from collections import defaultdict SQUARES = [x * * 2 for x in range(1, 3163)] DIGITS = defaultdict(int) for sqr in SQUARES: DIGITS['' . join(sorted(str(sqr)))] += 1 def sort_by_perfsq(arr): return sorted(arr, key=lambda n: (- DIGITS['' . join(sorted(str(n)))], n))
Sorting Arrays by the Amount of Perfect Squares that Each Element May Generate
582fdcc039f654905400001e
[ "Algorithms", "Mathematics", "Number Theory", "Permutations" ]
https://www.codewars.com/kata/582fdcc039f654905400001e
5 kyu
<h2>Christmas Present Calculator</h2> After we find out if <a href="https://www.codewars.com/kata/5857e8bb9948644aa1000246">Santa can save Christmas</a> there is another task to face. <br> <br> Santa's little helper aren't sick anymore. They are ready to give away presents again. But some of them are still weak. <br> This leads to more productive elves than others. <br> <br> <b>How many presents can Santa distribute this christmas?</b> <h3>Your Task:</h3> You will get two inputs.<br> One dictionary with the producitivity of each elf like the following: <code>{"Santa": 1, "elf_1": 1, "elf_2": 1, "elf_3": 2, "elf_4": 3}</code> and a string array with the time needed for each present like the following: <code>"hh:mm:ss"</code> <br> <br> The productivity describes the workload an elf can do each day: <br> <br> <code>//productivity 1 = 24 hours each day</code><br> <code>//productivity 2 = 48 hours each day</code><br> <code>...</code> <br> <br> <b>Return the number of present they can distribute at maximum.</b> <br> <br> Note that: <ul> <li>They have only 24 hours</li> <li>They try to give out as much as presents as possible (the ones with less time first)</li> <li>All the elves can work on multiple tasks. You can count it as one work capacity</li> </ul> <br> <br> <b>This kata is part of the Collection "Date fundamentals":</b> <ul> <li><a href="https://www.codewars.com/kata/count-the-days/javascript">#1 Count the Days!</a></li> <li><a href="https://www.codewars.com/kata/minutes-to-midnight">#2 Minutes to Midnight</a></li> <li><a href="https://www.codewars.com/kata/can-santa-save-christmas">#3 Can Santa save Christmas?</a></li> <li>#4 How Many Presents?</li> </ul>
reference
def count_presents(prod, presents): time = sum(prod . values()) * 24 pres_count = 0 for i in sorted(presents): t = int(i[: 2]) + (int(i[3: 5]) / 60) + (int(i[6:]) / 3600) if t <= time: pres_count += 1 time -= t return pres_count
Christmas Present Calculator
585b989c45376c73e30000d1
[ "Date Time", "Fundamentals" ]
https://www.codewars.com/kata/585b989c45376c73e30000d1
6 kyu
<h2> Introduction </h2> The GADERYPOLUKI is a simple substitution cypher used in scouting to encrypt messages. The encryption is based on short, easy to remember key. The key is written as paired letters, which are in the cipher simple replacement. The most frequently used key is "GA-DE-RY-PO-LU-KI". ``` g => a a => g d => e e => d etc. ``` The letters, which are not on the list of substitutes, stays in the encrypted text without changes. Other keys often used by Scouts: ``` PO-LI-TY-KA-RE-NU KA-CE-MI-NU-TO-WY KO-NI-EC-MA-TU-RY ZA-RE-WY-BU-HO-KI BA-WO-LE-TY-KI-JU RE-GU-LA-MI-NO-WY ``` <h2>Task</h2> Our scouts had party yestarday and they had too much milk and cookies. As the result all of them forgot the key. Your task is to help scouts to find the key that they used for encryption. Fortunately they have some messages that are already encoded. <h2>Input</h2> The function accepts has two arrays. <br/> The `messages` string array consists of lowercase characters and whitespace characters. The strings on the `messages` array are scout's messages before encrytption. <br/> The `secrets` string array consists of lowercase characters and whitespace characters. The strings on the `messages` array are scout's messages after encrytption. <h2>Output</h2> Return string should consists of lowercase characters only. The pairs of substitution should be ordered by the first letter of substitution. The letters in each pair should be in alphabethic order. <br> ``` ga => incorret output (error: g is after a ) ag => correct output deag => incorrect output (error: de is after ag) agde => correct output ``` <h2>Example</h2> ```csharp string[] messages = { "dance on the table", "hide my beers", "scouts rocks" }; string[] secretes = { "egncd pn thd tgbud" ,"hked mr bddys" ,"scplts ypcis" }; FindTheKey(messages, secretes); //=> agdeikluopry ``` ```javascript var messages = [ "dance on the table", "hide my beers", "scouts rocks" ]; var secrets = [ "egncd pn thd tgbud" ,"hked mr bddys" ,"scplts ypcis" ]; findTheKey(messages, secrets); //=> agdeikluopry ``` ```ruby messages = [ "dance on the table", "hide my beers", "scouts rocks" ]; secrets = [ "egncd pn thd tgbud" ,"hked mr bddys" ,"scplts ypcis" ]; findTheKey(messages, secrets); //=> agdeikluopry ``` # GADERYPOLUKI collection <table border="0" cellpadding="0" cellspacing="0"> <tr> <td ><a href="https://www.codewars.com/kata/592a6ad46d6c5a62b600003f" target="_blank">GADERYPOLUKI cypher vol 1</a></td> </tr> <tr> <td ><a href="https://www.codewars.com/kata/592b7b16281da94068000107" target="_blank">GADERYPOLUKI cypher vol 2</a></td> </tr> <tr> <td ><a href="https://www.codewars.com/kata/592bdf59912f2209710000e9" target="_blank">GADERYPOLUKI cypher vol 3 - Missing Key</a></td> </tr> <tr> <td ><a href="https://www.codewars.com/kata/592ceef6af58a64c7f00003c" target="_blank">GADERYPOLUKI cypher vol 4 - Missing key madness</a></td> </tr> </table>
reference
def find_the_key(messages, secrets): return '' . join(sorted({a + b for a, b in map(sorted, zip('' . join(messages), '' . join(secrets))) if a != b}))
GA-DE-RY-PO-LU-KI cypher vol 3 - Missing key
592bdf59912f2209710000e9
[ "Fundamentals", "Ciphers", "Cryptography" ]
https://www.codewars.com/kata/592bdf59912f2209710000e9
6 kyu
## Funny Dots You will get two integers `n` (width) and `m` (height) and your task is to draw the following pattern. Each line is seperated with a newline (`\n`) Both integers are equal or greater than 1; no need to check for invalid parameters. ## Examples <pre> <code> +---+---+---+ +---+ | o | o | o | dot(1, 1) => | o | dot(3, 2) => +---+---+---+ +---+ | o | o | o | +---+---+---+ </code> </pre> --- #### Serie: ASCII Fun <ul> <li><a href="https://www.codewars.com/kata/ascii-fun-number-1-x-shape">ASCII Fun #1: X-Shape</a></li> <li><a href="https://www.codewars.com/kata/ascii-fun-number-2-funny-dots">ASCII Fun #2: Funny Dots</a></li> <li><a href="https://www.codewars.com/kata/ascii-fun-number-3-puzzle-tiles">ASCII Fun #3: Puzzle Tiles</a></li> <li><a href="https://www.codewars.com/kata/ascii-fun-number-4-build-a-pyramid">ASCII Fun #4: Build a pyramid</a></li> </ul>
algorithms
def dot(n, m): sep = '+---' * n + '+' dot = '| o ' * n + '|' return '\n' . join([sep, dot] * m + [sep])
ASCII Fun #2: Funny Dots
59098c39d8d24d12b6000020
[ "ASCII Art" ]
https://www.codewars.com/kata/59098c39d8d24d12b6000020
6 kyu
<h2> Introduction </h2> Mr. Safety loves numeric locks and his Nokia 3310. He locked almost everything in his house. He is so smart and he doesn't need to remember the combinations. He has an algorithm to generate new passcodes on his Nokia cell phone. <br/> <img src='https://i.postimg.cc/2yCH2WhV/Nokia-3310.jpg' border='0' alt='postimage'/> <h2> Task </h2> Can you crack his numeric locks? Mr. Safety's treasures wait for you. Write an algorithm to open his numeric locks. Can you do it without his Nokia 3310? <h2>Input </h2> The `str` or `message` (Python) input string consists of lowercase and upercase characters. It's a real object that you want to unlock. <h2>Output </h2> Return a string that only consists of digits. <h2>Example</h2> ``` unlock("Nokia") // => 66542 unlock("Valut") // => 82588 unlock("toilet") // => 864538 ```
games
def unlock(message): return message . lower(). translate( message . maketrans("abcdefghijklmnopqrstuvwxyz", "22233344455566677778889999"))
Mr. Safety's treasures
592c1dfb912f22055b000099
[ "Puzzles" ]
https://www.codewars.com/kata/592c1dfb912f22055b000099
6 kyu
I want to honor the movie "X plus Y" reproducing here one of his mathematical problems. Although I can not pose the problem with the fidelity it deserves I have implemented it so that it can be properly tested. #### Original problem ##### There are N cards in a row and they can be face up or face down. A turn consists of taking two adjacent cards where the left one is face up and the right one can be face up or face down and flipping them both. Show that this process terminates. ## Kata Here is how this problem is adapted for this kata ... You will be provided with a string of random length. - A '1' represents card facing up. '0' represents cards facing down. - A turn consists of taking two adjacent cards where the left one is face up and the right one can be face up or face down and flipping them both. - If the only "1" that remains is the rightmost card, then just flip it on the final turn. Return the <b>minimal</b> count of turns needed to turn all the cards facing down. - Only strings containing 1's and 0's are valid. - An invalid string should return 0 turns. Enjoy the film if you can!
reference
from itertools import accumulate from operator import xor def x_plus_y(s): return sum(accumulate(map(int, s), xor))
X plus Y Card problem
59269e371a640c0e98000085
[ "Mathematics", "Fundamentals" ]
https://www.codewars.com/kata/59269e371a640c0e98000085
6 kyu
Consider the following class: ```csharp public class Animal { public string Name { get; set; } public int NumberOfLegs { get; set; } } ``` ```javascript var Animal = { name: "Cat", numberOfLegs: 4 } ``` ```python class Animal: def __init__(self, name, number_of_legs): self.name = name self.number_of_legs = number_of_legs ``` Write a method that accepts a list of objects of type Animal, and returns a new list. The new list should be a copy of the original list, sorted first by the animal's number of legs, and then by its name. If an empty list is passed in, it should return an empty list back.
reference
def sort_animals(input): return sorted(input, key=lambda x: (x . number_of_legs, x . name))
Sort My Animals
58ff1c8b13b001a5a50005b4
[ "Lists", "Sorting", "Fundamentals" ]
https://www.codewars.com/kata/58ff1c8b13b001a5a50005b4
6 kyu
<h2> Introduction </h2> The GADERYPOLUKI is a simple substitution cypher used in scouting to encrypt messages. The encryption is based on short, easy to remember key. The key is written as paired letters, which are in the cipher simple replacement. The most frequently used key is "GA-DE-RY-PO-LU-KI". ``` G => A g => a a => g A => G D => E etc. ``` The letters, which are not on the list of substitutes, stays in the encrypted text without changes. Other keys often used by Scouts: ``` PO-LI-TY-KA-RE-NU KA-CE-MI-NU-TO-WY KO-NI-EC-MA-TU-RY ZA-RE-WY-BU-HO-KI BA-WO-LE-TY-KI-JU RE-GU-LA-MI-NO-WY ``` <h2>Task</h2> Your task is to help scouts to encrypt and decrypt thier messages. Write the `Encode` and `Decode` functions. <h2>Input/Output</h2> The function should have two parameters. <br/> The `message` input string consists of lowercase and uperrcase characters and whitespace character.<br/> The `key` input string consists of only lowercase characters. <br/>The substitution has to be case-sensitive. <h2>Example</h2> ```csharp Encode("ABCD", "agedyropulik"); // => GBCE Encode("Ala has a cat", "gaderypoluki"); // => Gug hgs g cgt Decode("Dkucr pu yhr ykbir","politykarenu") // => Dance on the table Decode("Hmdr nge brres","regulaminowy") // => Hide our beers ``` ```javascript encode("ABCD", "agedyropulik"); // => GBCE encode("Ala has a cat", "gaderypoluki"); // => Gug hgs g cgt decode("Dkucr pu yhr ykbir","politykarenu") // => Dance on the table decode("Hmdr nge brres","regulaminowy") // => Hide our beers ``` ```ruby encode("ABCD", "agedyropulik"); // => GBCE encode("Ala has a cat", "gaderypoluki"); // => Gug hgs g cgt decode("Dkucr pu yhr ykbir","politykarenu") // => Dance on the table decode("Hmdr nge brres","regulaminowy") // => Hide our beers ``` # GADERYPOLUKI collection <table border="0" cellpadding="0" cellspacing="0"> <tr> <td ><a href="https://www.codewars.com/kata/592a6ad46d6c5a62b600003f" target="_blank">GADERYPOLUKI cypher vol 1</a></td> </tr> <tr> <td ><a href="https://www.codewars.com/kata/592b7b16281da94068000107" target="_blank">GADERYPOLUKI cypher vol 2</a></td> </tr> <tr> <td ><a href="https://www.codewars.com/kata/592bdf59912f2209710000e9" target="_blank">GADERYPOLUKI cypher vol 3 - Missing Key</a></td> </tr> <tr> <td ><a href="https://www.codewars.com/kata/592ceef6af58a64c7f00003c" target="_blank">GADERYPOLUKI cypher vol 4 - Missing key madness</a></td> </tr> </table>
reference
def encode(str, key): key = key . lower() + key . upper() dict = {char: key[i - 1] if i % 2 else key[i + 1] for i, char in enumerate(key)} return '' . join(dict . get(char, char) for char in str) decode = encode
GA-DE-RY-PO-LU-KI cypher vol 2
592b7b16281da94068000107
[ "Fundamentals", "Ciphers", "Cryptography" ]
https://www.codewars.com/kata/592b7b16281da94068000107
6 kyu
<h2> Introduction </h2> The GADERYPOLUKI is a simple substitution cypher used in scouting to encrypt messages. The encryption is based on short, easy to remember key. The key is written as paired letters, which are in the cipher simple replacement. The most frequently used key is "GA-DE-RY-PO-LU-KI". ``` G => A g => a a => g A => G D => E etc. ``` The letters, which are not on the list of substitutes, stays in the encrypted text without changes. <h2>Task</h2> Your task is to help scouts to encrypt and decrypt thier messages. Write the `Encode` and `Decode` functions. <h2>Input/Output</h2> The input string consists of lowercase and uperrcase characters and white . The substitution has to be case-sensitive. <h2>Example</h2> ```csharp Encode("ABCD") // => GBCE Encode("Ala has a cat") // => Gug hgs g cgt Encode("gaderypoluki"); // => agedyropulik Decode("Gug hgs g cgt") // => Ala has a cat Decode("agedyropulik") // => gaderypoluki Decode("GBCE") // => ABCD ``` ```javascript encode("ABCD") // => GBCE encode("Ala has a cat") // => Gug hgs g cgt encode("gaderypoluki"); // => agedyropulik decode("Gug hgs g cgt") // => Ala has a cat decode("agedyropulik") // => gaderypoluki decode("GBCE") // => ABCD ``` ```ruby encode("ABCD") // => GBCE encode("Ala has a cat") // => Gug hgs g cgt encode("gaderypoluki"); // => agedyropulik decode("Gug hgs g cgt") // => Ala has a cat decode("agedyropulik") // => gaderypoluki decode("GBCE") // => ABCD ``` # GADERYPOLUKI collection <table border="0" cellpadding="0" cellspacing="0"> <tr> <td ><a href="https://www.codewars.com/kata/592a6ad46d6c5a62b600003f" target="_blank">GADERYPOLUKI cypher vol 1</a></td> </tr> <tr> <td ><a href="https://www.codewars.com/kata/592b7b16281da94068000107" target="_blank">GADERYPOLUKI cypher vol 2</a></td> </tr> <tr> <td ><a href="https://www.codewars.com/kata/592bdf59912f2209710000e9" target="_blank">GADERYPOLUKI cypher vol 3 - Missing Key</a></td> </tr> <tr> <td ><a href="https://www.codewars.com/kata/592ceef6af58a64c7f00003c" target="_blank">GADERYPOLUKI cypher vol 4 - Missing key madness</a></td> </tr> </table>
reference
dict = {i[0]: i[1] for i in ['GA', 'DE', 'RY', 'PO', 'LU', 'KI', 'AG', 'ED', 'YR', 'OP', 'UL', 'IK', 'ga', 'de', 'ry', 'po', 'lu', 'ki', 'ag', 'ed', 'yr', 'op', 'ul', 'ik']} def encode(s): return '' . join([dict[i] if i in dict else i for i in s]) def decode(s): return '' . join([dict[i] if i in dict else i for i in s])
GA-DE-RY-PO-LU-KI cypher
592a6ad46d6c5a62b600003f
[ "Fundamentals", "Ciphers", "Cryptography" ]
https://www.codewars.com/kata/592a6ad46d6c5a62b600003f
7 kyu
<h2>Is the number even?</h2> If the numbers is even return `true`. If it's odd, return `false`. <br><br><br><br><br> Oh yeah... the following symbols/commands have been disabled! - use of `%` - use of `.even?` in Ruby - use of `mod` in Python
reference
def is_even(n): return not n & 1
isEven? - Bitwise Series
592a33e549fe9840a8000ba1
[ "Restricted", "Fundamentals" ]
https://www.codewars.com/kata/592a33e549fe9840a8000ba1
7 kyu
Write a function that accepts two numbers `a` and `b` and returns whether `a` is smaller than, bigger than, or equal to `b`, as a string. ``` (5, 4) ---> "5 is greater than 4" (-4, -7) ---> "-4 is greater than -7" (2, 2) ---> "2 is equal to 2" ``` There is only one problem... You cannot use `if` statements, and you cannot use the ternary operator `? :`. In fact the word `if` and the character `?` are not allowed in your code. ___ <center> You are always welcome to check out some of my other katas: <b>Very Easy (Kyu 8)</b> <a href="https://www.codewars.com/kata/5926d7494b2b1843780001e6">Add Numbers</a> <b>Easy (Kyu 7-6)</b> <a href="https://www.codewars.com/kata/590ee3c979ae8923bf00095b">Convert Color image to greyscale</a><br> <a href="https://www.codewars.com/kata/591190fb6a57682bed00014d">Array Transformations</a><br> <a href="https://www.codewars.com/kata/5914e068f05d9a011e000054">Basic Compression</a><br> <a href="https://www.codewars.com/kata/5927db23fb1f934238000015">Find Primes in Range</a><br> <a href="https://www.codewars.com/kata/592915cc1fad49252f000006">No Ifs No Buts</a> <b>Medium (Kyu 5-4)</b> <a href="https://www.codewars.com/kata/5910b92d2bcb5d98f8000001">Identify Frames In An Image</a><br> <a href="https://www.codewars.com/kata/5912950fe5bc241f9b0000af">Photoshop Like - Magic Wand</a><br> <a href="https://www.codewars.com/kata/59255740ca72049e760000cd">Scientific Notation</a><br> <a href="https://www.codewars.com/kata/59267e389b424dcd3f0000c9">Vending Machine - FSA</a><br> <a href="https://www.codewars.com/kata/59293c2cfafd38975600002d">Find Matching Parenthesis</a> <b>Hard (Kyu 3-2)</b> <a href="https://www.codewars.com/kata/59276216356e51478900005b">Ascii Art Generator</a>
reference
def no_ifs_no_buts(a, b): d = {a < b: 'smaller than', a == b: 'equal to', a > b: 'greater than'} return f' { a } is { d [ True ]} { b } '
No ifs no buts
592915cc1fad49252f000006
[ "Restricted", "Fundamentals" ]
https://www.codewars.com/kata/592915cc1fad49252f000006
7 kyu
Write a function `filterLucky`/`filter_lucky()` that accepts a list of integers and filters the list to only include the elements that contain the digit 7. For example, ``` ghci> filterLucky [1,2,3,4,5,6,7,68,69,70,15,17] [7,70,17] ``` Don't worry about bad input, you will always receive a finite list of integers.
reference
def filter_lucky(lst): return [n for n in lst if '7' in str(n)]
Find the lucky numbers
580435ab150cca22650001fb
[ "Fundamentals" ]
https://www.codewars.com/kata/580435ab150cca22650001fb
7 kyu
# Task Some light bulbs are placed in a circle (clockwise direction). Each one is either `on (1)` or `off (0)`. Every turn, the light bulbs change their states. If a light bulb was `on` at the `previous turn`, the light bulb to the `right of it` changes its state, i.e. if `lights[0]` is `on`. then, if `lights[1]` was `on`, it turns off and vice versa. Find the state of the light bulbs after `n` turns. # Input/Output - `[input]` integer array `lights` A non-empty array, the initial states of the light bulbs. `0 ≤ lights.length ≤ 100` - `[input]` integer `n` The number of turns. `0 ≤ n ≤ 300` - `[output]` an integer array The final light bulbs' states. ~~~if:lambdacalc # Encodings purity: `LetRec` numEncoding: `Church` export constructors `nil, cons` and deconstructor `foldl` for your `List` encoding ~~~ # Example For `lights = [0,1,1,0,1,1], n = 2`, the output should be `[1, 0, 1, 1, 0, 1]` Here are how the light bulbs' states change each turn: ``` 0) 0 1 1 0 1 1 -- orginal state 1) 1 1 0 1 1 0 -- 1st turn 2) 1 0 1 1 0 1 -- 2nd turn ``` If it's hard to understand, please look at the following "image" ;-) ``` turn 0: 0 <--- lights[0] 1 1 <--- lights[5] (left) and lights[1] (right) 1 1 <--- lights[4] (left) and lights[2] (right) 0 <--- lights[3] turn 1: 1 0 1 1 0 1 lights[0] changed to on, because its left side (lights[5]) is on at the previous turn (turn 0) lights[2] changed to off, because its left side (lights[1]) is on at the previous turn (turn 0) lights[3] changed to on, because its left side (lights[2]) is on at the previous turn (turn 0) lights[5] changed to off, because its left side (lights[4]) is on at the previous turn (turn 0) turn 2: 1 1 0 0 1 1 lights[1] changed to off, because its left side (lights[0]) is on at the previous turn (turn 1) lights[2] changed to on, because its left side (lights[1]) is on at the previous turn (turn 1) lights[4] changed to off, because its left side (lights[3]) is on at the previous turn (turn 1) lights[5] changed to on, because its left side (lights[4]) is on at the previous turn (turn 1) ```
algorithms
def light_bulbs(lights, n): return lights if not n else light_bulbs([b ^ lights[i - 1] for i, b in enumerate(lights)], n - 1)
Simple Fun #219: Light Bulbs
5901555b63bf404a66000029
[ "Puzzles", "Algorithms" ]
https://www.codewars.com/kata/5901555b63bf404a66000029
6 kyu
# Task Amin and Sam are playing a game in which Amin gives Sam two binary numbers `a` and `b`, written as strings, and asks him to calculate the minimum number of right rotate of string `a` that minimize the `Hamming distance` between `a` and `b`. Help Sam answer this question for the given `a` and `b`. A Hamming distance between strings of equal length `a` and `b` is defined as the number of positions `i`, such that `a[i] ≠ b[i]`. If you do not completely understand what Hamming distance is, try [this kata](https://www.codewars.com/kata/simple-fun-number-141-hamming-distance). ## Input 2 strings, `a` and `b`, of the same length consisting of `"0"` and `"1"` characters. ## Output The lowest possible number of right-rotations of `a` required to minimize the Hamming distance between `a` and `b`. ### Examples Example #1: for `a = "100"` and `b = "001"` the output should be `2`. ``` After 0 rotation, a = 100, | | b = 001 the Hamming distance between a and b is 2. After 1 rotation, a = 010, || b = 001 the Hamming distance between a and b is 2. After 0 rotation, a = 001, b = 001 the Hamming distance between a and b is 0. 0 is the minimum Hamming distance, so the answer is 2(it means 2nd retation). ``` Example #2: for `a = "10010011"` and `b = "00100101"` the output should be `7`. ``` After 0 rotation, a = 10010011, | || || b = 00100101 the Hamming distance between a and b is 5. After 1 rotation, a = 11001001, ||| || b = 00100101 the Hamming distance between a and b is 5. After 2 rotation, a = 11100100, || | b = 00100101 the Hamming distance between a and b is 3. After 3 rotation, a = 01110010, | | ||| b = 00100101 the Hamming distance between a and b is 5. After 4 rotation, a = 00111001, ||| b = 00100101 the Hamming distance between a and b is 3. After 5 rotation, a = 10011100, | ||| | b = 00100101 the Hamming distance between a and b is 5. After 6 rotation, a = 01001110, || | || b = 00100101 the Hamming distance between a and b is 5. After 7 rotation, a = 00100111, | b = 00100101 the Hamming distance between a and b is 1. 1 is the minimum Hamming distance, so the answer is 7(it means 7th retation). ```
algorithms
def hamming_rotate(a, b): def hamming_dist(i): return sum(d != b[(j + i) % len(a)] for j, d in enumerate(a)) return min(range(len(a)), key=hamming_dist)
Simple Fun #308: Hamming Rotate
592786effb1f93349b0000b2
[ "Algorithms" ]
https://www.codewars.com/kata/592786effb1f93349b0000b2
6 kyu
# Task John is a typist. He has a habit of typing: he never use the `Shift` key to switch case, just using only `Caps Lock`. Given a string `s`. Your task is to count how many times the keyboard has been tapped by John. You can assume that, at the beginning the `Caps Lock` light is not lit. # Input/Output `[input]` string `s` A non-empty string. It contains only English letters(uppercase or lowercase). `1 ≤ s.length ≤ 10000` `[output]` an integer The number of times John tapped the keyboard. # Example For `s = "a"`, the output should be `1`. John hit button `a`. For `s = "aa"`, the output should be `2`. John hit button `a, a`. For `s = "A"`, the output should be `2`. John hit button `Caps Lock, A`. For `s = "Aa"`, the output should be `4`. John hit button `Caps Lock, A, Caps Lock, a`.
reference
def typist(s): up = False t = len(s) for c in s: if c . isupper() and not up: up = True t += 1 elif c . islower() and up: up = False t += 1 return t
Simple Fun #305: Typist
592645498270ccd7950000b4
[ "Fundamentals" ]
https://www.codewars.com/kata/592645498270ccd7950000b4
6 kyu
It's Friday the 13th, and Jason is ready for his first killing spree! Create a function, killcount, that accepts two arguments: an array of array pairs (the conselor's name and intelligence - ["Chad", 2]) and an integer representing Jason's intellegence. Ruby, Python, Crystal: ```ruby counselors = [["Chad", 2], ["Tommy", 9]] jason = 7 ``` ```python counselors = [["Chad", 2], ["Tommy", 9]] jason = 7 ``` ```crystal counselors = [{"Chad", 2}, {"Tommy", 9}] jason = 7 ``` JavaScript: ```javascript var counselors = [["Chad", 2], ["Tommy", 9]]; var jason = 7; ``` PHP: ```php $counselors = [["Chad", 2], ["Tommy", 9]]; $jason = 7; ``` Your function must return an array of the names of all the counselors who can be outsmarted and killed by Jason. ![alt text](http://imagescdn.tweaktown.com/news/5/7/57271_4_new-friday-13th-game-slashes-pc-consoles.jpg) Happy Friday the 13th!
reference
def kill_count(counselors, jason): return [x for x, y in counselors if y < jason]
Friday the 13th Part 1
5925acf31a9825d616000e74
[ "Fundamentals", "Arrays" ]
https://www.codewars.com/kata/5925acf31a9825d616000e74
7 kyu
Write a function taking in a string like `WOW this is REALLY amazing` and returning `Wow this is really amazing`. String should be capitalized and properly spaced. Using `re` and `string` is not allowed. Examples: ```python filter_words('HELLO CAN YOU HEAR ME') #=> Hello can you hear me filter_words('now THIS is REALLY interesting') #=> Now this is really interesting filter_words('THAT was EXTRAORDINARY!') #=> That was extraordinary! ``` ```ruby filter_words('HELLO CAN YOU HEAR ME') #=> Hello can you hear me filter_words('now THIS is REALLY interesting') #=> Now this is really interesting filter_words('THAT was EXTRAORDINARY!') #=> That was extraordinary! ```
reference
def filter_words(st): return ' ' . join(st . capitalize(). split())
No yelling!
587a75dbcaf9670c32000292
[ "Strings", "Fundamentals" ]
https://www.codewars.com/kata/587a75dbcaf9670c32000292
7 kyu
# Task ``` +----+----+----+ | a1 | a2 | a3 | +----+----+----+ ``` As shown above. There are three grids. Each grid fill in a number(let's call `a1, a2 and a3`). Such that `0 ≤ a1, a2, a3 ≤ n`, where `n` is given, and meet the following rules: ``` - a1 + a2 is a multiple of 2; - a2 + a3 is a multiple of 3; - a1 + a2 + a3 is a multiple of 5; ``` Your task is to find a set of a1, a2, a3, which makes a1 + a2 + a3 maximum. Returns the `sum of a1, a2, a3`. # Input/Output `[input]` integer `n` A non-negative integer. It's the maximum possible value of a1, a2, a3. `0 ≤ n ≤ 10000` `[output]` an integer The maximum sum of a1, a2, a3. # Example For `n = 0`, the output should be `0`. The possible value of a1, a2, a3 can be `a1 = 0, a2 = 0, a3 = 0`. For `n = 3`, the output should be `5`. The possible value of a1, a2, a3 can be `a1 = 2, a2 = 2, a3 = 1`. For `n = 5`, the output should be `10`. The possible value of a1, a2, a3 can be `a1 = 4, a2 = 2, a3 = 4`. For `n = 9`, the output should be `25`. The possible value of a1, a2, a3 can be `a1 = 7, a2 = 9, a3 = 9`. For `n = 30`, the output should be `90`. The possible value of a1, a2, a3 can be `a1 = 30, a2 = 30, a3 = 30`.
games
LOOP = (0, 0, 5, 5, 10, 10, 15, 15, 20, 25, 25, 30, 30, 35, 40) def find_max_sum(n): q, r = divmod(n, 15) return 45 * q + LOOP[r]
Simple Fun #302: Find The Max Sum
59252121fb1f93fc8200013a
[ "Puzzles" ]
https://www.codewars.com/kata/59252121fb1f93fc8200013a
6 kyu
We want to know the index of the vowels in a given word, for example, there are two vowels in the word super (the second and fourth letters). So given a string "super", we should return a list of `[2, 4]`. Some examples: Mmmm => [] Super => [2,4] Apple => [1,5] YoMama -> [1,2,4,6] ### NOTES * Vowels in this context refers to: a e i o u y (including upper case) * This is indexed from `[1..n]` (not zero indexed!)
reference
def vowel_indices(word): return [i for i, x in enumerate(word, 1) if x . lower() in 'aeiouy']
Find the vowels
5680781b6b7c2be860000036
[ "Fundamentals" ]
https://www.codewars.com/kata/5680781b6b7c2be860000036
7 kyu
Write a function that generate the sequence of numbers which starts from the "From" number, then adds to each next term the "Step" number until the "To" number. For example: ```python generator(10, 20, 10) = [10, 20] # "From" = 10, "Step" = 10, "To" = 20 generator(10, 20, 1) = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] generator(10, 20, 5) = [10, 15, 20] ``` ```haskell generator 10 20 10 = [10, 20] -- "From" = 10, "Step" = 10, "To" = 20 generator 10 20 1 = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] generator 10 20 5 = [10, 15, 20] ``` ```ruby generator(10, 20, 10) = [10, 20] # "From" = 10, "Step" = 10, "To" = 20 generator(10, 20, 1) = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] generator(10, 20, 5) = [10, 15, 20] ``` If next term is greater than "To", it can't be included into the output array: ```python generator(10, 20, 7) = [10, 17] ``` ```haskell generator 10 20 7 = [10, 17] ``` ```ruby generator(10, 20, 7) = [10, 17] ``` If "From" bigger than "To", the output array should be written in reverse order: ```python generator(20, 10, 2) = [20, 18, 16, 14, 12, 10] ``` ```haskell generator 20 10 2 = [20, 18, 16, 14, 12, 10] ``` ```ruby generator(20, 10, 2) = [20, 18, 16, 14, 12, 10] ``` Don't forget about input data correctness: ```python generator(20, 10, 0) = [] generator(10, 20, -5) = [] ``` ```haskell generator 20 10 0 = [] generator 10 20 -5 = [] ``` ```ruby generator(20, 10, 0) = [] generator(10, 20, -5) = [] ``` "From" and "To" numbers are always integer, which can be negative or positive independently. "Step" can always be positive.
reference
def generator(start, stop, step): if step == 0: return [] if stop < start: return list(range(start, stop - 1, - step)) return list(range(start, stop + 1, step))
From-To-Step Sequence Generator
56459c0df289d97bd7000083
[ "Arrays", "Fundamentals" ]
https://www.codewars.com/kata/56459c0df289d97bd7000083
7 kyu
# Task We know that some numbers can be split into two primes. ie. `5 = 2 + 3, 10 = 3 + 7`. But some numbers are not. ie. `17, 27, 35`, etc.. Given a positive integer `n`. Determine whether it can be split into two primes. If yes, return the maximum product of two primes. If not, return `0` instead. # Input/Output `[input]` integer `n` A positive integer. `0 ≤ n ≤ 100000` `[output]` an integer The possible maximum product of two primes. or return `0` if it's impossible split into two primes. # Example For `n = 1`, the output should be `0`. `1` can not split into two primes For `n = 4`, the output should be `4`. `4` can split into two primes `2 and 2`. `2 x 2 = 4` For `n = 20`, the output should be `91`. `20` can split into two primes `7 and 13` or `3 and 17`. The maximum product is `7 x 13 = 91`
reference
def isPrime(n): return n == 2 or n > 2 and n & 1 and all(n % p for p in range(3, int(n * * .5 + 1), 2)) def prime_product(n): return next((x * (n - x) for x in range(n >> 1, 1, - 1) if isPrime(x) and isPrime(n - x)), 0)
Simple Fun #303: Prime Product
592538b3071ba54511000219
[ "Fundamentals" ]
https://www.codewars.com/kata/592538b3071ba54511000219
6 kyu
# Task Some children are playing rope skipping game. Children skip the rope at roughly the same speed: `once per second`. If the child fails during the jump, he needs to tidy up the rope and continue. This will take `3 seconds`. You are given an array sorted in ascending order, where each element is a jump count after which the child failed. This is a running total, meaning that each count includes the jumps before it. For example `[12, 23, 45]` means that the child failed 3 times while playing: after the 12th jump, after the 23rd jump, and after the 45th jump. Your task is to calculate how many times the child jumped in `60` seconds. Note: The children keep going until they have made at least `60` *jumps*, even if it takes them longer than `60` *seconds*. # Input/Output `[input]` integer array `failedCount` `0 ≤ failedCount.length ≤ 60` `1 ≤ failedCount[i] ≤ 60` `[output]` an integer how many times the child jumped in 60 seconds. # Example For `failedCount = []`, the output should be `60`. There is no mistake in the game process. So the child jumped 60 times in 60 seconds. For `failedCount = [12, 23, 45]`, the output should be `51`. ``` The 1st mistake occurred when he jumped 12 times. --> 12 seconds past. Tidy up the rope and continue. --> 15 seconds past. The 2nd mistake occurred when he jumped 23 times. --> 26 seconds past. Tidy up the rope and continue. --> 29 seconds past. The 3rd mistake occurred when he jumped 45 times. --> 51 seconds past. Tidy up the rope and continue. --> 54 seconds past. When he jumped 51 times --> 60 seconds past. ```
games
def tiaosheng(failed_counter): count = 0 jumps = 0 while count < 60: count += 1 jumps += 1 if jumps in failed_counter: count += 3 return jumps
Simple Fun #301: Rope Skipping Game
5925138effaed0de490000cf
[ "Puzzles" ]
https://www.codewars.com/kata/5925138effaed0de490000cf
6 kyu
Find the second-to-last element of a list. The input list will always contain at least two elements. Example: ```rust penultimate([1,2,3,4]) // -> 3 penultimate([4,3,2,1]) // -> 2 ``` ```haskell penultimate [1,2,3,4] -- => 3 penultimate ['a'..'z'] -- => 'y' ``` ```clojure (penultimate [1,2,3,4]) ; => 3 (penultimate "LISP IS AWESOME") ; => \M ``` ```python penultimate([1,2,3,4]) # => 3 penultimate("Python is dynamic") # => 'i' ``` (courtesy of [haskell.org](http://www.haskell.org/haskellwiki/99_questions/1_to_10))
reference
def penultimate(a): return a[- 2]
Penultimate
54162d1333c02486a700011d
[ "Lists", "Fundamentals" ]
https://www.codewars.com/kata/54162d1333c02486a700011d
7 kyu
###Lucky number Write a function to find if a number is lucky or not. If the sum of all digits is 0 or multiple of 9 then the number is lucky. `1892376 => 1+8+9+2+3+7+6 = 36`. 36 is divisible by 9, hence number is lucky. Function will return `true` for lucky numbers and `false` for others.
reference
def is_lucky(n): return n % 9 == 0
lucky number
55afed09237df73343000042
[ "Fundamentals", "Mathematics" ]
https://www.codewars.com/kata/55afed09237df73343000042
7 kyu
Count the number of occurrences of each character and return it as a (list of tuples) in order of appearance. For empty output return (an empty list). Consult the solution set-up for the exact data structure implementation depending on your language. Example: ```python ordered_count("abracadabra") == [('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 1)] ``` ```ruby ordered_count("abracadabra") == [['a', 5], ['b', 2], ['r', 2], ['c', 1], ['d', 1]] ``` ```haskell orderedCount "abracadabra" == [('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 1)] ``` ```scala Kata.orderedCount("abracadabra") == List(('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 1)) ``` ```groovy Kata.orderedCount("abracadabra") == [['a', 5], ['b', 2], ['r', 2], ['c', 1], ['d', 1]] ``` ```csharp Kata.OrderedCount("abracadabra") == new List<Tuple<char, int>> () { new Tuple<char, int>('a', 5), new Tuple<char, int>('b', 2), new Tuple<char, int>('r', 2), new Tuple<char, int>('c', 1), new Tuple<char, int>('d', 1) } ``` ```javascript orderedCount("abracadabra") == [['a', 5], ['b', 2], ['r', 2], ['c', 1], ['d', 1]] ``` ```julia # Note the single quotes: don't use a string, a character is used instead orderedCount("abracadabra") == [['a', 5], ['b', 2], ['r', 2], ['c', 1], ['d', 1]] ``` ```crystal # Note the single quotes: don't use a string, a character is used instead ordered_count("abracadabra") == [{'a', 5}, {'b', 2}, {'r', 2}, {'c', 1}, {'d', 1}] ``` ```lua ordered_count "abracadabra" == {{'a', 5}, {'b', 2}, {'r', 2}, {'c', 1}, {'d', 1}} ``` ```php orderedCount("abracadabra") == [['a', 5], ['b', 2], ['r', 2], ['c', 1], ['d', 1]] ``` ```fsharp orderedCount("abracadabra") = [('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 1)] ``` ```c ordered_count("abracadabra", *szout); // using: typedef struct Character_Count_Pair { char character; size_t count; } ccp; // returns: {{'a', 5}, {'b', 2}, {'r', 2}, {'c', 1}, {'d', 1}} // assigns length: szout = 5 ``` ```go OrderedCount("abracadabra") == []Tuple{Tuple{'a', 5}, Tuple{'b', 2}, Tuple{'r', 2}, Tuple{'c', 1}, Tuple{'d', 1}} // Where type Tuple struct { Char rune Count int } ``` ```vb Kata.OrderedCount("abracadabra") == new List(Of Tuple(Of Char, Integer)) () From { new Tuple(char, int)("a"c, 5), new Tuple(char, int)("b"c, 2), new Tuple(char, int)("r"c, 2), new Tuple(char, int)("c"c, 1), new Tuple(char, int)("d"c, 1) } ``` ```rust ordered_count("abracadabra") == vec![('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 1)] ``` ```typescript orderedCount("abracadabra") == [['a', 5], ['b', 2], ['r', 2], ['c', 1], ['d', 1]] ```
reference
from collections import Counter def ordered_count(input): return list(Counter(input). items())
Ordered Count of Characters
57a6633153ba33189e000074
[ "Fundamentals" ]
https://www.codewars.com/kata/57a6633153ba33189e000074
7 kyu
Write a function that doubles every second integer in a list, starting from the left. Example: For input array/list : ```javascript [1,2,3,4] ``` the function should return : ```javascript [1,4,3,8] ```
reference
def double_every_other(l): return [x * 2 if i % 2 else x for i, x in enumerate(l)]
Double Every Other
5809c661f15835266900010a
[ "Fundamentals", "Lists", "Arrays", "Algorithms" ]
https://www.codewars.com/kata/5809c661f15835266900010a
7 kyu
Write a function, `isItLetter` or `is_it_letter` or `IsItLetter`, which tells us if a given character is a letter or not.
reference
def is_it_letter(s): return s . isalpha()
Is it a letter?
57a06b07cf1fa58b2b000252
[ "Fundamentals" ]
https://www.codewars.com/kata/57a06b07cf1fa58b2b000252
7 kyu
Implement a function that returns the minimal and the maximal value of a list (in this order).
reference
def get_min_max(seq): return min(seq), max(seq)
Find min and max
57a1ae8c7cb1f31e4e000130
[ "Fundamentals" ]
https://www.codewars.com/kata/57a1ae8c7cb1f31e4e000130
7 kyu
Bob is a lazy man. He needs you to create a method that can determine how many ```letters``` (both uppercase and lowercase **ASCII** letters) and ```digits``` are in a given string. Example: "hel2!lo" --> 6 "wicked .. !" --> 6 "!?..A" --> 1
reference
def count_letters_and_digits(s): return sum(map(str . isalnum, s))
Help Bob count letters and digits.
5738f5ea9545204cec000155
[ "Strings", "Fundamentals" ]
https://www.codewars.com/kata/5738f5ea9545204cec000155
7 kyu
You will be given two ASCII strings, `a` and `b`. Your task is write a function to determine which one of these strings is "worth" more, and return it. A string's worth is determined by the sum of its ASCII codepoint indexes. So, for example, the string `HELLO` has a value of 372: H is codepoint 72, E 69, L 76, and O is 79. The sum of these values is 372. In the event of a tie, you should return the first string, i.e. `a`.
games
def highest_value(a, b): return max(a, b, key=lambda s: sum(map(ord, s)))
Which string is worth more?
5840586b5225616069000001
[ "Algorithms", "Strings", "Fundamentals" ]
https://www.codewars.com/kata/5840586b5225616069000001
7 kyu
Write a function `getNumberOfSquares` (C, F#, Haskell) / `get_number_of_squares` (Python, Ruby) that will return how many integer (starting from 1, 2...) numbers raised to power of 2 and then summed up are less than some number given as a parameter. E.g 1: For n = 6 result should be 2 because 1^2 + 2^2 = 1 + 4 = 5 and 5 < 6 E.g 2: For n = 15 result should be 3 because 1^2 + 2^2 + 3^2 = 1 + 4 + 9 = 14 and 14 < 15
reference
def get_number_of_squares(n): s, i = 0, 0 while s < n: i += 1 s += i * * 2 return i - 1
Sum of squares less than some number
57b71a89b69bfc92c7000170
[ "Fundamentals" ]
https://www.codewars.com/kata/57b71a89b69bfc92c7000170
7 kyu
The look and say sequence is a sequence in which each number is the result of a "look and say" operation on the previous element. Considering for example the classical version startin with `"1"`: `["1", "11", "21, "1211", "111221", ...]`. You can see that the second element describes the first as `"1(times number)1"`, the third is `"2(times number)1"` describing the second, the fourth is `"1(times number)2(and)1(times number)1"` and so on. Your goal is to create a function which takes a starting string (not necessarily the classical `"1"`, much less a single character start) and return the nth element of the series. ## Examples ```javascript lookAndSaySequence("1", 1) === "1" lookAndSaySequence("1", 3) === "21" lookAndSaySequence("1", 5) === "111221" lookAndSaySequence("22", 10) === "22" lookAndSaySequence("14", 2) === "1114" ``` ```python look_and_say_sequence("1", 1) == "1" look_and_say_sequence("1", 3) == "21" look_and_say_sequence("1", 5) == "111221" look_and_say_sequence("22", 10) == "22" look_and_say_sequence("14", 2) == "1114" ``` ```ruby look_and_say_sequence("1", 1) == "1" look_and_say_sequence("1", 3) == "21" look_and_say_sequence("1", 5) == "111221" look_and_say_sequence("22", 10) == "22" look_and_say_sequence("14", 2) == "1114" ``` ```crystal look_and_say_sequence("1" ,1) == "1" look_and_say_sequence("1", 3) == "21" look_and_say_sequence("1", 5) == "111221" look_and_say_sequence("22", 10) == "22" look_and_say_sequence("14", 2) == "1114" ``` ```csharp LookAndSaySequence("1" ,1) == "1" LookAndSaySequence("1", 3) == "21" LookAndSaySequence("1", 5) == "111221" LookAndSaySequence("22", 10) == "22" LookAndSaySequence("14", 2) == "1114" ``` ```c LookAndSaySequence("1" ,1) == "1" LookAndSaySequence("1", 3) == "21" LookAndSaySequence("1", 5) == "111221" LookAndSaySequence("22", 10) == "22" LookAndSaySequence("14", 2) == "1114" ``` Trivia: `"22"` is the only element that can keep the series constant.
reference
from re import sub def look_and_say_sequence(s, n): for _ in range(1, n): s = sub(r'(.)\1*', lambda m: str(len(m . group(0))) + m . group(1), s) return s
Look and say sequence generator
592421cb7312c23a990000cf
[ "Strings", "Regular Expressions", "Fundamentals" ]
https://www.codewars.com/kata/592421cb7312c23a990000cf
6 kyu
Given an `x` and `y` find the smallest and greatest numbers **above** and **below** a given `n` that are divisible by both `x` and `y`. ### Examples ```python greatest(2, 3, 20) => 18 # 18 is the greatest number under 20 that is divisible by both 2 and 3 smallest(2, 3, 20) => 24 # 24 is the smallest number above 20 that is divisible by both 2 and 3 greatest(5, 15, 100) => 90 smallest(5, 15, 100) => 105 greatest(123, 456, 789) => 0 # there are no numbers under 789 that are divisible by both 123 and 456 smallest(123, 456, 789) => 18696 ``` ```ruby greatest(2, 3, 20) => 18 # 18 is the greatest number under 20 that is divisible by both 2 and 3 smallest(2, 3, 20) => 24 # 24 is the smallest number above 20 that is divisible by both 2 and 3 greatest(5, 15, 100) => 90 smallest(5, 15, 100) => 105 greatest(123, 456, 789) => 0 # there are no numbers under 789 that are divisible by both 123 and 456 smallest(123, 456, 789) => 18696 ``` ```haskell greatest 2 3 20 => 18 -- 18 is the greatest number under 20 that is divisible by both 2 and 3 smallest 2 3 20 => 24 -- 24 is the smallest number above 20 that is divisible by both 2 and 3 greatest 5 15 100 => 90 smallest 5 15 100 => 105 greatest 123 456 789 => 0 -- there are no numbers under 789 that are divisible by both 123 and 456 smallest 123 456 789 => 18696 ``` ```clojure greatest 2 3 20 => 18 ;; 18 is the greatest number under 20 that is divisible by both 2 and 3 smallest 2 3 20 => 24 ;; 24 is the smallest number above 20 that is divisible by both 2 and 3 greatest 5 15 100 => 90 smallest 5 15 100 => 105 greatest 123 456 789 => 0 ;; there are no numbers under 789 that are divisible by both 123 and 456 smallest 123 456 789 => 18696 ``` ```csharp GreatestSmallest.Greatest(BigInteger.Parse("2"), BigInteger.Parse("3"), BigInteger.Parse("20")) => BigInteger.Parse("18") // 18 is the greatest number under 20 that is divisible by both 2 and 3 GreatestSmallest.Smallest(BigInteger.Parse("2"), BigInteger.Parse("3"), BigInteger.Parse("20")) => BigInteger.Parse("24") // 24 is the smallest number above 20 that is divisible by both 2 and 3 GreatestSmallest.Greatest(BigInteger.Parse("5"), BigInteger.Parse("15"), BigInteger.Parse("100")) => BigInteger.Parse("90") GreatestSmallest.Smallest(BigInteger.Parse("5"), BigInteger.Parse("15"), BigInteger.Parse("100")) => BigInteger.Parse("105") GreatestSmallest.Greatest(BigInteger.Parse("123"), BigInteger.Parse("456"), BigInteger.Parse("789")) => BigInteger.Parse("0") // there are no numbers under 789 that are divisible by both 123 and 456 GreatestSmallest.Smallest(BigInteger.Parse("123"), BigInteger.Parse("456"), BigInteger.Parse("789")) => BigInteger.Parse("18696") ``` ```java GreatestSmallest.greatest(new BigInteger("2"), new BigInteger("3"), new BigInteger("20")) => BigInteger("18") // 18 is the greatest number under 20 that is divisible by both 2 and 3 GreatestSmallest.greatest(new BigInteger("2"), new BigInteger("3"), new BigInteger("20")) => BigInteger("24") // 24 is the smallest number above 20 that is divisible by both 2 and 3 GreatestSmallest.greatest(new BigInteger("5"), new BigInteger("15"), new BigInteger("100")) => BigInteger("90") GreatestSmallest.smallest(new BigInteger("5"), new BigInteger("15"), new BigInteger("100")) => BigInteger("105") GreatestSmallest.greatest(new BigInteger("123"), new BigInteger("456"), new BigInteger("789")) => BigInteger("0") // there are no numbers under 789 that are divisible by both 123 and 456 GreatestSmallest.smallest(new BigInteger("123"), new BigInteger("456"), new BigInteger("789")) => BigInteger("18696") ``` **Notes:** 1. you should never return `n` even if it is divisible by `x` and `y` always the number above or below it 2. `greatest` should return 0 if there are no numbers under `n` that are divisible by both `x` and `y` 3. and all arguments will be valid (integers greater than 0). ### Note for Haskell users >Please take a look at [bkaes comment](http://www.codewars.com/kata/when-greatest-is-less-than-smallest/discuss#56418f0fbf1f44834d000050) and give us your opinion
algorithms
from math import gcd def greatest(x, y, n): lcm = (x * y) / / gcd(x, y) return (n / / lcm) * lcm if (n / / lcm) * lcm < n else 0 def smallest(x, y, n): lcm = (x * y) / / gcd(x, y) return lcm + (n / / lcm) * (lcm)
When greatest is less than smallest
55f2a1c2cb3c95af75000045
[ "Mathematics", "Logic", "Algorithms" ]
https://www.codewars.com/kata/55f2a1c2cb3c95af75000045
6 kyu
Your task here is the find the GCF (Greatest Common Factor) of any two numbers passed into a method, which will return one integer answer as an output. Examples: ```java findGCF(4, 6); // Should return 2 findGCF(93, 186); // Should return 93 findGCF(20, 5); // Should return 5 ``` ```python find_GCF(4, 6) # Should return 2 find_GCF(93, 186) # Should return 93 find_GCF(20, 5) # Should return 5 ``` ```cpp findGCF(4, 6); // Should return 2 findGCF(93, 186); // Should return 93 findGCF(20, 5); // Should return 5 ``` ```csharp FindGCF(4, 6); // Should return 2 FindGCF(93, 186); // Should return 93 FindGCF(20, 5); // Should return 5 ``` ```haskell findGcf 2 4 -- Should return 2 findGcf 8 20 -- Should return 4 findGcf 5 13 -- Should return 1 ``` ```ruby find_GCF(4, 6) # Should return 2 find_GCF(93, 186) # Should return 93 find_GCF(20, 5) # Should return 5 ``` Here, inputs will always be natural numbers so there's no need to worry about negative values or zero.
algorithms
from fractions import gcd as find_GCF
Find the GCF of Two Numbers
579e3476cf1fa55592000045
[ "Algorithms", "Logic", "Numbers", "Data Types", "Mathematics" ]
https://www.codewars.com/kata/579e3476cf1fa55592000045
7 kyu
Consider a game, wherein the player has to guess a target word. All the player knows is the length of the target word. To help them in their goal, the game will accept guesses, and return the number of letters that are in the correct position. Write a method that, given the correct word and the player's guess, returns this number. For example, here's a possible thought process for someone trying to guess the word "dog": ```cs CountCorrectCharacters("dog", "car"); //0 (No letters are in the correct position) CountCorrectCharacters("dog", "god"); //1 ("o") CountCorrectCharacters("dog", "cog"); //2 ("o" and "g") CountCorrectCharacters("dog", "cod"); //1 ("o") CountCorrectCharacters("dog", "bog"); //2 ("o" and "g") CountCorrectCharacters("dog", "dog"); //3 (Correct!) ``` ```javascript countCorrectCharacters("dog", "car"); //0 (No letters are in the correct position) countCorrectCharacters("dog", "god"); //1 ("o") countCorrectCharacters("dog", "cog"); //2 ("o" and "g") countCorrectCharacters("dog", "cod"); //1 ("o") countCorrectCharacters("dog", "bog"); //2 ("o" and "g") countCorrectCharacters("dog", "dog"); //3 (Correct!) ``` ```python count_correct_characters("dog", "car"); #0 (No letters are in the correct position) count_correct_characters("dog", "god"); #1 ("o") count_correct_characters("dog", "cog"); #2 ("o" and "g") count_correct_characters("dog", "cod"); #1 ("o") count_correct_characters("dog", "bog"); #2 ("o" and "g") count_correct_characters("dog", "dog"); #3 (Correct!) ``` ```ruby count_correct_characters("dog", "car"); #0 (No letters are in the correct position) count_correct_characters("dog", "god"); #1 ("o") count_correct_characters("dog", "cog"); #2 ("o" and "g") count_correct_characters("dog", "cod"); #1 ("o") count_correct_characters("dog", "bog"); #2 ("o" and "g") count_correct_characters("dog", "dog"); #3 (Correct!) ``` The caller should ensure that the guessed word is always the same length as the correct word, but since it could cause problems if this were not the case, you need to check for this eventuality: ```cs //Throw an InvalidOperationException if the two parameters are of different lengths. ``` ```javascript //Throw an error if the two parameters are of different lengths. ``` ```python #Raise an exception if the two parameters are of different lengths. ``` ```ruby #Raise an error if the two parameters are of different lengths. ``` You may assume, however, that the two parameters will always be in the same case.
games
def count_correct_characters(s, t): assert len(s) == len(t) return sum(a == b for a, b in zip(s, t))
Guess the Word: Count Matching Letters
5912ded3f9f87fd271000120
[ "Strings", "Games", "Puzzles" ]
https://www.codewars.com/kata/5912ded3f9f87fd271000120
7 kyu
# Task Get the digits sum of `n`<sub>th</sub> number from the [Look-and-Say sequence](http://en.wikipedia.org/wiki/Look-and-say_sequence)(1-based). `1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211, ...` # Input/Output `[input]` integer `n` `n`<sub>th</sub> number in the sequence to get where `1 <= n <= 55` and `n=1 is "1"`. [output] an integer The sum of digits in `n`<sub>th</sub> number from the `Look-and-Say` sequence. # Example For `n = 2`, the output shoule be 2. `"11" --> 1 + 1 --> 2` For `n = 3`, the output shoule be 3. `"21" --> 2 + 1 --> 3` For `n = 4`, the output shoule be 5. `"1211" --> 1 + 2 + 1 + 1 --> 5`
games
def look_and_say_and_sum(N): l = [1] for n in range(N - 1): result = [1, l[0]] for i in range(1, len(l)): if l[i] == result[- 1]: result[- 2] += 1 else: result += [1, l[i]] l = result return sum(l)
Simple Fun #299: Look And Say And Sum
5922828c80a27c049c000078
[ "Puzzles" ]
https://www.codewars.com/kata/5922828c80a27c049c000078
5 kyu
*** No Loops Allowed *** You will be given an array (a) and a limit value (limit). You must check that all values in the array are below or equal to the limit value. If they are, return true. Else, return false. You can assume all values in the array are numbers. Do not use loops. Do not modify input array. Looking for more, loop-restrained fun? Check out the other kata in the series: <a> https://www.codewars.com/kata/no-loops-2-you-only-need-one</a> <a> https://www.codewars.com/kata/no-loops-3-copy-within</a>
reference
def small_enough(a, limit): return max(a) <= limit
No Loops 1 - Small enough?
57cc4853fa9fc57a6a0002c2
[ "Fundamentals", "Arrays" ]
https://www.codewars.com/kata/57cc4853fa9fc57a6a0002c2
7 kyu
A series or sequence of numbers is usually the product of a function and can either be infinite or finite. In this kata we will only consider finite series and you are required to return a code according to the type of sequence: |Code|Type|Example| |-|-|-| |`0`|`unordered`|`[3,5,8,1,14,3]`| |`1`|`strictly increasing`|`[3,5,8,9,14,23]`| |`2`|`not decreasing`|`[3,5,8,8,14,14]`| |`3`|`strictly decreasing`|`[14,9,8,5,3,1]`| |`4`|`not increasing`|`[14,14,8,8,5,3]`| |`5`|`constant`|`[8,8,8,8,8,8]`| ~~~if:rust For Rust, the following enum is provided as result type: ```rust if:rust #[derive(Debug, PartialEq, Clone, Copy)] pub enum Order { Unordered, Increasing, NotDecreasing, Decreasing, NotIncreasing, Constant, } ``` ~~~ You can expect all the inputs to be non-empty and completely numerical arrays/lists - no need to validate the data; do not go for sloppy code, as rather large inputs might be tested. Try to achieve a good solution that runs in linear time; also, do it functionally, meaning you need to build a *pure* function or, in even poorer words, do NOT modify the initial input!
algorithms
def sequence_classifier(arr): if all(arr[i] == arr[i + 1] for i in range(len(arr) - 1)): return 5 if all(arr[i] < arr[i + 1] for i in range(len(arr) - 1)): return 1 if all(arr[i] <= arr[i + 1] for i in range(len(arr) - 1)): return 2 if all(arr[i] > arr[i + 1] for i in range(len(arr) - 1)): return 3 if all(arr[i] >= arr[i + 1] for i in range(len(arr) - 1)): return 4 return 0
Sequence classifier
5921c0bc6b8f072e840000c0
[ "Algorithms" ]
https://www.codewars.com/kata/5921c0bc6b8f072e840000c0
6 kyu
# RoboScript #3 - Implement the RS2 Specification ## Disclaimer The story presented in this Kata Series is purely fictional; any resemblance to actual programming languages, products, organisations or people should be treated as purely coincidental. ## About this Kata Series This Kata Series is based on a fictional story about a computer scientist and engineer who owns a firm that sells a toy robot called MyRobot which can interpret its own (esoteric) programming language called RoboScript. Naturally, this Kata Series deals with the software side of things (I'm afraid Codewars cannot test your ability to build a physical robot!). ## Story Last time, you implemented the RS1 specification which allowed your customers to write more concise scripts for their robots by allowing them to simplify consecutive repeated commands by postfixing a non-negative integer onto the selected command. For example, if your customers wanted to make their robot move 20 steps to the right, instead of typing `FFFFFFFFFFFFFFFFFFFF`, they could simply type `F20` which made their scripts more concise. However, you later realised that this simplification wasn't enough. What if a set of commands/moves were to be repeated? The code would still appear cumbersome. Take the program that makes the robot move in a snake-like manner, for example. The shortened code for it was `F4LF4RF4RF4LF4LF4RF4RF4LF4LF4RF4RF4` which still contained a lot of repeated commands. ## Task Your task is to allow your customers to further shorten their scripts and make them even more concise by implementing the newest specification of RoboScript (at the time of writing) that is RS2. RS2 syntax is a superset of RS1 syntax which means that all valid RS1 code from the previous Kata of this Series should still work with your RS2 interpreter. The only main addition in RS2 is that the customer should be able to group certain sets of commands using round brackets. For example, the last example used in the previous Kata in this Series: <pre style="background: #161616; color: #c5c8c6; font-family: 'CamingoCode-Regular', monospace; display: block; padding: 10px; margin-bottom: 15px; font-weight: normal; overflow-x: auto"> LF5RF3RF3RF7 </pre> ... can be expressed in RS2 as: <pre style="background: #161616; color: #c5c8c6; font-family: 'CamingoCode-Regular', monospace; display: block; padding: 10px; margin-bottom: 15px; font-weight: normal; overflow-x: auto"> LF5(RF3)(RF3R)F7 </pre> Or ... <pre style="background: #161616; color: #c5c8c6; font-family: 'CamingoCode-Regular', monospace; display: block; padding: 10px; margin-bottom: 15px; font-weight: normal; overflow-x: auto"> (L(F5(RF3))(((R(F3R)F7)))) </pre> Simply put, your interpreter should be able to deal with nested brackets of any level. And of course, brackets are useless if you cannot use them to repeat a sequence of movements! Similar to how individual commands can be postfixed by a non-negative integer to specify how many times to repeat that command, a sequence of commands grouped by round brackets `()` should also be repeated `n` times provided a non-negative integer is postfixed onto the brackets, like such: <pre style="background: #161616; color: #c5c8c6; font-family: 'CamingoCode-Regular', monospace; display: block; padding: 10px; margin-bottom: 15px; font-weight: normal; overflow-x: auto"> (SEQUENCE_OF_COMMANDS)n </pre> ... is equivalent to ... <pre style="background: #161616; color: #c5c8c6; font-family: 'CamingoCode-Regular', monospace; display: block; padding: 10px; margin-bottom: 15px; font-weight: normal; overflow-x: auto"> SEQUENCE_OF_COMMANDS...SEQUENCE_OF_COMMANDS (repeatedly executed "n" times) </pre> For example, this RS1 program: <pre style="background: #161616; color: #c5c8c6; font-family: 'CamingoCode-Regular', monospace; display: block; padding: 10px; margin-bottom: 15px; font-weight: normal; overflow-x: auto"> F4LF4RF4RF4LF4LF4RF4RF4LF4LF4RF4RF4 </pre> ... can be rewritten in RS2 as: <pre style="background: #161616; color: #c5c8c6; font-family: 'CamingoCode-Regular', monospace; display: block; padding: 10px; margin-bottom: 15px; font-weight: normal; overflow-x: auto"> F4L(F4RF4RF4LF4L)2F4RF4RF4 </pre> Or: <pre style="background: #161616; color: #c5c8c6; font-family: 'CamingoCode-Regular', monospace; display: block; padding: 10px; margin-bottom: 15px; font-weight: normal; overflow-x: auto"> F4L((F4R)2(F4L)2)2(F4R)2F4 </pre> All 4 example tests have been included for you. Good luck :D ## Kata in this Series 1. [RoboScript #1 - Implement Syntax Highlighting](https://www.codewars.com/kata/roboscript-number-1-implement-syntax-highlighting) 2. [RoboScript #2 - Implement the RS1 Specification](https://www.codewars.com/kata/roboscript-number-2-implement-the-rs1-specification) 3. **RoboScript #3 - Implement the RS2 Specification** 4. [RoboScript #4 - RS3 Patterns to the Rescue](https://www.codewars.com/kata/594b898169c1d644f900002e) 5. [RoboScript #5 - The Final Obstacle (Implement RSU)](https://www.codewars.com/kata/5a12755832b8b956a9000133)
algorithms
from collections import deque import re TOKENIZER = re . compile(r'(R+|F+|L+|\)|\()(\d*)') def parseCode(code): cmds = [[]] for cmd, n in TOKENIZER . findall(code): s, r = cmd[0], int(n or '1') + len(cmd) - 1 if cmd == '(': cmds . append([]) elif cmd == ')': lst = cmds . pop() cmds[- 1]. extend(lst * r) else: cmds[- 1] += [(s, r)] return cmds[0] def execute(code): pos, dirs = (0, 0), deque([(0, 1), (1, 0), (0, - 1), (- 1, 0)]) seens = {pos} for s, r in parseCode(code): if s == 'F': for _ in range(r): pos = tuple(z + dz for z, dz in zip(pos, dirs[0])) seens . add(pos) else: dirs . rotate((r % 4) * (- 1) * * (s == 'R')) miX, maX = min(x for x, y in seens), max(x for x, y in seens) miY, maY = min(y for x, y in seens), max(y for x, y in seens) return '\r\n' . join('' . join('*' if (x, y) in seens else ' ' for y in range(miY, maY + 1)) for x in range(miX, maX + 1))
RoboScript #3 - Implement the RS2 Specification
58738d518ec3b4bf95000192
[ "Esoteric Languages", "Interpreters", "Regular Expressions", "Algorithms" ]
https://www.codewars.com/kata/58738d518ec3b4bf95000192
4 kyu
# Task Given two numbers `x` and `y`. You have to convert `x` to `y` using minimum number of operations. There are two valid operation on the number `x`: ``` Multiply x by some prime p Divide x by some prime p ``` Your task is to find the minimum number of operations. Note that integer division is NOT allowed. That is, the result of `7 / 2` is 3.5, instead of 3. # Example For: `x = 2, y = 3`, the result should be `2`. `2 -> 2 * 3 -> 6 / 2 -> 3` in 2 moves. # Input/Output - `[input]` integer `x` A decimal positive integer. `0 < x <= 10^12` - `[input]` integer `y` A decimal positive integer. `0 < y <= 10^12` - `[output]` an integer The minimum number of operations
games
from collections import Counter def factors(n): for i in [2] + list(range(3, int(n * * 0.5) + 1, 2)): while not n % i: yield i n = n / / i if n > 2: yield n def prime_operations(x, y): C = Counter(factors(x)) C . subtract(Counter(factors(y))) return sum(map(abs, C . values()))
Simple Fun #127: Prime Operations
58a3e2978bdda5a0d9000187
[ "Puzzles" ]
https://www.codewars.com/kata/58a3e2978bdda5a0d9000187
5 kyu
## Task Given a string consisting of lowercase English letters, find the largest square number which can be obtained by reordering its characters and replacing them with digits (leading zeros are not allowed) where same characters always map to the same digits and different characters always map to different digits. If there is no solution, return `-1` ## Examples ``` "ab" --> 81 "zzz" --> -1 // There are no 3-digit square numbers with identical digits "aba" --> 900 // It can be obtained after reordering the initial string into "baa" ``` ## Input/Output - `[input]` string `s` - Constraints: `2 ≤ s.length < 10`. - `[output]` an integer
games
from collections import Counter from math import isqrt def mask(x): return sorted(Counter(str(x)). values()) def construct_square(s): m, r = mask(s), range(isqrt(10 * * ~ - len(s)), isqrt(10 * * len(s)) + 1) return (m := mask(s)) and max((n * n for n in r if mask(n * n) == m), default=- 1)
Simple Fun #33: Construct Square
58870c87c81516bbdb0000d8
[ "Puzzles" ]
https://www.codewars.com/kata/58870c87c81516bbdb0000d8
6 kyu
## Task Last night you had to study, but decided to party instead. Now there is a black and white photo of you that is about to go viral. You cannot let this ruin your reputation, so you want to apply box blur algorithm to the photo to hide its content. The algorithm works as follows: each pixel x in the resulting image has a value equal to the average value of the input `image` pixels' values from the `3 × 3` square with the center at x. All pixels at the edges are cropped. As pixel's value is an integer, all fractions should be rounded down. ### Example ``` image = [ [1, 1, 1], [1, 7, 1], [1, 1, 1] ] result = [ [1] ] ``` In the given example all boundary pixels were cropped, and the value of the pixel in the middle was obtained as `floor((1 + 1 + 1 + 1 + 7 + 1 + 1 + 1 + 1) / 9) = floor(15 / 9) = 1`. ### Input/Output - `[input]` 2D integer array `image` An image is stored as a rectangular matrix of non-negative integers. Constraints: `3 ≤ image.length ≤ 15,` `3 ≤ image[0].length ≤ 15,` `0 ≤ image[i][j] ≤ 255.` - `[output]` 2D integer array A blurred image.
games
from scipy . ndimage import convolve def box_blur(image): return (convolve(image, [[1, 1, 1]] * 3)[1: - 1, 1: - 1] / / 9). tolist()
Simple Fun #84: Box Blur
5895326bcc949f496b00003e
[ "Puzzles" ]
https://www.codewars.com/kata/5895326bcc949f496b00003e
6 kyu
### Background I was reading a [book](http://www.amazon.co.uk/Things-Make-Do-Fourth-Dimension/dp/1846147646/) recently, "Things to Make and Do in the Fourth Dimension" by comedian and mathematician Matt Parker, and in the first chapter of the book Matt talks about problems he likes to solve in his head to take his mind off the fact that he is in his dentist's chair, we've all been there! The problem he talks about relates to polydivisible numbers, and I thought a kata should be written on the subject as it's quite interesting. (Well it's interesting to me, so there!) ### Polydivisib... huh what? So what are they? A polydivisible number is divisible in an unusual way. The first digit is cleanly divisible by `1`, the first two digits are cleanly divisible by `2`, the first three by `3` and so on. The interesting thing about polydivisiblity is that it relates to the underlying number, but not the base it is written in, so if aliens came to Earth and used base `23` (`11` fingers on one hand and `12` on the other), no matter what squiggles they use to write numbers, they would find the same numbers polydivisible! ### Polydivisibilty Example: Let's do a worked example to clear up any questions ... Starting wih the number `1,232` in base `10` then: ``` 1232 1 /1 = 1 Yay! 12 /2 = 6 Yay! 123 /3 = 41 Yay! 1232 /4 = 308 Yay! ``` Thus `1,232` is a polydivisible number in base `4` and above. However starting wih the number `123,220` and using base `10` then: ``` 123220 1 /1 = 1 Yay! 12 /2 = 6 Yay! 123 /3 = 41 Yay! 1232 /4 = 308 Yay! 12322 /5 = 2464.4 Oh no, that's not a round number! 123220 /6 = 220536.333r Oh no, that's not a round number! ``` Thus `123,220` is not a polydivisible base 10 number, but what about in another base? Again starting wih the number `123,220` and using base `6` then: ``` base 6 base 10 1 = 1 -> 1 /1 = 1 Yay! 12 = 8 -> 8 /2 = 4 Yay! 123 = 51 -> 51 /3 = 17 Yay! 1232 = 308 -> 308 /4 = 77 Yay! 12322 = 1850 -> 1850 /5 = 370 Yay! 123220 = 11100 -> 11100 /6 = 1850 Yay! ``` Thus `123,220` is a polydivisible base `6` number (and a polydivisible base `10` number when converted to `11100` in base `10`). ### Kata In this kata you must implement two methods: `is_polydivisible(n, b)` and `get_polydivisible(n, b)`. The first `is_polydivisible(n, b)` will return `True` if `n` is polydivisible in base `b` or `False` if not. The second `get_polydivisible(n, b)` will return the `n`th polydivisible number using base `b`, the first polydivisible number is of course always `0`. You can assume that all inputs are valid. ```if:haskell All necessary arithmetic can be done in `Int` range. ``` ### Kata Examples: ```python is_polydivisible("1232", 10) # => True is_polydivisible("123220", 10) # => False is_polydivisible("123220", 6) # => True get_polydivisible(22, 10) # => "32" get_polydivisible(22, 16) # => "1A" get_polydivisible(42, 16) # => "42" ``` ```ruby is_polydivisible("1232", 10) # => True is_polydivisible("123220", 10) # => False is_polydivisible("123220", 6) # => True get_polydivisible(22, 10) # => "32" get_polydivisible(22, 16) # => "1A" get_polydivisible(42, 16) # => "42" ``` ```javascript isPolydivisible("1232", 10) // => True isPolydivisible("123220", 10) // => False isPolydivisible("123220", 6) // => True getPolydivisible(22, 10) // => "32" getPolydivisible(22, 16) // => "1A" getPolydivisible(42, 16) // => "42" ``` ```haskell isPolydivisible "1232" 10 -- -> True isPolydivisible "123220" 10 -- -> False isPolydivisible "123220" 6 -- -> True getPolydivisible 22 10 -- -> "32" getPolydivisible 22 16 -- -> "1A" getPolydivisible 42 16 -- -> "42" ``` #### A Note on Bases The maximum base used is base `62`, and uses characters in the following order `[0-9][A-Z][a-z]` to denote its digits, base `n` will use the first `n` characters of this sequence. ```if-not:haskell A constant CHARS has been declared with this sequence for you. ```
algorithms
CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" def from10(n, b): if b == 10: return n new = '' while n: new += str(CHARS[n % b]) n / /= b return new[:: - 1] def to10(n, b): num = 0 for i, d in enumerate(str(n)[:: - 1]): num += int(CHARS . index(d)) * (b * * i) return num def is_polydivisible ( s , b ): for i in range ( 1 , len ( s ) + 1 ): if to10 ( s [: i ], b ) % i != 0 : return False return True def get_polydivisible ( n , b ): if n == 1 : return '0' i = 0 poly = [] while len ( poly ) < n : fr = str ( from10 ( i , b )) if is_polydivisible ( str ( fr ), b ): poly . append ( fr ) i += 1 else : i += 1 return poly [ - 1 ]
Polydivisible Numbers
556206664efbe6376700005c
[ "Number Theory", "Algorithms" ]
https://www.codewars.com/kata/556206664efbe6376700005c
4 kyu
In this kata, your task is to create a regular expression capable of evaluating binary strings (strings with only `1`s and `0`s) and determining whether the given string represents a number divisible by 3. Take into account that: * An empty string *might* be evaluated to true (it's not going to be tested, so you don't need to worry about it - unless you want) * The input should consist only of binary digits - no spaces, other digits, alphanumeric characters, etc. * There might be leading `0`s. ```if-not:julia ### Examples (Javascript) * `multipleof3Regex.test('000')` should be `true` * `multipleof3Regex.test('001')` should be `false` * `multipleof3Regex.test('011')` should be `true` * `multipleof3Regex.test('110')` should be `true` * `multipleof3Regex.test(' abc ')` should be `false` ``` ```if:julia ### Examples * `occursin(multipleof3regex, '000')` should be `true` * `occursin(multipleof3regex, '001')` should be `false` * `occursin(multipleof3regex, '011')` should be `true` * `occursin(multipleof3regex, '110')` should be `true` * `occursin(multipleof3regex, ' abc ')` should be `false` ``` You can check more in the example test cases ### Note There's a way to develop an automata (FSM) that evaluates if strings representing numbers in a given base are divisible by a given number. You might want to check an example of an automata for doing this same particular task [here](http://math.stackexchange.com/questions/140283/why-does-this-fsm-accept-binary-numbers-divisible-by-three). If you want to understand better the inner principles behind it, you might want to study how to get the modulo of an arbitrarily large number taking one digit at a time.
games
PATTERN = re . compile(r'^(0|1(01*0)*1)*$')
Binary multiple of 3
54de279df565808f8b00126a
[ "Regular Expressions", "Algorithms", "Puzzles", "Number Theory" ]
https://www.codewars.com/kata/54de279df565808f8b00126a
4 kyu
## Introduction <pre style="white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;">A multi-storey car park (also called a parking garage, parking structure, parking ramp, parkade, parking building, parking deck or indoor parking) is a building designed for car parking and where there are a number of floors or levels on which parking takes place. It is essentially an indoor, stacked car park. Parking structures may be heated if they are enclosed. Design of parking structures can add considerable cost for planning new developments, and can be mandated by cities or states in new building parking requirements. Some cities such as London have abolished previously enacted minimum parking requirements (Source <a href="https://en.wikipedia.org/wiki/Multi-storey_car_park">Wikipedia</a>) </pre> <center><img src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/carpark.jpg"></center> ## Task <pre style="white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;"> Your task is to escape from the carpark using only the staircases provided to reach the exit. You may not jump over the edge of the levels (you’re not Superman!) and the exit is always on the far right of the ground floor. </pre> ## Rules <pre style="white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;"> 1. You are passed the carpark data as an argument into the function.<br> 2. Free carparking spaces are represented by a <span style="color:#A1A85E">0</span><br> 3. Staircases are represented by a <span style="color:#A1A85E">1</span><br> 4. Your parking place (start position) is represented by a <span style="color:#A1A85E">2</span> which could be on any floor.<br> 5. The exit is always the far right element of the ground floor.<br> 6. You must use the staircases to go down a level.<br> 7. You will never start on a staircase.<br> 8. The start level may be any level of the car park.<br> 9. Each floor will have only one staircase apart from the ground floor which will not have any staircases.</pre> ## Returns <pre style="white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;"> Return an array of the quickest route out of the carpark<br> <span style="color:#A1A85E">R1</span> = Move Right one parking space.<br> <span style="color:#A1A85E">L1</span> = Move Left one parking space.<br> <span style="color:#A1A85E">D1</span> = Move Down one level. </pre> ## Example ### Initialise ```ruby carpark = [[1, 0, 0, 0, 2], [0, 0, 0, 0, 0]] ``` ```python carpark = [[1, 0, 0, 0, 2], [0, 0, 0, 0, 0]] ``` ```javascript carpark = [[1, 0, 0, 0, 2], [0, 0, 0, 0, 0]]; ``` ```csharp Kata kata = new Kata(); int[,] carpark = new int[,] { { 1, 0, 0, 0, 2 }, { 0, 0, 0, 0, 0 } }; ``` ```fsharp let carpark = [[1; 0; 0; 0; 2] [0; 0; 0; 0; 0]] ``` ```c carpark = {{1, 0, 0, 0, 2}, {0, 0, 0, 0, 0}} ``` ```cpp carpark = {{1, 0, 0, 0, 2}, {0, 0, 0, 0, 0}} ``` ```java carpark = {{1, 0, 0, 0, 2}, {0, 0, 0, 0, 0}} ``` ### Working Out <pre style="white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;"> - You start in the most far right position on level 1 - You have to move Left 4 places to reach the staircase => "<span style="color:#A1A85E">L4</span>" - You then go down one flight of stairs => "<span style="color:#A1A85E">D1</span>" - To escape you have to move Right 4 places => "<span style="color:#A1A85E">R4</span>" </pre> ### Result ```ruby result = ["L4", "D1", "R4"] ``` ```python result = ["L4", "D1", "R4"] ``` ```javascript result = ["L4", "D1", "R4"] ``` ```csharp string[] result = new string[] { "L4", "D1", "R4" }; ``` ```fsharp let result = ["L4"; "D1"; "R4"] ``` ```c result = {"L4", "D1", "R4"} ``` ```cpp result = {"L4", "D1", "R4"} ``` ```java result = {"L4", "D1", "R4"} ``` Good luck and enjoy!<br> ## Kata Series If you enjoyed this, then please try one of my other Katas. Any feedback, translations and grading of beta Katas are greatly appreciated. Thank you. <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58663693b359c4a6560001d6" target="_blank">Maze Runner</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58693bbfd7da144164000d05" target="_blank">Scooby Doo Puzzle</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/7KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/586a1af1c66d18ad81000134" target="_blank">Driving License</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/586c0909c1923fdb89002031" target="_blank">Connect 4</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/586e6d4cb98de09e3800014f" target="_blank">Vending Machine</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/587136ba2eefcb92a9000027" target="_blank">Snakes and Ladders</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58a848258a6909dd35000003" target="_blank">Mastermind</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58b2c5de4cf8b90723000051" target="_blank">Guess Who?</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58f5c63f1e26ecda7e000029" target="_blank">Am I safe to drive?</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58f5c63f1e26ecda7e000029" target="_blank">Mexican Wave</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/58fdcc51b4f81a0b1e00003e" target="_blank">Pigs in a Pen</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/590300eb378a9282ba000095" target="_blank">Hungry Hippos</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/5904be220881cb68be00007d" target="_blank">Plenty of Fish in the Pond</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/590adadea658017d90000039" target="_blank">Fruit Machine</a></span> <span style="display: flex !important;"><img style="margin:0px;" src="https://raw.githubusercontent.com/adrianeyre/codewars/master/Ruby/Authored/6KYU.png" alt="Rank"/>&nbsp;<a href="https://www.codewars.com/kata/591eab1d192fe0435e000014" target="_blank">Car Park Escape</a></span>
reference
def escape(carpark): car, stairs, start, moves, x = - 1, - 1, - 1, [], 0 while x < len(carpark): # Use string to avoid troubles with absence of 1 or 2 line = '' . join(map(str, carpark[x])) stairs = line . find("1") # Search for stairs if start == - 1: # Do this only while the car had not been found yet start = line . find("2") if start >= 0: # Car found, start moving the "car" and declare that the car has been already found (start = -2) car, start = start, - 2 if start == - 2: if x == len(carpark) - 1: # Car is at ground level if car != len(carpark[x]) - 1: # Move the car to the exit if needed moves . append("R" + str(len(carpark[x]) - 1 - car)) return moves moves . append(["L", "R"][stairs - car > 0] + str(abs(stairs - car))) # Archive the move needed car, comingFrom = stairs, x # Move the car to the stair, collect the current level while carpark[x][car] == 1: x += 1 # Go down while stairs are present moves . append("D" + str(x - comingFrom)) # Archive the whole descent else: x += 1 # If you reach this, car has not been found yet, so serach one level "lower"
Car Park Escape
591eab1d192fe0435e000014
[ "Arrays", "Games", "Fundamentals" ]
https://www.codewars.com/kata/591eab1d192fe0435e000014
5 kyu
# Task Amin and Haji are playing a simple game: Haji thinks of a number `x` in range `[1..n]`, and Amin tries to guess the number by asking variations of the following question: `"Is your number divisible by number y?"`. The game is played according to the following rules: first Amin asks all the questions that interest him (sometimes he doesn't even need to ask any), and then Haji responds to each question with either `"yes"` or `"no"`. After receiving all the answers, Amin should determine the number Haji is thinking of. Unfortunately, Amin is not familiar with basic number theory. Help him find the minimum number of questions he must ask to make an accurate guess of Haji's number. # Input/Output `[input]` integer `n` The maximum number Haji could be thinking of. `1 ≤ n ≤ 1000` `[output]` an integer The minimum number of questions Amin should ask. # Examples For `n = 4`, the output should be `3`. Amin should ask if the number is divisible by `2, 3 or 4` to know the answer for sure. - if Amin don't ask number `2`, he can not determine the number `x` is `1` or `2` (When the number `x` is `1` or `2`, whether Amin asks numbers `3` and `4`, Haji's answer always be "no" and "no") - if Amin don't ask number `3`, he can not determine the number `x` is `1` or `3` (When the number `x` is `1` or `3`, whether Amin asks numbers `2` or `4`, Haji's answer always be "no" and "no") - if Amin don't ask number `4`, he can not determine the number `x` is `2` or `4` (When the number `x` is `2` or `4`, whether Amin asks numbers `2` and `3`, Haji's answer always be "yes" and "no") --- For `n = 6`, the output should be `4`. It's enough to ask questions about divisibility by `2, 3, 4 and 5`. - if Amin don't ask number `5`, he can not determine the number `x` is `1` or `5` (When the number `x` is `1` or `5`, whether Amin asks numbers `2, 3 and 4`, Haji's answer always be "no","no","no") --- For `n = 1`, the output should be `0`. There is only number `1` in range `[1,1]`, so Amin don't need to ask any question --- For `n = 10`, the output should be `7`. It's enough to ask questions about divisibility by `2, 3, 4, 5, 7, 8, 9`.
algorithms
from math import log def find_divs(mx=10 * * 3): def is_prime(n): return n == 2 or all(n % k for k in [2] + [* range(3, int(n * * .5) + 1, 2)]) marg = int(mx * * .5) res = {k for k in range(2, mx + 1) if is_prime(k)} res = res | {d * * pw for d in res if d <= marg for pw in range(2, int(log(mx, d)) + 1)} return res DIVS = find_divs() def guess_what(n): return sum(x <= n for x in DIVS)
Simple Fun #295: Guess Number
591e62eef99b994288000057
[ "Mathematics", "Number Theory" ]
https://www.codewars.com/kata/591e62eef99b994288000057
6 kyu
## Task Ram lives in a house which is round in shape. The house has `n` entrances numbered from `1` to `n`. For each `i` in range `1..n-1` entrances `i` and `i + 1` are adjacent; entrances `1` and `n` are also adjacent. Ram's flat is located at entrance `a`. Each evening he goes for a walk around the house, counting the entrances he walks by. Today Ram decided to walk until he counts `b` entrances. Help Ram to determine the number of the entrance near which he will be at the end of his walk. ## Input/Output **Input:** * integer `n` - The number of entrances, `1 ≤ n ≤ 200` * integer `a` - The number of the entrance where Ram starts his walk, `1 ≤ a ≤ n` * integer `b` - The number of entrances Ram wants to count, `-100 000 ≤ b ≤ 100 000` ##### *Note:* * if `b > 0`, Ram walks clockwise until he counts `b` entrances * if `b < 0`, Ram walks counterclockwise until he counts `b` entrances * if `b = 0`, Ram stays at his entrance and doesn't go anywhere **Output:** * an integer - The number of the house at the end of his walk. ## Examples For `n = 5, a = 1 and b = 3`, the output should be `4`: Ram will walk clockwise around the house, counting the entrances as follows: `1 -> 2 -> 3 -> 4` For `n = 6, a = 2 and b = -5`, the output should be `3`: Ram will walk counterclockwise around the house, so he will count the entrances as follows: `2 -> 1 -> 6 -> 5 -> 4 -> 3`
games
def round_and_round(n, a, b): return (a + b) % n or n
Simple Fun #296: Round And Round
591e8c715b1d254f9e00005e
[ "Puzzles" ]
https://www.codewars.com/kata/591e8c715b1d254f9e00005e
7 kyu
Given a certain square matrix ```A```, of dimension ```n x n```, that has negative and positive values (many of them may be 0). We need the following values rounded to the closest integer: - the average of all the positive numbers and zeros that are in the principal diagonal and in the columns with odd index, **avg1** - the absolute value of the average of all the negative numbers in the secondary diagonal and in the columns with even index, **avg2** Let's see the requirements in an example: ``` A = [[ 1, 3, -4, 5, -2, 5, 1], [ 2, 0, -7, 6, 8, 8, 15], [ 4, 4, -2, -10, 7, -1, 7], [ -1, 3, 1, 0, 11, 4, 21], [ -7, 6, -4, 10, 5, 7, 6], [ -5, 4, 3, -5, 7, 8, 17], [-11, 3, 4, -8, 6, 16, 4]] ``` The elements of the principal diagonal are: ``` [1, 0, -2, 0, 5, 8, 4] ``` The ones that are also in the "odd columns" (we consider the index starting with 0) are: ``` [0, 0, 8] all positives ``` So, ``` avg1 = [8 / 3] = 3 ``` The elements of the secondary diagonal are: ``` [-11, 4, -4, 0, 7, 8, 1] ``` The ones that are in the even columns are: ``` [-11, -4, 7, 1] ``` The negative ones are: ``` [-11, -4] ``` So, ``` avg2 = [|-15 / 2|] = 8 ``` Create a function ```avg_diags()```that may receive a square matrix of uncertain dimensions and may output both averages in an array in the following order: ```[avg1, avg2]``` If one of the diagonals have no elements fulfilling the requirements described above the function should return ```-1``` So, if the function processes the matrix given above, it should output: ``` [3, 8] ``` Features of the random tests: ``` number of tests = 110 5 ≤ matrix_length ≤ 1000 -1000000 ≤ matrix[i, j] ≤ 1000000 ``` Enjoy it! Translations into another languages will be released soon.
reference
def avg_diags(m): a1, a2, l, l1, l2 = 0, 0, len(m), 0, 0 for i in range(0, l): if i & 1: if m[i][i] >= 0: a1 += m[i][i] l1 += 1 else: if m[l - i - 1][i] < 0: a2 += m[len(m) - i - 1][i] l2 += 1 return [round(a1 / l1) if l1 > 0 else - 1, round(abs(a2) / l2) if l2 > 0 else - 1]
#4 Matrices: Process for a Square Matrix
58fef91f184b6dcc07000179
[ "Mathematics", "Data Structures", "Matrix", "Linear Algebra", "Fundamentals" ]
https://www.codewars.com/kata/58fef91f184b6dcc07000179
6 kyu
Two numbers are **relatively prime** if their greatest common factor is 1; in other words: if they cannot be divided by any other common numbers than 1. `13, 16, 9, 5, and 119` are all relatively prime because they share no common factors, except for 1. To see this, I will show their factorizations: ```python 13: 13 16: 2 * 2 * 2 * 2 9: 3 * 3 5: 5 119: 17 * 7 ``` Complete the function that takes 2 arguments: a number (`n`), and a list of numbers (`arr`). The function should return a list of all the numbers in `arr` that are relatively prime to `n`. All numbers in will be positive integers. ## Examples ```python relatively_prime(8, [1, 2, 3, 4, 5, 6, 7]) >> [1, 3, 5, 7] relatively_prime(15, [72, 27, 32, 61, 77, 11, 40]) >> [32, 61, 77, 11] relatively_prime(210, [15, 100, 2222222, 6, 4, 12369, 99]) >> [] ``` ```haskell relativelyPrime 8 [1, 2, 3, 4, 5, 6, 7] == [1,3,5,7] relativelyPrime 15 [72, 27, 32, 61, 77, 11, 40] == [32, 61, 77, 11] relativelyPrime 210 [15, 100, 2222222, 6, 4, 12369, 99]) == [] 17 17 ``` ```ruby relatively_prime(8, [1, 2, 3, 4, 5, 6, 7]) >> [1, 3, 5, 7] relatively_prime(15, [72, 27, 32, 61, 77, 11, 40]) >> [32, 61, 77, 11] relatively_prime(210, [15, 100, 2222222, 6, 4, 12369, 99]) >> [] ```
algorithms
from fractions import gcd def relatively_prime(n, l): return [x for x in l if gcd(n, x) == 1]
Relatively Prime Numbers
56b0f5f84de0afafce00004e
[ "Fundamentals", "Algorithms" ]
https://www.codewars.com/kata/56b0f5f84de0afafce00004e
7 kyu
Create a function that takes a number as an argument and returns a grade based on that number. Score | Grade -----------------------------------------|----- Anything greater than 1 or less than 0.6 | "F" 0.9 or greater | "A" 0.8 or greater | "B" 0.7 or greater | "C" 0.6 or greater | "D" Examples: ``` grader(0) should be "F" grader(1.1) should be "F" grader(0.9) should be "A" grader(0.8) should be "B" grader(0.7) should be "C" grader(0.6) should be "D" ```
reference
def grader(x): if 0.9 <= x <= 1: return "A" elif 0.8 <= x < 0.9: return "B" elif 0.7 <= x < 0.8: return "C" elif 0.6 <= x < 0.7: return "D" else: return "F"
Grader
53d16bd82578b1fb5b00128c
[ "Fundamentals" ]
https://www.codewars.com/kata/53d16bd82578b1fb5b00128c
8 kyu
# Task Given a number `n`, return a string representing it as a sum of distinct powers of three, or return `"Impossible"` if that's not possible to achieve. # Input/Output `[input]` integer `n` A positive integer n. `1 ≤ n ≤ 10^16`. `[output]` a string A string representing the sum of powers of three which adds up to n, or `"Impossible"` if there is no solution. If the solution does exist, it should be return as `"3^a1+3^a2+ ... +3^an"`, where ai for `0 ≤ i ≤ n` represents the corresponding exponent of the term. The terms in the string should also be sorted in descending order, meaning that higher powers should appear before the lower ones in the string (`"3^0+3^1"` is incorrect, whereas `"3^1+3^0"` is correct). # Example For `n = 4`, the output should be `"3^1+3^0"`. 4 can be represented as `3+1` which is in fact 3 to the power of 1 plus 3 to the power of 0 For `n = 2`, the output should be `"Impossible"`. There is no way to represent 2 as a sum of `distinct powers` of 3.
algorithms
import numpy as np def sum_of_threes(n): s = np . base_repr(n, 3) if '2' in s: return 'Impossible' return '+' . join(['3^{}' . format(i) for i, d in enumerate(s[:: - 1]) if d == '1'][:: - 1])
Simple Fun #290: Sum Of Threes
591d3375e51f4a0940000052
[ "Algorithms" ]
https://www.codewars.com/kata/591d3375e51f4a0940000052
6 kyu
Every natural number, ```n```, may have a prime factorization like: <a href="http://imgur.com/1M2nwjh"><img src="http://i.imgur.com/1M2nwjh.png?1" title="source: imgur.com" /></a> We define the **geometric derivative of n**, as a number with the following value: <a href="http://imgur.com/dMNPsIx"><img src="http://i.imgur.com/dMNPsIx.png?1" title="source: imgur.com" /></a> For example: calculate the value of ```n*``` for ```n = 24500```. ``` 24500 = 2²5³7² n* = (2*2) * (3*5²) * (2*7) = 4200 ``` Make a function, ```f``` that can perform this calculation ``` f(n) ----> n* ``` Every prime number will have ```n* = 1```. Every number that does not have an exponent ```ki```, higher than 1, will give a ```n* = 1```, too ```python, rust f(24500) == 4200 f(997) == 1 ``` Do your best!
reference
def f(n): res = 1 i = 2 while n != 1: k = 0 while n % i == 0: k += 1 n / /= i if k != 0: res *= k * i * * (k - 1) i += 1 return res
Transformation of a Number Through Prime Factorization
572caa2672a38ba648001dcd
[ "Fundamentals", "Algorithms", "Mathematics" ]
https://www.codewars.com/kata/572caa2672a38ba648001dcd
5 kyu
# Task There's a wolf who lives in the plane forest, which is located on the `Cartesian coordinate system`. When going on the hunt, the wolf starts at point `(0, 0)` and goes `spirally` as shown in the picture below: ![](https://i.gyazo.com/cad8fce0e87dcb1d45dc345dbb22f6c2.png) The wolf finally found something to eat at point `(x, y)`. Your task is to calculate the number of turns he had to make to get to that point. # Input/Output `[input]` integer `x` x coordinate of the final point. `-1000000 ≤ x ≤ 1000000` `[input]` integer `y` y coordinate of the final point. `-1000000 ≤ y ≤ 1000000` `[output]` an integer The number of turns. # Example For `x = 1` and `y = 1`, the output should be `1`. Path:`(0,0) --> (1,0) --> (1,1)`, 1 turn at `(1,0)` For `x = 1` and `y = -1`, the output should be `4`. Path:`(0,0) --> (1,0) --> (1,1) --> (-1,1) --> (-1,-1) --> (1,-1)`, 4 turns at `(1,0), (1,1), (-1,1), (-1,-1)`
games
def turns_on_road(x, y): if [x, y] == [0, 0]: return 0 if x > 0 and - x + 1 < y <= x: return 4 * x - 3 if x < 0 and x <= y < - x: return 4 * (- x) - 1 if y > 0 and - y <= x < y: return 4 * y - 2 if y < 0 and y < x <= - y + 1: return 4 * (- y)
Simple Fun #288: Turns On Road
591c075a94414c1617000063
[ "Puzzles" ]
https://www.codewars.com/kata/591c075a94414c1617000063
6 kyu
<img src="https://i.imgur.com/ta6gv1i.png?1" title="source: imgur.com" /> <!-- Weekly Kata Challenge 4/Feb/2022 --> <span style='color:#cc3300;'> <i> > "What is your name" said Tim. <br>"My name" said the mouse "Is Dinglemouse". <br><br> > "What were you before the witch turned you into a mouse" said Rose. <br>"I was a <span style='color:yellow;'>banana</span>" said Dingle the mouse, "So be careful. If you see her, run away!". </i> </span> *- <a href="https://www.youtube.com/watch?v=mep9TlGDno4">Badjelly the Witch</a>&nbsp;(12:32), Spike Milligan* # Kata Task Given a string of letters ```a```, ```b```, ```n``` how many different ways can you make the word "<span style='color:yellow;'>banana</span>" by crossing out various letters and then reading left-to-right? (Use ```-``` to indicate a crossed-out letter) # Example Input ``` bbananana ``` Output ``` b-anana-- b-anan--a b-ana--na b-an--ana b-a--nana b---anana -banana-- -banan--a -bana--na -ban--ana -ba--nana -b--anana ``` # Notes * You must return all possible bananas, but the order does not matter * The example output above is formatted for readability. Please refer to the example tests for expected format of your result. <div style='color:red;font-size:2em'> :-) <br> <br> <br> </div>
algorithms
import itertools def bananas(s): result = set() for comb in itertools . combinations(range(len(s)), len(s) - 6): arr = list(s) for i in comb: arr[i] = '-' candidate = '' . join(arr) if candidate . replace('-', '') == 'banana': result . add(candidate) return result
Bananas
5917fbed9f4056205a00001e
[ "Strings", "Algorithms" ]
https://www.codewars.com/kata/5917fbed9f4056205a00001e
5 kyu
In this simple exercise, you will build a program that takes a value, `integer `, and returns a list of its multiples up to another value, `limit `. If `limit` is a multiple of ```integer```, it should be included as well. There will only ever be positive integers passed into the function, not consisting of 0. The limit will always be higher than the base. For example, if the parameters passed are `(2, 6)`, the function should return `[2, 4, 6]` as 2, 4, and 6 are the multiples of 2 up to 6.
reference
def find_multiples(integer, limit): return list(range(integer, limit + 1, integer))
Find Multiples of a Number
58ca658cc0d6401f2700045f
[ "Fundamentals", "Arrays" ]
https://www.codewars.com/kata/58ca658cc0d6401f2700045f
8 kyu
# Task You are given a `chessboard` with several `rooks` and `bishops` placed on some of its squares. How many unoccupied squares are there that are not under attack of any chess piece? Here, the standard rules are applied: a square is under attack of a rook or a bishop only if all squares between the piece and the current square are unoccupied. # Input/Output - `[input]` integer array `chessboard` matrix of size `8x8` containing numbers `{-1, 0, 1}` which represents chess pieces placement: `-1 -> bishop, 0 -> empty square, 1 -> rook` - `[output]` an integer number of safe squares on the board.
games
PIECES_MOVES = {1: [(1, 0), (- 1, 0), (0, 1), (0, - 1)], - 1: [(1, 1), (- 1, - 1), (- 1, 1), (1, - 1)]} def bishops_and_rooks(chessboard): def theRootOfAllEvil(r, c): evilIsHere . add((r, c)) for dr, dc in PIECES_MOVES[chessboard[r][c]]: for i in range(1, 8): x, y = r + dr * i, c + dc * i if not (0 <= x < 8 and 0 <= y < 8) or chessboard[x][y] != 0: break evilIsHere . add((x, y)) evilIsHere = set() for r in range(8): for c in range(8): if chessboard[r][c] != 0: theRootOfAllEvil(r, c) return 64 - len(evilIsHere)
Chess Fun #9: Bishops And Rooks
58a3b28b2f949e21b3000001
[ "Puzzles" ]
https://www.codewars.com/kata/58a3b28b2f949e21b3000001
5 kyu
Given a positive integer `n`, return first n dgits of Thue-Morse sequence, as a string (see examples). Thue-Morse sequence is a binary sequence with 0 as the first element. The rest of the sequece is obtained by adding the Boolean (binary) complement of a group obtained so far. ``` For example: 0 01 0110 01101001 and so on... ``` ![alt](https://upload.wikimedia.org/wikipedia/commons/f/f1/Morse-Thue_sequence.gif) Ex.: ```javascript thueMorse(1); //'0' thueMorse(2); //'01' thueMorse(5); //'01101' thueMorse(10): //'0110100110' ``` ```python thue_morse(1); #"0" thue_morse(2); #"01" thue_morse(5); #"01101" thue_morse(10): #"0110100110" ``` ```ruby thue_morse(1); #"0" thue_morse(2); #"01" thue_morse(5); #"01101" thue_morse(10): #"0110100110" ``` ```crystal thue_morse(1); #"0" thue_morse(2); #"01" thue_morse(5); #"01101" thue_morse(10): #"0110100110" ``` - You don't need to test if n is valid - it will always be a positive integer. - `n` will be between 1 and 10000 [Thue-Morse on Wikipedia](https://en.wikipedia.org/wiki/Thue%E2%80%93Morse_sequence) [Another kata on Thue-Morse](https://www.codewars.com/kata/simple-fun-number-106-is-thue-morse) by @myjinxin2015
algorithms
def thue_morse(n): out = "0" while len ( out ) < n : out += out . replace ( '1' , '2' ). replace ( '0' , '1' ). replace ( '2' , '0' ) return out [: n ]
Thue-Morse Sequence
591aa1752afcb02fa300002a
[ "Strings", "Binary", "Algorithms" ]
https://www.codewars.com/kata/591aa1752afcb02fa300002a
6 kyu
You are given a matrix ```M```, of positive and negative integers. It should be sorted in an up and down column way, starting always with the lowest element placed at the top left position finishing with the highest depending on ```n``` value: at the bottom right position if the number of columns,```n```, is odd, or placed at the top right, if ```n``` is even. E.g.: ``` M = [[-20, -4, -1], [ 1, 4, 7], [ 8, 10, 12]] M_ = [[-20, 7, 8], [-4, 4, 10], [-1, 1, 12]] ``` In order to be more understandable we show the directions of the sorting for the new matrix with arrows: <a href="http://imgur.com/owCZAeI"><img src="http://i.imgur.com/owCZAeI.jpg" title="source: imgur.com" /></a> Create the function ```up_down_col_sort()``` that receives a matrix as an argument and may do this kind of sorting. Your function will be tested with square or rectangular matrices of ```m``` rows and ```n``` columns Features of the random tests: ``` Number of tests = 120 10 <= m <= 200 10 <= n <= 200 -1000 <= M[i,j] <= 1000 ``` The kata is available at Python 2, Typescript, Javascript and Ruby at the moment. Translations into another languages will be released soon.
reference
def up_down_col_sort(m): f = [] for i in m: for j in i: f += [j] f = sorted(f) a = len(m) d = 0 g = [] for i in range(0, len(f), a): if d == 0: g += [f[i: i + a]] d += 1 else: g += [f[i: i + a][:: - 1]] d = 0 return [list(i) for i in zip(* g)]
#8 Matrices: Up and Down Sorting For Each Column
590b8d5cee471472f40000aa
[ "Fundamentals", "Algorithms", "Data Structures", "Mathematics", "Matrix", "Sorting" ]
https://www.codewars.com/kata/590b8d5cee471472f40000aa
6 kyu
# Task `Codewars Weekly` has gained popularity in the past months and is receiving lots of fan letters. Unfortunately, some of the readers use offensive words and the editor wants to keep the magazine family friendly. To manage this, you have been asked to implement a censorship algorithm. You will be given the fan letter `text` and a list of `forbiddenWords`. Your algorithm should replace all occurrences of the forbidden words in the text with sequences of asterisks of the same length. Be careful to censor only words, no one want to see `"classic"` spelled as `"cl***ic"`. # Input/Output `[input]` string `text` Text to censor, composed of mixed case English (or non-English, for random cases) words separated by a single whitespace character each. No punctuation is used. All words may consist of Latin alphabet letters only. `[input]` string array `forbiddenWords` The list of words to censor, all in lowercase. `[output]` a string The censored text. Its length should be the same as the length of text. # Example For `text = "The cat does not like the fire"` and `forbiddenWords = ["cat","fire"]`, the output should be `"The *** does not like the ****"`.
reference
def censor_this(text, forbidden_words): return ' ' . join([w if w . lower() not in forbidden_words else '*' * len(w) for w in text . split()])
Simple Fun #283: Censor The Forbidden Words
591a86bfe76dc98f24000030
[ "Fundamentals" ]
https://www.codewars.com/kata/591a86bfe76dc98f24000030
6 kyu
We have a square matrix ```M``` of dimension ```n x n``` that has positive and negative numbers in the ranges ```[-9,-1]``` and ```[0,9]```,( the value ```0``` is excluded). We want to add up all the products of the elements of the diagonals ```UP-LEFT to DOWN-BOTTOM```, that is the value of```sum1```; and the elements of the diagonals ```UP-RIGHT to LEFT-DOWN``` and that is ```sum2```. Then, as a final result, the value of ```sum1 - sum2```. E.g. ```python,cobol,typscript,d,ruby,rust,javascript M = [[ 1, 4, 7, 6, 5], [-3, 2, 8, 1, 3], [ 6, 2, 9, 7, -4], [ 1, -2, 4, -2, 6], [ 3, 2, 2, -4, 7]] ``` ```julia M = [1 4 7 6 5; -3 2 8 1 3; 6 2 9 7 -4; 1 -2 4 -2 6; 3 2 2 -4 7] ``` Let's see how to get this result in the image below: <a href="http://imgur.com/MHfydrP"><img src="http://i.imgur.com/MHfydrP.jpg?1" title="source: imgur.com" /></a> So the value of ```sum1 - sum2``` is equal to: ``` 1164 - 66 = 1098 ``` Create the code to do this calculation. Features of the random tests: ``` Numbers of tests = 150 5 <= dimension <= 25 (python, ruby and COBOL) 5 <= dimension <= 20 (javascript) -10 < M[i,j] < 0 and 0 < M[i,j] < 10 ``` This kata is available in Python2, Ruby, Typescript, D, Cobol, Julia, Rust and Javascript at the moment. Translations into another languages will be released soon. Enjoy it!
reference
def sum_prod_diags(m): s, n = 0, len(m) for d in 0, - 1: for x in range(n): h = v = 1 for u in range(n - x): h *= m[u ^ d][x + u] if x: v *= m[(x + u) ^ d][u] s += (d | 1) * (h + v) return s
#9 Matrices: Adding diagonal products
590bb735517888ae6b000012
[ "Matrix", "Algorithms", "Fundamentals" ]
https://www.codewars.com/kata/590bb735517888ae6b000012
5 kyu
# The Problem Dan, president of a Large company could use your help. He wants to implement a system that will switch all his devices into offline mode depending on his meeting schedule. When he's at a meeting and somebody texts him, he wants to send an automatic message informing that he's currently unavailable and the time when he's going to be back. # What To Do Your task is to write a helper function `checkAvailability` that will take 2 arguments: * schedule, which is going to be a nested array with Dan's schedule for a given day. Inside arrays will consist of 2 elements - start and finish time of a given appointment, * *currentTime* - is a string with specific time in hh:mm 24-h format for which the function will check availability based on the schedule. * If no appointments are scheduled for `currentTime`, the function should return `true`. If there are no appointments for the day, the output should also be `true` * If Dan is in the middle of an appointment at `currentTime`, the function should return a string with the time he's going to be available. # Examples `checkAvailability([["09:30", "10:15"], ["12:20", "15:50"]], "11:00");` should return `true` `checkAvailability([["09:30", "10:15"], ["12:20", "15:50"]], "10:00");` should return `"10:15"` If the time passed as input is *equal to the end time of a meeting*, function should also return `true`. `checkAvailability([["09:30", "10:15"], ["12:20", "15:50"]], "15:50");` should return `true` *You can expect valid input for this kata*
algorithms
def check_availability(schedule, current_time): for tb, te in schedule: if tb <= current_time < te: return te return True
Are you available?
5603002927a683441f0000cb
[ "Algorithms" ]
https://www.codewars.com/kata/5603002927a683441f0000cb
6 kyu
This series of katas will introduce you to basics of doing geometry with computers. Write the function `circleArea`/`CircleArea` which takes in a `Circle` object and calculates the area of that circle.</br> The `Circle` class can be seen below: ```javascript // Represents a Circle where center is a Point and radius is a Number class Circle { constructor(center, radius) { this.center = center; this.radius = radius; } } ``` ```csharp public class Circle { public Point Center { get; private set; } public double Radius { get; private set; } public Circle(Point center, double radius) { this.Center = center; this.Radius = radius; } } ``` ```ruby # Represents a Circle where center is a Point and radius is a Number class Circle attr_accessor :center, :radius def initialize(center, radius) @center = center @radius = radius end end ``` And the `Point` class can be seen below: ```javascript // Represents a Point where x and y are Numbers class Point { constructor (x,y) { this.x = x; this.y = y; } } ``` ```csharp public class Point { public double X { get; private set; } public double Y { get; private set; } public Point(double x, double y) { this.X = x; this.Y = y; } } ``` ```ruby # Represents a Point where x and y are Numbers class Point attr_accessor :x, :y def initialize(x, y) @x = x @y = y end end ``` <!-- C# documentation --> ```if:csharp <h1>Documentation:</h1> <h2>Kata.CircleArea Method (Circle)</h2> Returns the area of a circle. <span style="font-size:20px">Syntax</span> <div style="margin-top:-10px;padding:2px;background-color:Grey;position:relative;left:20px;width:600px;"> <div style="background-color:White;color:Black;border:1px;display:block;padding:10px;padding-left:18px;font-family:Consolas,Courier,monospace;"> <span style="color:Blue;">public</span> <span style="color:Blue;">static</span> <span style="color:Blue;">double</span> CircleArea(</br> <span style="position:relative;left:62px;">Circle circle</span></br>   ) </div> </div> </br> <div style="position:relative;left:20px;"> <strong>Parameters</strong> </br> <i>circle</i> </br> <span style="position:relative;left:50px;">Type: Circle</span></br> <span style="position:relative;left:50px;">The circle to calculate the area of.</span> </br></br> <strong>Return Value</strong> </br> <span>Type: <a href="https://msdn.microsoft.com/en-us/library/system.double(v=vs.110).aspx">System.Double</a></span></br> A double representing the area of the circle. </div> ``` <!-- end C# documentation --> Tests round answers to 6 decimal places.
reference
from math import pi def circle_area(circle): return pi * circle . radius * * 2
Geometry Basics: Circle Area in 2D
58e3f824a33b52c1dc0001c0
[ "Geometry", "Fundamentals" ]
https://www.codewars.com/kata/58e3f824a33b52c1dc0001c0
8 kyu
# Task Given an array `arr`, find the maximal value of `k` such `a[i] mod k` = `a[j] mod k` for all valid values of i and j. If it's impossible to find such number (there's an infinite number of `k`s), return `-1` instead. # Input/Output `[input]` integer array `arr` A non-empty array of positive integer. `2 <= arr.length <= 10` `1 <= arr[i] <= 100` `[output]` an integer The maximum value of `k` or `-1` if there is none. # Example For `arr = [1, 2, 3]`, the output should be `1`. `1` is the only k which satisfies the given conditions. For `arr = [1, 1, 1]`, the output should be `-1`. `1 % k = 1` for `any k > 1`, so it's impossible to find the maximum. For `arr = [5, 2, 8]`, the output should be `3`. `5 % 3 == 2 % 3 == 8 % 3 == 2`
algorithms
def finding_k(arr): for n in range(max(arr) - 1, 0, - 1): if len({x % n for x in arr}) == 1: return n return - 1
Simple Fun #279: Finding K
5919427e5ffc30804900005f
[ "Algorithms" ]
https://www.codewars.com/kata/5919427e5ffc30804900005f
6 kyu
You are a *khm*mad*khm* scientist and you decided to play with electron distribution among atom's shells. You know that basic idea of electron distribution is that electrons should fill a shell untill it's holding the maximum number of electrons. --- Rules: - Maximum number of electrons in a shell is distributed with a rule of 2n^2 (n being position of a shell). - For example, maximum number of electrons in 3rd shield is 2*3^2 = 18. - Electrons should fill the lowest level shell first. - If the electrons have completely filled the lowest level shell, the other unoccupied electrons will fill the higher level shell and so on. --- ``` Ex.: atomicNumber(1); should return [1] atomicNumber(10); should return [2, 8] atomicNumber(11); should return [2, 8, 1] atomicNumber(47); should return [2, 8, 18, 19] ```
algorithms
def atomic_number(electrons): result = [] i = 1 while electrons > 0: result . append(min(2 * (i * * 2), electrons)) electrons -= result[- 1] i += 1 return result
Ideal electron distribution
59175441e76dc9f9bc00000f
[ "Arrays", "Lists", "Algorithms" ]
https://www.codewars.com/kata/59175441e76dc9f9bc00000f
6 kyu
# Description: Replace the pair of exclamation marks and question marks to spaces(from the left to the right). A pair of exclamation marks and question marks must has the same number of "!" and "?". That is: "!" and "?" is a pair; "!!" and "??" is a pair; "!!!" and "???" is a pair; and so on.. # Examples ``` replace("!!") === "!!" replace("!??") === "!??" replace("!?") === " " replace("!!??") === " " replace("!!!????") === "!!!????" replace("!??!!") === "! " replace("!????!!!?") === " ????!!! " replace("!?!!??!!!?") === " !!!?" ```
reference
import re def replace(s): dic = {'!': '?', '?': '!'} r = re . findall(r'[!]+|[/?]+', s) for i in r[:]: ii = dic[i[0]] * len(i) if ii in r: r[r . index(ii)] = ' ' * len(i) return '' . join(r)
Exclamation marks series #15: Replace the pair of exclamation marks and question marks to spaces
57fb2c822b5314e2bb000027
[ "Fundamentals" ]
https://www.codewars.com/kata/57fb2c822b5314e2bb000027
6 kyu
# Task Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable `TUT-GLOP`. Sometimes only part of the number is used to spell a word. When you get back to your hotel tonight you can order a pizza from Gino's by dialing `310-GINO`. The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. `888-1200`). The keypad of a phone supplies the mapping of letters to numbers, as follows: ``` A, B, and C map to 2 D, E, and F map to 3 G, H, and I map to 4 J, K, and L map to 5 M, N, and O map to 6 P, R, and S map to 7 T, U, and V map to 8 W, X, and Y map to 9 letters can be uppercase or lowercase ``` There is no mapping for `Q(q) or Z(z)`. Hyphens are not dialed, and can be added and removed as necessary. The standard form of `TUT-GLOP` is `888-4567`, the standard form of `310-GINO` is `310-4466`, and the standard form of `3-10-10-10` is `310-1010`. Two telephone numbers are equivalent if they have the same standard form. (They dial the same number.) Given a list `phoneNumbers`, your task is to find the duplicate telephone number in the list. Return an array like this: `["310-1010:2","487-3279:4","888-4567:3"]` The form of each element is `standard form + : + numbers of duplicate` # Input/Output - `[input]` string array `phoneNumbers` The list of the telephone numbers. Each telephone number consists of a string composed of decimal digits, letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters. - `[output]` a string array The duplicate telephone number list. Arrange the output string by telephone number in ascending lexicographical order. If there are no duplicates in the input return `[]`. - #Example For phoneNumbers = ``` [ "7399425", "SEXY-GAL", "Sexy-GAL", "sexy-gal", "SEXY-425", "S-E-X-Y-G-A-L" ] ``` The output should be: ``` ["739-9425:6"] ```
algorithms
def find_duplicate_phone_numbers(phone_numbers): stan = [a . upper(). translate(str . maketrans('ABCDEFGHIJKLMNOPRSTUVWXY', '222333444555666777888999')). replace('-', '') for a in phone_numbers] return sorted(['{}-{}:{}' . format(a[: 3], a[3:], stan . count(a)) for a in set(stan) if stan . count(a) > 1])
Simple Fun #186: Duplicate Phone Numbers
58bf67eb68d8469e3c000041
[ "Algorithms" ]
https://www.codewars.com/kata/58bf67eb68d8469e3c000041
6 kyu
# Task Given a `sequence` of integers, check whether it is possible to obtain a strictly increasing sequence by erasing no more than one element from it. # Example For `sequence = [1, 3, 2, 1]`, the output should be `false`; For `sequence = [1, 3, 2]`, the output should be `true`. # Input/Output - `[input]` integer array `sequence` Constraints: `2 ≤ sequence.length ≤ 1000, -10000 ≤ sequence[i] ≤ 10000.` - `[output]` a boolean value `true` if it is possible, `false` otherwise.
games
def almost_increasing_sequence(sequence): save, first = - float('inf'), True for i, x in enumerate(sequence): if x > save: save = x elif first: if i == 1 or x > sequence[i - 2]: save = x first = False else: return False return True
Simple Fun #64: Almost Increasing Sequence
5893e7578afa367a61000036
[ "Puzzles" ]
https://www.codewars.com/kata/5893e7578afa367a61000036
6 kyu