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
## <span style="color:#0ae">Luhn algorithm</span> The *Luhn algorithm* is a simple checksum formula used to validate credit card numbers and other identification numbers. #### Validation - Take the decimal representation of the number. - Starting from rightmost digit and moving left, double every second digit; if the new value is greater than `9`, replace it with the sum of its digits. - Sum up all the resulting values. - The number is valid if (and only if) the checksum is a multiple of `10`. Example: ``` 8 9 1 2 8 number 8 18 1 4 8 double even digits (2 -> 4, 9 -> 18) 8 9 1 4 8 18 -> 1+8 -> 9 8+9+1+4+8 -> 30 30 % 10 == 0 -> valid ``` #### Check digit A valid number can be obtained appending a *check digit* to the number. For example, if the original number is `8912`, we can append `8` to obtain a valid number (`89128`). *Warning: the algorithm for computing check digit in wikipedia is wrong.* ## <span style="color:#0ae">Task</span> Compute the *check digit* of a number. #### Input - **`n`** *[int]* The number. Range: `$0$`–`$10^{30}$`. #### Output *[int]* - The *check digit*, an integer *k* (0 ≤ k < 10) such that `n * 10 + k` is valid. ## <span style="color:#0ae">Restrictions</span> Your code should not be longer than **72 bytes**. *(Personal best: 69 bytes)*
games
def lcd(n): return n and ((n * 79 + 4) / / 10 + lcd(n / / 100)) % 10
[Code Golf] Luhn Check Digit
6112e90fda33cb002e3f3e44
[ "Restricted", "Puzzles" ]
https://www.codewars.com/kata/6112e90fda33cb002e3f3e44
6 kyu
Given multiple lists (name, age, height), each of size n : An entry contains one name, one age and one height. The attributes corresponding to each entry are determined by the index of each list, for example entry 0 is made up of ```name[0], age[0], height[0]```. A duplicate entry is one in which the name, age and height are ALL the same. Write a function which takes in the attributes for each entry and returns an integer for the number of duplicated entries. For a set of duplicates, the original entry should not be counted as a duplicate.
reference
def count_duplicates(* args): return len(args[0]) - len(set(zip(* args)))
Counting Duplicates Across Multiple Lists
6113c2dc3069b1001b8fdd05
[ "Lists", "Fundamentals" ]
https://www.codewars.com/kata/6113c2dc3069b1001b8fdd05
7 kyu
Before attempting this kata, take a look at [this one](https://www.codewars.com/kata/5713d18ec82eff7766000bb2). Dobble, also known as "Spot it!", is played with a deck of cards where each card contains 8 different figures and any two cards have exactly one figure in common. The total number of distinct figures in a deck of cards is 57. In this kata, we will model the cards as tuples (or lists, arrays, or other, depending on language) of strings. The strings describe the figures on the card. For example, here are two cards: ``` ("TARGET", "FIRE", "QUESTION MARK", "CANDLE", "CLOCK", "APPLE", "G-KEY", "DOG"), ("COBWEB", "CLOWN", "ART", "BOTTLE", "CACTUS", "G-KEY", "SNOWFLAKE", "EYE"), ``` These two cards have one figure in common, which is `"G-KEY"`. A deck of Dobble cards has 55 cards, which is strange because 57 cards would make the deck, in a sense, _complete_. In fact, it's possible to add two cards to the deck while preserving the property that any two cards have exactly one figure in common. An example is given in the Example Test Cases. Your task is two write a function `missing_cards(cards)`, which takes as argument a list of 55 tuples each containing 8 distinct strings, and returns a list of two tuples each containing 8 distinct strings such that when the input and output are concatenated one obtains a list of 57 tuples such that any two tuples in this list have exactly one string in common. The input argument `cards` will always be a valid list of tuples, so no validation is required. Neither the output list nor the tuples in this list need to be ordered in any particular way.
reference
from collections import Counter def missing_cards(cards): cs = Counter(x for c in cards for x in c) y = next(x for x, k in cs . items() if k == 6) r = [[y], [y]] for x in (x for x, k in cs . items() if k == 7): s = set(r[1] + [x]) r[all(len(set(c) & s) <= 1 for c in cards)]. append(x) return [* map(tuple, r)]
Dobble: Identify the missing cards
610bfdde5811e400274dbf66
[ "Games", "Puzzles", "Algorithms" ]
https://www.codewars.com/kata/610bfdde5811e400274dbf66
5 kyu
# Mirrored Exponential Chunks Using a single function provided with an array, create a new one in the following ways: - Separate array elements into chunks. Each chunk will contain `2^abs(n)` elements where `n` is the "distance" to the median chunk. - The median chunk(s) will have one single element, or will not appear in the output if there is some ambiguity about it. - If an outlying chunk does not have enough elements to reach the `2^abs(n)` requirement, it will contain as many elements as remain. - Chuncks in mirrored places (compared to the median chunk) should be of the same length. - You must maintain original element order within each chunk. - You must maintain original element order from chunk to chunk. Example Input/Solution: ``` input: [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,27,28,29] solution: [[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,27,28,29]] ``` ```if-not:python Note: do it efficiently. Your function will have to be at most 2.5x slower than the reference solution. ```
algorithms
from collections import deque def mirrored_exponential_chunks(arr): left, median = divmod(len(arr), 2) p, right, mirror = 1, left + median, deque([]) if median: mirror . append(arr[left: right]) while left > 0: p *= 2 mirror . appendleft(arr[max(left - p, 0): left]) mirror . append(arr[right: right + p]) left -= p right += p return list(mirror)
Mirrored Exponential Chunks
5852d0d463adbd39670000a1
[ "Arrays", "Algorithms" ]
https://www.codewars.com/kata/5852d0d463adbd39670000a1
5 kyu
# Task Write a function with the following properties: - takes two lists - returns a list of all possibilities to pair as many elements as possible from both lists while keeping the order of the elements - output format is a list of lists of tuples, or a list with an empty list, if no pairs are possible - inner lists can be of any order (see tests) ## Hints If both input lists are of equal length, then every item of one list will be paired with an item of the other list (see first example) -> results in only one sublist. If both input lists are of different length and not empty, then every item of the shorter list will be paired, but not every item of the larger list -> results in more than one sublist, because there are more then one possibilities to omit items from the larger list. # Example 1 Pair elements of `['c', 'o', 'd', 'e']` with elements of `['w', 'a', 'r', 's']` Expected Result: [[('c', 'w'), ('o', 'a'), ('d', 'r'), ('e', 's')]] # Example 2 Pair elements of the following two lists: ['electric', 'horse', 'fly'] ['1st', '2nd'] Valid result: [[('electric', '1st'), ('horse', '2nd')], [('electric', '1st'), ('fly', '2nd')], [('horse', '1st'), ('fly', '2nd')]] # Example 3 Pair elements of `['a', 'b', 'c']` with elements of `['x', 'y']` Valid Result: [[('a', 'x'), ('b', 'y')], [('a', 'x'), ('c', 'y')], [('b', 'x'), ('c', 'y')]] # Example 4 Pair elements of `[1, 2]` with elements of `[6, 7, 8, 9]` Valid Result: [[(1, 6), (2, 7)], [(1, 6), (2, 8)], [(1, 6), (2, 9)], [(1, 7), (2, 8)], [(1, 7), (2, 9)], [(1, 8), (2, 9)]]
reference
from itertools import combinations def pair_items(a, b): n = min(len(a), len(b)) return [list(zip(x, y)) for x in combinations(a, n) for y in combinations(b, n)]
Pair items from two lists of different lengths
61055e2cb02dcb003da50cd5
[ "Fundamentals" ]
https://www.codewars.com/kata/61055e2cb02dcb003da50cd5
6 kyu
## Decode the cipher Where ```python # encode: Callable[ [str,int,int], list[int] ] encode = lambda a,b,c:(d:=0)or[(d:=(string.ascii_letters.index(e)+b+c)%(b*c)+d) for e in a] ``` The ciphered string `a` includes only ascii letters and: ```python 3 <= len(a) <= 128 8 <= b <= 256 8 <= c <= 256 ``` Example ```python decode([243, 445, 661, 878, 1104, 1302, 1518, 1720], 99, 99) -> "TestCase" ```
games
def decode(s, r, a): return "" . join( chr((e := x - t - r - a) + [39, 97][e < 26]) for t, x in zip([0, * s], s))
Decode a cipher - simple
61026860c135de00251c6a54
[ "Ciphers", "Puzzles" ]
https://www.codewars.com/kata/61026860c135de00251c6a54
6 kyu
The 2 main sequences in Mathematics are Arithmetic Progression and Geometric Progression. Those are the sequences you will be working with in this kata. # Introduction A sequence of numbers is called an Arithmetic Progression if the difference between any two consecutive terms is always same. In simple terms, it means that next number in the series is calculated by adding a fixed number to the previous number in the series. This fixed number is called the common difference. A sequence of numbers is called a Geometric Progression if the ratio of any two consecutive terms is always same. In simple terms, it means that next number in the series is calculated by multiplying a fixed number to the previous number in the series. This fixed number is called the common ratio. # Rules Given an array of integers that follow either series, you have to determine the series and return accordingly : "0" if it is an AP "1" if it is a GP "-1" if it doesn't follow any of the above sequences "2" if it is both an AP and GP For Example, series_array = [2, 5, 8, 11, 14] #should return 0 series_array = [1, 2, 4, 8, 16] #should return 1 series_array = [1, 2, 1, 3, 4, 5] #should return -1 series_array = [1, 1, 1, 1, 1] #should return 2 series_array = [0, 0, 0, 0, 0] #should return 0 The main challenge is identifying the differences between the 2 sequences and to find a way of determining each sequence If the series has all 0's, then 0 should be returned as it is not accepted as a term GP NOTE : Only APs and GPs are considered in this question. Other series like Harmonic Progression are not considered and assume that the array will have atleast one element
algorithms
INF = float('inf') def determine_sequence(arr): isArith = len({b - a for a, b in zip(arr, arr[1:])}) == 1 isGeom = len({b / a if a else INF for a, b in zip(arr, arr[1:])}) == 1 return set(arr) != {0} and - 1 + isArith + 2 * isGeom
Sequence Determiner
610159919347db0019cabddc
[ "Algorithms" ]
https://www.codewars.com/kata/610159919347db0019cabddc
7 kyu
Bob works for Yamazon as a barcode scanning specialist. Every day, armed with his trusty laser, his job is to scan barcodes of packages as they pass in front of him on a conveyor belt. One day, his boss Beff Jezos tells him "There's been a big mixup with the new barcodes. We forgot to count every bardcode that had a repeating digit. Now we are short boxes but we dont know how many to order. I need you to hand count every barcode that has a double digit." Yamazon barcodes are very long. Bob knows there are more labels to count then he has time in his life. Is there a way to keep his sanity and his job? ***** For this Kata, you will write a function that accepts an integer 'ndigit' representing the number of digits in a barcode. The function should return the total number of n-digit integers which contain a 'double digit' (the same digit twice in a row)" Barcodes are numeric only (containing 0 - 9), and will not have leading zeroes (IE, a six digit barcode will start as 100000). For example: ``` number_of_duplicate_digits(2) should return 9 11,22,33,44,55,66,77,88,99 number_of_duplicate_digits(3) should return 171: 110,111,122,133... etc. ``` Expect large numbers with ndigits upwards of 10000, so execution time will be a factor. Dont bother trying to generate the entire list.
algorithms
def number_of_duplicate_digits(n): return 9 * 10 * * (n - 1) - 9 * * n
How many double digits?
60fb2e158b940b00191e24fb
[ "Mathematics", "Algorithms", "Puzzles" ]
https://www.codewars.com/kata/60fb2e158b940b00191e24fb
6 kyu
# Task Write a function that determines if the provided sequence of non-negative integers can be represented by a simple graph. [A simple graph](https://mathworld.wolfram.com/SimpleGraph.html#:~:text=A%20simple%20graph%2C%20also%20called,Bronshtein%20and%20Semendyayev%202004%2C%20p.) is a graph without any loops (a vertex with an edge linking back to itself) and without multiple edges between any two vertices. The degree of a vertex is the number of edges adjacent to it. A sequence of non-negative integers can be represented by a simple graph if there is at least one simple graph with such a sequence of vertex degrees. For example, a sequence of vertices with degrees ```[2, 3, 3, 1, 2, 2, 3]``` might be represented by the following simple graph: ``` (2)-----(3)-----(3)-----(1) | | | (2) (2) | | | | \------(3)------/ ``` # Examples ```python solution([2, 3, 3, 1, 2, 2, 3]) --> True solution([2, 3, 2, 1, 2, 2, 3]) --> False solution([1, 1, 2, 2]) --> True # Graph: 1-2-2-1 solution([0, 0, 0]) --> True # The graph may be disconnected solution([1]) --> False solution([]) --> True # The graph may be empty ``` ```rust solution(vec![2, 3, 3, 1, 2, 2, 3]) --> true solution(vec![2, 3, 2, 1, 2, 2, 3]) --> false solution(vec![1, 1, 2, 2]) --> true // Graph: 1-2-2-1 solution(vec![0, 0, 0]) --> true // The graph may be disconnected solution(vec![1]) --> false solution(vec![]) --> true // The graph may be empty ```
algorithms
# https://en.wikipedia.org/wiki/Erdős–Gallai_theorem#Statement def solution(degrees): degrees = sorted(filter(None, degrees), reverse=True) return not degrees or sum(degrees) % 2 == 0 and all(sum(degrees[: k + 1]) <= k * (k + 1) + sum(min(k + 1, x) for i, x in enumerate(degrees[k + 1:])) for k in range(len(degrees)))
Graph-like Sequence
60815326bbb0150009f55f7e
[ "Sorting", "Algorithms", "Graph Theory" ]
https://www.codewars.com/kata/60815326bbb0150009f55f7e
5 kyu
# A war of mirrors You are presented with a battlefield with ally spaceships, enemies and mirrors (ignore the borders): ``` +----------+ |> A C \| | / B | | D | | | | > E /| +----------+ ``` The symbols are as follows: * Your spaceships are triangle-shaped (like in *Asteroids*!) and have an orientation: * `>` Right * `<` Left * `^` Up * `v` Down * The enemies are represented as **uppercase letters**. * The mirrors are diagonal lines (either `/` or `\`). As a commander, you want to know how optimal this disposition is, so you would want to know how many enemies you would be able to defeat if every spaceship shot a laser in the direction they are facing. As you may have guessed, the mirrors are a strategic device that you placed there to **change the direction of the lasers** via reflection. The behavior of lasers when impacting mirror is kind of obvious: ``` /----- | >---+----\ | | | | \----/ ``` But there is a catch, **spaceships are also mirrors** that bifurcate lasers when impacted from the front: ``` | | >-----\ | | | | -+-----^--- | ``` When they are hit from behind or from the sides, the laser will **stop propagating**, but the spaceship will be just fine. # Your task Write a function `laser(field: List[str]) -> List[str]` that takes a battlefield state given as a list of strings and outputs the letters of the enemies that will be defeated in a sorted list. # Technical notes * You only count each defeated enemy **once**, even if it is hit by more than one laser. * You **can** mutate the input, but it is not necessary. * The (0, 0) is at the top left corner and the coordinates are (row, column). # Examples ``` +----------+ |> A B \| | / C | | D | => All enemies are defeated: ['A', 'B', 'C', 'D', 'E'] | | | > E /| +----------+ +----------+ |> A B \| | / E | | D | => All enemies are defeated except D and E: ['A', 'B', 'C'] | | | > C /| +----------+ +----------+ |>A B<| | / D | | D B | => All enemies are defeated: ['A', 'B', 'B', 'D', 'D'] (Notice the repeated enemies) | | |\ < > /| +----------+ ``` *__Note__: bonus internet points if you make a small, elegant solution :)*
algorithms
SHIPS = dict(zip('<>^v', [(0, - 1), (0, 1), (- 1, 0), (1, 0)])) MIRRORS = {'/': - 1, '\\': 1} def rotate(dx, dy, c): c = MIRRORS[c]; return dy * c, dx * c def laser(lst): X, Y = len(lst), len(lst[0]) out, seen = set(), set() lasers = {(x, y, * SHIPS[c]) for x, r in enumerate(lst) for y, c in enumerate(r) if c in SHIPS} while lasers: seen |= lasers bag = set() for x, y, dx, dy in lasers: a, b = x + dx, y + dy if 0 <= a < X and 0 <= b < Y: c = lst[a][b] if c in SHIPS: if SHIPS . get(c, (1, 1)) == (- dx, - dy): for m in '/\\': bag . add((a, b, * rotate(dx, dy, m))) else: if c . isalnum(): out . add((a, b)) if c in MIRRORS: dx, dy = rotate(dx, dy, c) bag . add((a, b, dx, dy)) lasers = bag - seen return sorted(lst[a][b] for a, b in out)
3-2-1 Fire!
5e94456c4af7f4001f2e2a52
[ "Games", "Algorithms" ]
https://www.codewars.com/kata/5e94456c4af7f4001f2e2a52
5 kyu
_yet another easy kata!_ ## Task: [Playfair cipher](https://en.wikipedia.org/wiki/Playfair_cipher) is a digram substitution cipher which unlike single letter substitution cipher encrypts pairs of letters. In this kata, you're going to implement the same. --- <br> ### Input A string `s` and key `key` both consist of letters from the English alphabet and whitespace characters. --- # Implementation: _In this kata, the cipher is case insensitive._ ### Matrix formation * A 5 by 5 matrix of unique letters is to be constructed. The matrix should consist of letters from the string `key` + `alphabet` considering only the first occurrence of each letter. As the number of letters in the alphabet is 26, we would consider `i` and `j` to be the same. using `playfair jexample` as key ``` P L A Y F (I/J) R E X M B C D G H K N O Q S T U V W Z ``` You have to construct 5X5 matrix with the letters of string and remaining alphabets written in this matrix (with only first occurence) Remember: if J comes before I in the key, then it's J that goes into the matrix rather than I, in short whoever comes first goes into matrix but will be used as both i and j --- ### Encryption `All examples used in this section use the above key matrix as ref.` 1. You have to deal only with letters so discard other characters. 2. Insert `x` in between all pair of contiguous letters. (`eg coddwars -> codxdwars or codddwars -> codxdxdwars`) Note :Don't worry about inputs with consecutive `xx`, you'll never encounter them during the tests. 4. Add `x` to make string length even. 5. Break the given plaintext into pairs. 6. For each pair: - If both letters are in the same row, then they are replaced by the letters to the immediate right of each one; `LY` `$\to$` `AF`. (wrap around if required, e.g `LF` `$\to$` `AP`). - If both letters are in the same column, then they are replaced by the letter immediately beneath each one; `eo` `$\to$` `dv`. (wrap around if required) - If the digraph letters are neither in the same row nor the same column, the rule differs. <br> 1. To encipher the first letter, look along its row until you reach the column containing the second letter; the letter at this intersection replaces the first letter. <br> 2. To encipher the second letter, look along its row until you reach the column containing the first letter; the letter at the intersection replaces the second letter. <br> `$\Rightarrow$` `RO` `$\to$` `EN`. 7. Now you have to insert space characters in the ciphered string so that they are matching there original position in the input string.". --- ### Output * Ciphered text generated from the above steps in upper case. --- # Example: ``` s = cozy lummox gives smart squid who asks for job pen key = playfair jexample key matrix = described above After step 1, 2, 3: s = cozylumxmoxgivesxsmartsquidwhoasksforjobpenx After step 4: s = co zy lu mx mo xg iv es xs ma rt sq ui dw ho as ks fo ri ob pe nx qr After step 5: ciphertext pairs = dn wf rl im es gq et mo mq ef iu ks tr gv ds fo nk as er kd ai After step 6: ciphered text = dnwf rlimes gqetm omqef iukst rgv dsfo nka ser kda iqr Hence, output: DNWF RLIMES GQETM OMQEF IUKST RGV DSFO NKA SER KDA IQR ``` _Enjoy!_
reference
from string import ascii_uppercase as letters import re def encipher(s, key, S=5): def cleanW(s): return s . replace(' ', '') def replKey(m): di = (m[0] + 'X')[: 2] (i, j), (x, y) = (chars[c] for c in di) return (mat[i][(j + 1) % S] + mat[x][(y + 1) % S] if i == x else mat[(i + 1) % S][j] + mat[(x + 1) % S][y] if j == y else mat[i][y] + mat[x][j]) def unused(c): nonlocal clean if c in used: return False if c in 'IJ': if c == 'J': clean = 'IJ' used . update('IJ') else: used . add(c) return True clean = 'JI' used = set() it = iter(cleanW(key . upper() + letters)) mat = [[next(c for c in it if c . isalpha() and unused(c)) for _ in range(S)] for _ in range(S)] chars = {c: (i, j) for i, r in enumerate(mat) for j, c in enumerate(r)} ss = re . sub(r'([A-Z])(?=\1)', r'\1X', cleanW(s . upper()). replace(* clean)) it = iter(re . sub(r'..?', replKey, ss)) return re . sub(r'\w', lambda _: next(it), s) + '' . join(it)
Unusual Cipher
5efdde81543b3b00153e918a
[ "Ciphers", "Fundamentals" ]
https://www.codewars.com/kata/5efdde81543b3b00153e918a
5 kyu
given the first few terms of a sequence, can you figure out the formula that was used to generate these numbers, so we can find any term in the sequence? ## Task - write a function that accepts an array of number(the first few terms of a sequence) - your function should return a mapping function that accepts an integer(n) and then return the nth term of the sequence, where zero is the first term. - in practice a sequance can be completed in many ways, assume that the equation used is a [Polynomial](https://en.wikipedia.org/wiki/Polynomial), and find the simplest(smallest degree) equation possible, that leaves you with a single unique solution. ## Examples | input | equation | degree | more terms | | --- | --- | --- | --- | | `[2, 4, 6]` | `$ 2x+2 $` | `$ 1 $` | `2, 4, 6, 8, 10, 12, ...` | | `[100, 101]` | `$ x+100 $` | `$ 1 $` | `100, 101, 102, 103, ...` | | `[5]` | `$ 5 $` | `$ 0 $` | `5, 5, 5, 5, 5, 5, ...` | | `[6, 17, 88, 321, 866]` | `$ 2x^4+5x^3+x^2+3x+6 $` | `$ 4 $` | `6, 17, 88, 321, 866, 1921, ...` | | `[1, 1, 1, 7]` | `$ x^3-3x^2+2x+1 $` | `$ 3 $` | `1, 1, 1, 7, 25, 61, ...` | | `[]` | `$ 0 $` | `$ 0 $` | `0, 0, 0, 0, 0, 0, ...` | | `[3, 2, 1]` | `$ -x+3 $` | `$ 1 $` | `3, 2, 1, 0, -1, -2, ...` | ## Notes - your solution should support at least equations of degree 0 to 9 - your solution should run fast when `n` is big - all tests are random, but you don't need to worry about invalid input - always return a solution even if you get empty input - usually you get more terms than you need, but sometimes you get exactly what you need - all sequences have integer terms and uses equations with integer coefficients ```if:javascript For javascript, return the value of the nth term as a `BigInt` type ``` ```if:python For python, numpy is disabled. ```
algorithms
def solve_sequence(seq): ds = [(seq[:] or [0])] while len(set(seq)) > 1: ds . append(seq := [b - a for a, b in zip(seq, seq[1:])]) def fact(n, l): return n * fact(n - 1, l - 1) if l else 1 terms = [v[0] / / fact(i, i) for i, v in enumerate(ds)] return lambda n: sum(v * fact(n, i) if i else v for i, v in enumerate(terms))
Find the nth Term of a Sequence
60f9f0145a54f500107ae29b
[ "Algebra", "Algorithms" ]
https://www.codewars.com/kata/60f9f0145a54f500107ae29b
5 kyu
We have to solve the Diophantine Equation: x<sup>2</sup> + 3y<sup>2</sup> = z<sup>3</sup> So, `x`, `y` and `z`, should be strictly positive integers (`x, y, z > 0`). This equation has a certain number of solutions if the value of `z` is limited. Let's say we want to know the number of solutions when `z` is under or equal 10 (`z ≤ 10`). The equation given above has `3` solutions and are: ``` x y z Verified equation x + y + z 4 4 4 4² + 3*4² = 4³ (64 = 64) 12 10 9 7 10² + 3*9² = 7³ (343 = 343) 26 14 7 7 14² + 3*7² = 7³ (343 = 343) 28 ``` Implement a brute force algorithm that given an upper bound `z_max ≤ 600` may find the number of total solutions having `z ≤ z_max`. Besides, it should output the solutions with the maximum possible value of `z` (and obviously less or equal to `z_max`). They should be sorted by the value of `x+y+z` increasing. If some solutions have the same sum, sort them by `x` decreasing. Let's see some examples of our ```dioph_solver()``` ```python dioph_solver(10) == [3, [[10, 9, 7], [14, 7, 7]]] dioph_solver(15) == [6, [[26, 13, 13], [35, 18, 13]]] ``` Have a good and productive time!
reference
total, memo = 0, [[], [], [], []] for z in range(4, 600): x, z3, tmp = 1, z * * 3, [] while (x2 := x * * 2) < z3: y2, r = divmod(z3 - x2, 3) if r == 0 and (y := y2 * * 0.5) % 1 == 0: tmp . append([x, int(y), z]) total += 1 x += 1 if tmp: tmp . sort(key=lambda t: (sum(t), - t[0])) else: tmp = memo[- 1][1] memo . append([total, tmp]) dioph_solver = memo . __getitem__
Diophantine Equation Solver
57e32bb7ec7d241045000661
[ "Data Structures", "Algorithms", "Mathematics" ]
https://www.codewars.com/kata/57e32bb7ec7d241045000661
6 kyu
### Peel the onion Your function will receive two positive integers ( integers ranging from 1 upward), and return an array. There's logic in there, but all you get are the example test cases to find it. Below overview for your convenience. (And, alright: the function name is a strong hint of what to do.) ``` (s, d) => array (1, 1) => [1] (2, 1) => [2] (3, 1) => [2, 1] (4, 1) => [2, 2] (5, 1) => [2, 2, 1] (1, 2) => [1] (2, 2) => [4] (3, 2) => [8, 1] (4, 2) => [12, 4] (5, 2) => [16, 8, 1] (1, 3) => [1] (2, 3) => [8] (3, 3) => [26, 1] (4, 3) => [56, 8] (5, 3) => [98, 26, 1] (1, 4) => [1] (2, 4) => [16] (3, 4) => [80, 1] (4, 4) => [240, 16] (5, 4) => [544, 80, 1] ```
games
def peel_the_onion(s, d): return [i * * d - (i - 2) * * d if i > 1 else 1 for i in range(s, 0, - 2)]
Peel the onion
60fa9511fb42620019966b35
[ "Algorithms", "Puzzles", "Mathematics", "Logic" ]
https://www.codewars.com/kata/60fa9511fb42620019966b35
6 kyu
The task is to find, as fast as you can, a rearrangement for a given square matrix, of different positive integers, that its determinant is equal to ```0```. E.g: ``` matrix = [[2, 1], [3, 6]] determinant = 9 ``` With the arrengament: ``` [[2, 1], [6, 3]] determinant = 0 ``` Create a function ```rearr()``` that receives a square matrix and outputs a new square matrix with the same elements but reordered to have its determinant the 0 value. If there is no possible matrix for that the function should output ```-1```. You may see content about the determinant of a 3 x 3 matrix <a href= "https://www.khanacademy.org/math/algebra-home/alg-matrices/alg-determinants-and-inverses-of-large-matrices/v/finding-the-determinant-of-a-3x3-matrix-method-2"> Here</a> And for a 4 x 4 matrix <a href = "https://www.khanacademy.org/math/linear-algebra/matrix-transformations/determinant-depth/v/linear-algebra-simpler-4x4-determinant">There</a> The determinant of a 2 x 2 you will find it easy. Features of the random tests: ``` numbers of random tests = 122 tests for 2x2 (100), 3x3 (20) and 4x4 (2) matrices ``` Enjoy it!!
reference
import numpy as np from itertools import permutations, chain def rearr(matrix): ln = len(matrix) for p in permutations(chain . from_iterable(matrix)): arr = np . reshape(p, (ln, ln)) if np . linalg . det(arr) == 0: return arr . tolist() return - 1
#3 Matrices: Rearrange the matrix
5901aee0af945e3a35000068
[ "Algorithms", "Puzzles", "Linear Algebra", "Fundamentals", "Matrix" ]
https://www.codewars.com/kata/5901aee0af945e3a35000068
5 kyu
We have the following sequences, each of them with a its id (f_): Triangular numbers Tn: ```T(n) = n * (n + 1) / 2``` -------------> ```f3``` Square Numbers Sqn: ```Sq(n) = n * n``` ----------------------------> ```f4``` PentagonalNumbers Pn: ```P(n) = n * (3 * n − 1) / 2``` ------------> ```f5``` Hexagonal Numbers Hn: ```H(n) = n * (2 * n − 1)``` -----------------> ```f6``` Heptagonal Numbers Heptn: ```Hept(n) = n * (5 * n − 3) / 2``` ------> ```f7``` Octagonal Numbers On: ```O(n) = n * (3 * n − 2)``` -----------------> ```f8``` All functions can be accessed via the FUNCTIONS variable in the preloaded section: ``` FUNCTIONS = [f3, f4, f5, f6, f7, f8] ``` Suposse that we want to obtain, for example, the first ```6```, (n terms) of the sequence of the Hexagonal numbers. They are: ```1, 6, 15, 28, 45 and 66``` Now we are going to make a 'chain of corresponding terms' with the remaining sequences: ``` Term Hex Seq Triang Seq Square Seq Pentag Seq Hept Seq Oct Seq chain 1 1 1 1 1 1 1 1 chain 2 2 6 3 4 5 7 8 chain 3 3 15 6 9 12 18 21 chain 4 4 28 10 16 22 34 40 chain 5 5 45 15 25 35 55 65 chain 6 6 66 21 36 51 81 96 ``` Now we proceed to obtain the numeric result for each chain. We multiply the value of the selected function, in this case the value of the Hexagonal sequence, by the result of the sum of the terms of the remaining sequences. The results for every chain will be: ``` chain 1 = 1 * ( 1 + 1 + 1 + 1 + 1) = 1 * 5 = 5 chain2 = 6 * (3 + 4 + 5 + 7 + 8) = 6 * 27 = 162 chain3 = 15 * (6 + 9 + 12 + 18 + 21) = 15 * 66 = 990 chain4 = 28 * (10 + 16 + 22 + 34 + 40) = 28 * 122 = 3416 chain5 = 45 * (15 + 25 + 35 + 55 + 65) = 45 * 195 = 8775 chain6 = 66 * (21 + 36 + 51 + 81 + 96) = 66 * 285 = 18810 ``` The total sum of the chains will be: ``` ChainsTotalSums = 5 + 162 + 990 + 3416 + 8775 + 18810 = 32158 ``` # Task We need a function ```make_sum_chains()``` that can make this calculation. The function will receive two arguments, the ```function id```, and the number of terms n. # Examples ```python f_ = f6 n = 6 make_sum_chains(f_, n) == 32158 ``` Another one: ```python f_ = f8 n = 10 make_sum_chains(f_, n) == 503855 ``` The number will be allways positive (1 <= n <= 10^4). Enjoy it!!
reference
def make_sum_chains(f_, n): return sum(f_(i) * sum(f(i) for f in FUNCTIONS if f != f_) for i in range(1, n + 1))
Chains With Sums and Products
566b4504595b1b2317000012
[ "Fundamentals", "Mathematics" ]
https://www.codewars.com/kata/566b4504595b1b2317000012
6 kyu
An equilateral triangle with integer side length `n>=3` is divided into `n^2` equilateral triangles with side length 1 as shown in the diagram below. The vertices of these triangles constitute a triangular lattice with `(n+1)(n+2)/2` lattice points. Base triangle for `n=3`: ![Example](https://projecteuler.net/project/images/p577_counting_hexagons.png) Last regular hexagon for `n=6`: <svg xmlns:osb="http://www.openswatchbook.org/uri/2009/osb" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 127.219 110.614" height="418.069" width="480.829"><defs><linearGradient osb:paint="solid" id="a"><stop offset="0" stop-color="#00df00"/></linearGradient><linearGradient gradientUnits="userSpaceOnUse" y2="150.473" x2="118.61" y1="150.473" x1="55.382" id="b" xlink:href="#a"/></defs><path d="M93.458 89.647l-29.595 16.91-29.442-17.175.153-34.085 29.595-16.91L93.61 55.562z" fill="#00f8fc" stroke="#000" stroke-width=".185"/><path transform="matrix(.93938 -.55445 .54937 .94807 -100.327 -22.187)" d="M118.349 168.762l-31.515 18.007L55.48 168.48l.163-36.296 31.515-18.008 31.352 18.29z" fill="none" stroke="url(#b)" stroke-width=".197"/><path d="M123.851 106.281l-118.882.821L63.699 3.737z" fill="none" stroke="#ed0000" stroke-width=".338"/></svg> Let `H(n)` be the number of all regular hexagons that can be found by connecting 6 of these points. For example, `H(3)=1`, `H(6)=12` and `H(20)=966`. Create function `counting_hexagons` that calculates `H(n)` where `3 <= n <= 40000`. Solution size should be less than 8KB. `Javascript: use BigInt` _Adopted from projecteuler.net_
games
# Who needs loops? def counting_hexagons(n): x = n / / 3 s0 = x s1 = x * (x - 1) / / 2 s2 = s1 * (2 * x - 1) / / 3 s3 = s1 * s1 m0 = s0 * (n * * 2 - 3 * n + 2) m1 = s1 * (n * * 2 - 9 * n + 11) m2 = s2 * (- 6 * n + 18) m3 = s3 * 9 return (m0 + m1 + m2 + m3) / / 2
Counting hexagons
60eb76fd53673e001d7b1b98
[ "Mathematics", "Puzzles" ]
https://www.codewars.com/kata/60eb76fd53673e001d7b1b98
6 kyu
Different colour pattern lists produce different numerical sequences in colours. For example the sequence [<span style="color:red">'red'</span>, <span style="color:#EEBB00">'yellow''</span>, <span style="color:DodgerBlue">'blue''</span>], produces the following coloured sequence: <span style="color:red"> 1 </span> <span style="color:#EEBB00"> 2</span> <span style="color:DodgerBlue"> 3</span> <span style="color:red"> 4 </span><span style="color:#EEBB00"> 5</span> <span style="color:DodgerBlue"> 6 </span> <span style="color:red"> 7 </span><span style="color:#EEBB00"> 8</span> <span style="color:DodgerBlue"> 9</span> <span style="color:red"> 10</span> <span style="color:#EEBB00"> 11 </span><span style="color:DodgerBlue"> 12 </span> <span style="color:red"> 13</span>..... The sequence [<span style="color:red">'red'</span>, <span style="color:#EEBB00">'yellow'</span>, <span style="color:DodgerBlue">'blue'</span>, <span style="color:orange"> 'orange'</span>, <span style="color:green"> 'green'</span>] produce the sequence: <span style="color:red"> 1 </span> <span style="color:#EEBB00"> 2 </span><span style="color:DodgerBlue"> 3 </span> <span style="color:orange"> 4 </span><span style="color:green"> 5 </span> <span style="color:red"> 6 </span> <span style="color:#EEBB00"> 7 </span><span style="color:DodgerBlue"> 8 </span> <span style="color:orange"> 9 </span><span style="color:green"> 10 </span><span style="color:red"> 11</span> <span style="color:#EEBB00"> 12</span> <span style="color:DodgerBlue"> 13</span>..... We have the following recursive sequence: * a<sub>1</sub> = 1 * a<sub>n</sub> = a<sub>n-1</sub> + n + k having that **k** may be positive or negative. ## Task Create a function ```count_col_hits()```, (javascript ```countColHits()```that receives the following arguments: - the value of k - a certain pattern colour list, `pat_col`,or array of colours (that has an specific order as it was shown above) - a range of values, `range_`, an array of two elements, having a lower and upper bound, `[a, b]`, such that `a < b` The function should output an array with two elements: - the maximum number of hits that each colour has in the range `[a, b]`, such that every value, `val`, that hits the sequence of coloured numbers are such that, `a ≤ val ≤ b` - the corresponding name of the colour that produces this maximum amount of hits (or it may be also colours that produce the maximum amount of hits). ### Examples ```python k = -4 pat_col = ['red', 'yellow', 'blue', 'orange', 'green'] range_ = [20, 40] ith term value colour hit or not 1 1 red yes 2 -1 --- no (negative values do not hit) 3 -2 --- no 4 -2 --- no 5 -1 --- no 6 1 red yes 7 4 orange yes 8 8 blue yes 9 13 blue yes 10 19 orange yes 11 26 red yes <---- hit in the range, 20 ≤ 26 ≤ 40 12 34 orange yes <---- hit in the range, 20 ≤ 34 ≤ 40 count_col_hits(k, pat_col, range_) == [1, ['orange', 'red']] # If there is more than one colour the array should be sorted alphabetically ``` Having another case changing the input: ```python k = -7 pat_col = ['red', 'yellow', 'blue', 'orange', 'green', 'pink'] range_ = [20, 150] count_col_hits(k, pat_col, range_) == [4, 'orange'] #If there is only one colour with maximum amount of hits there is no need to use an array of colours in the result. # The other colours had the result: 'red': 3, 'green': 2, 'yellow': 1, 'blue': 0, 'pink': 0 ``` Your code should handle carefully the cases where there are no hits at all. For that case the output should be an empty array. ```python k = 50 pat_col = ['red', 'yellow', 'blue', 'orange', 'green', 'pink'] range_ = [20, 50] count_col_hits(k, pat_col, range_) == [] ``` You will be always receiving valid inputs for the arguments of the function. --- Features of the random tests: * Numpber of tests: `200` * `-100 ≤ k ≤ 100` * length of pattern colour array: `5 ≤ l ≤ 20` * `100 ≤ a ≤ 100000`, `1000 ≤ b ≤ 10**8` and always `a < b`
reference
from itertools import count, takewhile from collections import Counter from math import ceil def count_col_hits(k, col, rng): a, b = rng na = ceil((- (2 * k + 1) + ((2 * k + 1) * * 2 + 8 * (k + a)) * * .5) / 2) c = Counter(col[(v - 1) % len(col)] for v in takewhile(lambda v: v <= b, (n * (n + 1) / / 2 + (n - 1) * k for n in count(na)))) if not c: return [] mCol = max(c . values()) lst = sorted(k for k, v in c . items() if v == mCol) return [mCol, lst if len(lst) != 1 else lst[0]]
Working With Coloured Numbers II
57fb33039610ce3b490000f9
[ "Fundamentals", "Data Structures", "Algorithms", "Mathematics", "Logic", "Strings" ]
https://www.codewars.com/kata/57fb33039610ce3b490000f9
5 kyu
We are given an array of digits (0 <= digit <= 9). Let's have one as an example ```[3, 5, 2]``` ```Step 1```: We form all the possible numbers with these digits ``` [3, 5, 2] (dig_list)----> [2, 3, 5, 23, 25, 32, 35, 52, 53, 235, 253, 325, 352, 523, 532] (generated numbers, gen_num) ``` ```Step 2```: According to `pow_`, a given integer, we form an array with the terms of a power, sequence up to the maximum generated number (all the power terms should be less or equal than this maximum number). For our example we define the power equals to ```2``` ``` max_number = 532 pow_ = 2 (square numbers) powL = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529] ``` ```Step3```: We will form all the possible sub arrays with **contiguous perfect squares**, calculating its corresponding sum of terms. We start with sub-arrays with length 1, up to the maximum possible lengths. ``` sub-array sum Is in gen_num [1] 1 False [4] 4 False [9] 9 False [16] 16 False [25] 25 True <--- hit (when the sum of powers coincides with a number of gen_num) .... ... .... .... ... .... [1, 4] 5 True <--- hit [4, 9] 13 False [9, 16] 25 True (but we don't count it, we had a hit at 25 and we count different values) [16, 25] 41 False [25, 36] 61 False [36, 49] 85 False ....... ... ..... [1, 4, 9] 14 False [4, 9, 16] 29 False [9, 16, 25] 50 False .......... ... ..... And so on. ``` For this example we had three hits ```[5, 25, 25]```, but we do not count values with twice or more hits, so we had two hits at```5``` and ```25``` For the case: ``` dig_list = [3, 5, 2, 4, 6, 7, 9] pow_ = 2 amount_hits = 208 ``` We may have a different power. See this case: ``` dig_list = [3, 5, 2, 4, 6, 7, 9] pow_ = 3 amount_hits = 29 ``` Make the function ```count_hits_powterm```, that receives two arguments ```dig_list``` and ```pow_```. The function will output a tuple with the amount of hits and a sorted list with the values having at least a hit. Let's two examples: ```python dig_list = [3, 5, 2] pow_ = 2 count_hits_powterm(dig_list, pow_) == (2, [5, 25]) dig_list = [3, 5, 2, 4, 6, 7, 9] pow_ = 3 count_hits_powterm(dig_list, pow_) == (29, [9, 27, 35, 36, 64, 432, 729, 3572, 3925, 4256, 4356, 5643, 27945, 37259, 43659, 46935, 75392, 273645, 462537, 674325, 674352, 2573496, 2943675, 3974256, 4762395, 5497632, 5924736, 6739524, 9426375]) ``` If we have in our ```dig_list``` the digit ```0```, if a generated number has a leading zero will be discarded. For example let's see the numbers generated for a case like this: ``` dig_list = [3, 5, 2, 0] -----> [2, 3, 5, 20, 23, 25, 30, 32, 35, 50, 52, 53, 203, 205, 230, 235, 250, 253, 302, 305, 320, 325, 350, 352, 502, 503, 520, 523, 530, 532, 2035, 2053, 2305, 2350, 2503, 2530, 3025, 3052, 3205, 3250, 3502, 3520, 5023, 5032, 5203, 5230, 5302, 5320] (gen_num) ``` Digits may occur twice or more in the given dig_list. ``` dig_list = [3, 5, 5] -----> [3, 5, 35, 53, 55, 355, 535, 553] (gen_num) ``` Enjoy it!! Operations with sets may be useful for optimization.
reference
from itertools import accumulate, chain, count, dropwhile, takewhile, islice, permutations def permuted_powerset(digits): l = list(map(str, digits)) c = chain . from_iterable(permutations(l, r) for r in range(1, len(l) + 1)) return dropwhile(0 . __eq__, map(int, map('' . join, c))) def sublist_sum_below(m, iterable): l = list(takewhile(m . __ge__, iterable)) a = (accumulate(islice(l, i, None)) for i in range(len(l))) return chain . from_iterable(takewhile(m . __ge__, g) for g in a) def count_hits_powterm(digits, power): p = set(permuted_powerset(digits)) s = p . intersection(sublist_sum_below( max(p), map(power . __rpow__, count(1)))) return len(s), sorted(s)
Count The Hits Adding Contiguous Powers!
569d754ec6447d939c000046
[ "Fundamentals", "Mathematics", "Permutations", "Sorting", "Logic", "Strings" ]
https://www.codewars.com/kata/569d754ec6447d939c000046
5 kyu
The two integer triangles have something in common: <a href="http://imgur.com/7eXfJXH"><img src="http://i.imgur.com/7eXfJXH.jpg?1" title="source: imgur.com" /></a> <a href="http://imgur.com/oWywzs2"><img src="http://i.imgur.com/oWywzs2.jpg?1" title="source: imgur.com" /></a> In the smaller triangle with sides ```(4, 5, 6)``` the value of an angle is twice the value of another one. In effect ```∠C = 2(∠B)``` and the perimeter ```p``` of this triangle is: ``` p = 4 + 5 + 6 = 15 ``` In the bigger triangle with sides ```(7, 9, 12)``` one angle of it is the double of other angle. In this case ```∠C = 2(∠A)``` and the perimeter ```p``` of this other triangle is: ``` p = 7 + 9 + 12 = 28 ``` The triangle ```(4, 5, 6)``` is the smallest integer triangle in having this property and the following is ```(7, 9, 12)```. Both of them fulfill this property, the Greatest Common Divisor (gcd) of the sides a, b, c is one. In another way: ```gcd = 1``` The first perimeters of these triangles with the corresponding triple of triangle sides is as follows: ``` Ord num perimeter (p) triangle (all with gcd(a, b ,c) = 1) 1 15 (4, 5, 6) 2 28 (7, 9, 12) 3 40 (9, 15, 16) 4 45 (9, 16, 20) ``` We need a function ```per_ang_twice()```, that we introduce the number ```n```, the ordinal number of the sequence and will output an array with the perimeter value first and then a list with the triangle or triangles (with one angle value twice the value of another triangle angle) Let's see the previous cases applied to our wanted function: ```python per_ang_twice(1) == [15, [(4, 5, 6)]] per_ang_twice(2) == [28, [(7, 9, 12)]] per_ang_twice(3) == [40, [(9, 15, 16)]] per_ang_twice(4) == [45, [(9, 16, 20)]] ``` The values of the triangle sides should be be sorted. If the ordinal number outputs a perimeter value having more than one triangle, these last ones should be sorted by the value of the first side ```python perAngTwice(1016) == [11704, [(304, 5625, 5775), (2025, 3960, 5719)]]) ``` Your code will be tested for perimeters values up to 1.500.000. You will find some hints for special integer triangles at : https://en.wikipedia.org/wiki/Integer_triangle Happy coding!!
reference
from collections import defaultdict from functools import reduce from math import gcd from heapq import * def queuer(n, m): return m * (m + n), n, m MAX_P = 1500000 D_ORD = defaultdict(list) q, seen = [queuer(2, 3)], set((2, 3)) while q: p, n, m = heappop(q) a, b, c = tri = tuple(sorted((n * n, m * n, m * m - n * n))) if reduce(gcd, tri) == 1: D_ORD[p]. append(tri) for nxt in ((n + 1, m + (m - n == 1)), (n, m + 1)) if m < 2 * n - 1 else ((n + 1, m + (m - n == 1)),): if nxt not in seen: tup = queuer(* nxt) if tup[0] <= MAX_P: heappush(q, tup) seen . add(nxt) LST = [[k, sorted(lst)] for k, lst in D_ORD . items()] def per_ang_twice(n): return LST[n - 1]
Integer Triangles Having One Angle The Double of Another One
56411486f3486fd9a300001a
[ "Fundamentals", "Algorithms", "Mathematics", "Geometry", "Memoization", "Data Structures" ]
https://www.codewars.com/kata/56411486f3486fd9a300001a
5 kyu
Create a Regular Expression that matches valid [pawn moves](https://en.wikipedia.org/wiki/Chess_piece) from the chess game (using standard Algebraic notation). https://en.wikipedia.org/wiki/Algebraic_notation_(chess) # The notation on the chess board ``` a b c d e f g h ⬜⬛⬜⬛⬜⬛⬜⬛ 8 ⬛⬜⬛⬜⬛⬜⬛⬜ 7 ⬜⬛⬜⬛⬜⬛⬜⬛ 6 ⬛⬜⬛⬜⬛⬜⬛⬜ 5 ⬜⬛⬜⬛⬜⬛⬜⬛ 4 ⬛⬜⬛⬜⬛⬜⬛⬜ 3 ⬜⬛⬜⬛⬜⬛⬜⬛ 2 ⬛⬜⬛⬜⬛⬜⬛⬜ 1 ``` # Simple moves `a4` denotes a pawn move to the square a4. Note that the departing square is not important (which, in case of `a4`, could be `a2` or `a3` for white and `a5` for black). # Captures They are using `[fromCol]x[toSquare]`. `axb5` means a capture by a pawn coming from the column `a` on the square `b5`. Be aware that captures can only be performed in diagonals. So `axf3` isn't a valid notation. # En passant (https://en.wikipedia.org/wiki/En_passant) "En passant" is a special case of capture, that can be executed in very specific conditions. I'll let you figure out what they are... To denote "en passant", `e.p.` is added after the capture notation: * `bxc6e.p.` is valid * `c6e.p.` or `bxa4e.p.` aren't valid # Promotion When a pawn reaches the opposite end of the board, it can be promoted to some other pieces: Q, B, N, R. For this kata, we will considere that those pawn HAVE to be promoted. This is denoted this way: * `a8=Q` or `f1=B` are valid promotions * `c3=R` or `a8` aren't valid # Check and checkmate Check is notated `+`, checkmate is notated `#`. Fro example: `a7+` or `a1=Q#` <br> Of course, some of these rules may apply at the same time... (or not. Think about it ;) ) ```if:python Matching will be done using `re.match(your_string)` ``` ____ These tools may help you: [Regexp cheat sheet](https://www.rexegg.com/regex-quickstart.html) [Online tester](https://regex101.com/r/1uTQes/11)
algorithms
VALID_PAWN_MOVE_REGEX = '([a-h][2-7]|[a-h][18]=[QBNR]|(axb|bx[ac]|cx[bd]|dx[ce]|ex[df]|fx[eg]|gx[fh]|hxg)([2457]|[36](e\.p\.)?|[18](=[QBNR])?))[+#]?$'
Chess Fun # 13 : RegEx Like a Boss #1 : Valid Pawn Moves
5c178c8430f61aa318000117
[ "Regular Expressions", "Algorithms" ]
https://www.codewars.com/kata/5c178c8430f61aa318000117
5 kyu
A chess position can be expressed as a string using the <a href="https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation"> Forsyth–Edwards Notation (FEN)</a>. Your task is to write a parser that reads in a FEN-encoded string and returns a depiction of the board using the Unicode chess symbols (♔,♕,♘,etc.). The board should be drawn from the perspective of the active color (i.e. the side making the next move). <i>Using the CodeWars dark theme is strongly recommended for this kata. Otherwise, the colors will appear to be inverted.</i> The complete FEN format contains 6 fields separated by spaces, but we will only consider the first two fields: Piece placement and active color (side-to-move). The rules for these fields are as follows: <ul> <li>The first field of the FEN describes piece placement.</li> <li>Each row ('rank') of the board is described one-by-one, starting with rank 8 (the far side of the board from White's perspective) and ending with rank 1 (White's home rank). Rows are separated by a forward slash ('/').</li> <li>Within each row, the contents of the squares are listed starting with the "a-file" (White's left) and ending with the "h-file" (White's right).</li> <li>Each piece is identified by a single letter: pawn = P, knight = N, bishop = B, rook = R, queen = Q and king = K. White pieces are upper-case (PNBRQK), while black pieces are lowercase (pnbrqk).</li> <li>Empty squares are represented using the digits 1 through 8 to denote the number of consecutive empty squares.</li> <li>The piece placement field is followed by a single space, then a single character representing the color who has the next move ('w' for White and 'b' for Black).</li> <li>Four additional fields follow the active color, separated by spaces. These fields can be ignored.</li> </ul><br/> Using this encoding, the starting position is: ```rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1``` Using the characters "_" and "▇" to represent dark and light unoccupied spaces, respectively, the starting position using the Unicode pieces would be: <br /> ♖♘♗♕♔♗♘♖<br /> ♙♙♙♙♙♙♙♙<br /> ▇_▇_▇_▇_<br /> _▇_▇_▇_▇<br /> ▇_▇_▇_▇_<br /> _▇_▇_▇_▇<br /> ♟♟♟♟♟♟♟♟<br /> ♜♞♝♛♚♝♞♜<br /> <br /> After the move 1. Nf3, the FEN would be... ```rnbqkbnr/pppppppp/8/8/8/5N2/PPPPPPPP/RNBQKB1R b KQkq - 1 1``` ...and because we draw the board from the perspective of the active color, the Unicode board would be: <br /> ♜_♝♛♚♝♞♜<br /> ♟♟♟♟♟♟♟♟<br /> ▇_♞_▇_▇_<br /> _▇_▇_▇_▇<br /> ▇_▇_▇_▇_<br /> _▇_▇_▇_▇<br /> ♙♙♙♙♙♙♙♙<br /> ♖♘♗♕♔♗♘♖<br /> <br /> <b>Symbols</b> <br /> *Again, note that these colors are inverted from the Unicode character names because most people seem to use the dark theme for CodeWars. <br /> <ul> <li>Empty white square: ▇ (2587)</li> <li>Empty black square: _ (FF3F)</li> <li>White king (K): ♚ (265A)</li> <li>White queen (Q): ♛ (265B)</li> <li>White rook (R): ♜ (265C)</li> <li>White bishop (B): ♝ (265D)</li> <li>White knight (N): ♞ (265E)</li> <li>White pawn (P): ♟ (265F)</li> <li>Black king (k): ♔ (2654)</li> <li>Black queen (q): ♕ (2655)</li> <li>Black rook (r): ♖ (2656)</li> <li>Black bishop (b): ♗ (2657)</li> <li>Black knight (n): ♘ (2658)</li> <li>Black pawn (p): ♙ (2659)</li> </ul> <b>NB: Empty squares must have the proper colors.</b> The bottom-right and top-left squares on a chess board are white.
algorithms
map = { "r": "♖", "n": "♘", "b": "♗", "q": "♕", "k": "♔", "p": "♙", "R": "♜", "N": "♞", "B": "♝", "Q": "♛", "K": "♚", "P": "♟", } blank1 = "▇" blank2 = "_" def parse_fen(string): fields = string . split(" ") state = fields[0]. split("/") flip = 1 if fields[1] == "w" else - 1 board = "" for y, row in enumerate(state[:: flip]): x = 0 for code in row[:: flip]: if code in map: board += map[code] x += 1 else: for _ in range(int(code)): board += blank2 if (y + x) % 2 else blank1 x += 1 board += "\n" return board
Chess position parser (FEN)
56876fd23475fa415e000031
[ "Unicode", "Algorithms" ]
https://www.codewars.com/kata/56876fd23475fa415e000031
5 kyu
This kata is an extension and harder version of another kata, [Reflecting Light](https://www.codewars.com/kata/5eaf88f92b679f001423cc66), it is recommended to do that one first. <details> <summary>Reminders from Reflecting Light</summary> Four mirrors are placed in a way that they form a rectangle with corners at coordinates `(0, 0)`, `(max_x, 0)`, `(0, max_y)`, and `(max_x, max_y)`. A light ray enters the rectangle at point, `(0, 0)`. If the light ray hits one of the rectangle's corners, and exits out of the rectangle. We can think of the light ray as a line. About everything else is different in this kata. </details> **Parameters** - `max_x` and `max_y` are the same parameters passed in as the previous version. - `point` is another parameter passed in. If we connect the line from `(0, 0)` to `point`, that is the path of the light as it enters the rectangle. The next mirror it touches will mark its first reflection. - The last paramter is `num_reflections`. This is the maximum amount of times the light ray will still reflect. If the number of reflections of the light ray exceeds this number, it will vanish. **The reflection of light** In this case, to know how the light will reflect, please look at the following image: ![Reflecting light](data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxIQDw8PDxAQEA8PDg8PDw8QEBAVFRAPFRUXFhUWFRYYHiggGBolGxYXITIhJSorLi4uFx8zODMsNygtLisBCgoKDg0OFxAQFy8lICUtLS0vLS0tKy0tLS0tLS0tLSstLS0tLS0tLS0tLS0tLTAtLS0vLS0tLS0tLS0tLS0rLf/AABEIAKgBLAMBEQACEQEDEQH/xAAcAAADAAMBAQEAAAAAAAAAAAAAAQIDBAUGBwj/xABKEAABAwIDAwcIBgkCBAcAAAABAAIDBBEFEiExQdEGExUiUXGTFDJTVFVhgZEjc5ShsbIHFkJScpKis8GC0iQzdPA0Q0RFY8Ph/8QAGgEBAQADAQEAAAAAAAAAAAAAAAECAwQFBv/EADURAAIBAgQDBgUDBAMBAAAAAAABAgMRBBIhMUFRkQUTFFJhcSKBsdHwMqHBM0Lh8RUjgmL/2gAMAwEAAhEDEQA/AO+F1mZQQFBCnnuVXJ5srXVMVo6iNpcSBpK1ovZwG+w0Pw7uavRUldbnoYHGS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NYXEBabuVhXV3fMnJr63sHzmkFBvehv111nogZrm9grXxeIqFpW6/ituXW4K81tHe861O5X2djprRA98sXYngtlHzq25GSzIyFchr0vZlRAiu3LWqqx8wN+HiZaYQKJwjhnETxJsrLox7FLPXTYMpicLFI+rXTyaLsQCzb2fDwAEvQnsIBCEIBCEIBCEIBCEIBCEIH//Z) Anyways, they both include the angle of reflection and the angle of incidence. In our kata and both these images, those angles are the exact same. The line seperating the two angles is perpendicular to the mirror. **Task** Find the number of reflections the light ray has reflected off of the top, right, bottom, and left mirrors **until the ray hits a corner or vanishes**. Return a tuple of the number of reflections off of each of the mirrors in that order(top, right, bottom, left.) ``` Top ------------------------ | |R L| |i e| |g f| |h t| |t | | ------------------------ Bottom ``` **Examples** - `max_x = 42`, `max_y = 56`, `point = (5, 5)`, `num_reflections = 10` ![d](https://i.imgur.com/rX9AT7Q.png) Should return `(1, 2, 1, 1)`. There were 5 reflections, and that is less than 10. **Notes:** - If the light ray goes through the corner, for instance the top right corner, it doesn't count as hitting the top mirror or the right mirror.
reference
from math import gcd def reflecting_light(max_x, max_y, point, num_reflections): dx, dy = point if dx == 0 or dy == 0: return 0, 0, 0, 0 d = gcd(dx, dy) max_x *= dy / / d max_y *= dx / / d r0 = (max_x + max_y) / / gcd(max_x, max_y) r = min(r0, num_reflections + 1) nx = max_x * r / / (max_x + max_y) - (r == r0) ny = max_y * r / / (max_x + max_y) - (r == r0) return (nx + 1) / / 2, (ny + 1) / / 2, nx / / 2, ny / / 2
Reflecting Light V2
5f30a416542ae3002a9c4e18
[ "Geometry", "Mathematics" ]
https://www.codewars.com/kata/5f30a416542ae3002a9c4e18
5 kyu
<h1>Task</h1> Write a program that uses the image of the Tic-Tac-Toe field to determine whether this situation could have occurred as a result of playing with all the rules. Recall that the game of "Tic-Tac-Toe" is played on a 3x3 field. Two players take turns. The first puts a cross, and the second – a zero. It is allowed to put a cross and a zero in any cell of the field that is not yet occupied. When one of the players puts three of his signs in the same horizontal, vertical or diagonal, or when all the cells of the field are occupied, the game ends. ## Input/Output Input: a 9-character string describing the playing field, the "_" symbol indicates an empty cell. It is guaranteed that the string contains only the characters `X`, `0`, `_`. <p>Output: True if this situation can occur during a fair game according to the rules and False otherwise.</p> <h1>Examples</h1> ```python is_it_possible("XXX"+\ "XXX"+\ "XXX") # Should return False is_it_possible("0XX"+\ "XX0"+\ "00X") # Should return True is_it_possible("XXX"+\ "0_0"+\ "___") # Should return True is_it_possible("___"+\ "___"+\ "___") # Should return True is_it_possible("XXX"+\ "000"+\ "___") # Should return False ```
games
def is_it_possible(field): flag = True ls = [(0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6)] num = field . count('X') - field . count('0') dic = {1: ('0', '0', '0'), 0: ('X', 'X', 'X')} if num in [0, 1]: for a, b, c in ls: if (num, (field[a], field[b], field[c])) in dic . items(): flag = False else: flag = False return flag
Check that the situation is correct
5f78635e51f6bc003362c7d9
[ "Puzzles" ]
https://www.codewars.com/kata/5f78635e51f6bc003362c7d9
5 kyu
Given a positive integer (n) find the nearest fibonacci number to (n). If there are more than one fibonacci with equal distance to the given number return the smallest one. Do it in a efficient way. 5000 tests with the input range 1 <= n <= 2^512 should not exceed 200 ms.
algorithms
from bisect import bisect FIB = [0, 1] TOP = 2 * * 512 a, b = 1, 1 while FIB[- 1] < TOP: a, b = a + b, a FIB . append(a) def nearest_fibonacci(n): i = bisect(FIB, n) return min(FIB[i - 1: i + 1], key=lambda v: (abs(v - n), v))
Find Nearest Fibonacci Number
5ca22e6b86eed5002812061e
[ "Mathematics", "Algorithms" ]
https://www.codewars.com/kata/5ca22e6b86eed5002812061e
5 kyu
## Task You are given two positive integer numbers `a` and `b`. These numbers are being simultaneously decreased by 1 until the smaller one is 0. Sometimes during this process the greater number is going to be divisible (as in with no remainder) by the smaller one. Your task is to tell how many times (starting with `a` and `b`) this will be the case. ## Example ```python a = 3, b = 5 #start, 5 is not divisible by 3 a = 2, b = 4 #decreased by 1, 4 is divisible by 2 a = 1, b = 3 #decreased by 1, 3 is divisible by 1 a = 0, b = 2 #decreased by 1, the smaller number is 0, end The result should be 2 a = 8, b = 4 #start, 8 is divisible by 4 a = 7, b = 3 #decreased by 1, 7 is not divisible by 3 a = 6, b = 2 #decreased by 1, 6 is divisible by 2 a = 5, b = 1 #decreased by 1, 5 is divisible by 1 a = 4, b = 0 #decreased by 1, the smaller number is 0, end The result should be 3 ``` ## Details * Both numbers might be as big as `10^12` * `a` might equal `b` ### Acknowledgments Inspecting [@ChristianECooper][1]'s code in his [Beggar Thy Neighbour][2] kata helped me write test cases. Be sure to check out his [other katas][3]. [1]: https://www.codewars.com/users/ChristianECooper [2]: https://www.codewars.com/kata/58dbea57d6f8f53fec0000fb [3]: https://www.codewars.com/users/ChristianECooper/authored
reference
def how_many_times(a, b): if a > b: a, b = b, a if a <= 0: return - 1 if a == b: return a n = b - a return sum(1 + (x < n / x <= a) for x in range(1, min(a, int(n * * 0.5)) + 1) if not n % x)
Minus 1: is divisible?
5f845fcf00f3180023b7af0a
[ "Fundamentals", "Mathematics", "Algorithms", "Performance" ]
https://www.codewars.com/kata/5f845fcf00f3180023b7af0a
5 kyu
*Translations appreciated* # Overview Your task is to decode a qr code. You get the qr code as 2 dimensional array, filled with numbers. 1 is for a black field and 0 for a white field. It is always a qr code of version 1 (21*21), it is always using mask 0 ((x+y)%2), it is always using byte mode and it always has error correction level H (up to 30%). The qr code won't be positioned wrong and there won't be any squares for positioning exept the three big ones in the corners. You should return the message inside the qr code as string. The QR Code will always be valid and be of `version 1`, meaning the decoded message will never be more than 8 characters long. The way to decode a complete QR-code is explained below, but keep in mind that in this kata, you'll only have to decode the parts in green in the picture below: <img src="https://i.ibb.co/7RjZbXG/dcode-image-v3-v2.jpg" alt="dcode-image-v3-v2" border="0"> <br> # Input/ouput * Input: 2D array of `0` (white) and `1` (black) values * Output: the decoded message, according to the process described below. ```javascript const qrcode = [[ 1, 1, 1, 1, 1, 1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, 0, 0, 0, 0, 0, 0}, new [] {0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1}, new [] {0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1}, new [] {0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1}, new [] {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0}, new [] {1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0}, new [] {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0}, new [] {1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1}, new [] {1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0}, new [] {1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1}, new [] {1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0}, new [] {1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1}, new [] {1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0}, new [] {1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1} }; return "Hello"; ``` <br> # Decoding a QR-code Here comes the explaination on how to decode a qr code. You can skip it, if you already know how it works: ### Positioning information First of all we have to take a look at the big three positioning fields in the corners. <img src="https://i.ibb.co/99YtbCj/qrmatrixpkf2.jpg" alt="qrmatrixpkf2" border="0"> You can see on the image that these fields are connected. The fields are just there for the positioning and I told before that the qr code will be always positioned correctly so you can ignore them. ### Mask information The bits next to the positioning fields give us information about the mask and the error correction level the qr code uses. I wrote above that it is always mask 0 and always error correction level H, so we can also ignore that stuff. <img src="https://i.ibb.co/7jzjQy5/qrmatrixti2.jpg" alt="qrmatrixti2" border="0"> ### Reading information Now we start with the important stuff. Go through the qr code like the red arrow shows on this picture (btw I made it with paint so don't judge me) - We start in the lower right corner - Then we go one to the left - Then we go one up and one to the right - And so on just look the red arrow ___Important:___ Remember that everything inside the blue boxes has another purpose than encoding information, so don't forget to skip those parts. <img src="https://i.ibb.co/zsqr5JZ/dcode-image-v3.png" alt="dcode-image-v3" border="0"> In the image below, you may find the complete pattern to read information in a QR-code. But keep in mind you'll be handling only "QR-code version 1", so you don't need to read the full set of data (see <a href="https://i.ibb.co/7RjZbXG/dcode-image-v3-v2.jpg" target="_blank">picture at the top</a> if needed). <img src="https://i.ibb.co/rFk5Dc5/1920px-QR-Character-Placement-svg.png" alt="1920px-QR_Character_Placement.svg" border="0"> ### Decoding information We have to build a bit sequence now. In order to do that we will use mask 0 definition which is `((x+y)%2)==0`, where: - x and y are the indexes of our 2 dimensional array (0-based) - if the condition of our mask is true, we have to convert the pixel: black -> 0 and white -> 1 - A mask is used to prevent long sequences of identical bits so that a scanner can better recognize the code For each black field add 1 to our bit sequence and for each white field add 0 to our bit sequence, don't forget that many bits get converted because of mask 0. Let's do the first bits together: * We start with the first pixel (in the lower right corner, where also the red arrow begins) which is black, but we have to use mask because (20+20)%2 is 0, therefore we don't add 1 to our bit sequence but 0. * Next field is white. This time we don't use mask because (20+19)%2 isn't 0, so we add a 0 to our bit sequence. * Next field is black. This time we don't use mask because (19+20)%2 isn't 0, so we add a 1 to our bit sequence. Important (!): Since we're limiting ourselves to version 1, we have to continue that process only until our bit sequence is 76 long, because the input will never be longer than eight characters. At the end you get a bit sequence: ``` bits: 0100000000100100100001101001000011101100000100011110110000010001111011001111 legend: MMMMssssssss... - "M": mode bits (4 bits) - "s": size message bits (8 bits) - ...: message bits and error correction information ``` This bit sequence is representing the following information * First 4 bits show mode: `0100`. This isn't important for us, because I told you before that we will use always byte mode in this kata. * The following 8 bits show the length of the encoded word: `00000010`. This is the binary representation of number 2, so we know our word is 2 characters long. * The following bits are data bits followed by error correction bits (but you can ignore error correction bits, because there won't be any errors). We know our word is 2 chars long, so we take the next 16 bits (because 1 char=8 bits): - First group of 8 bits: `01001000`. This is `72` in decimal which is ascii value of `"H"`. - Second group of 8 bits: `01101001`. This is `105` in decimal which is ascii value of `"i"`. Since we don't handle in this kata error correction, we got our word/output: `"Hi"`. Good luck :)
algorithms
def scanner(qrc): bits = '' . join(str(qrc[x][y] ^ ((x + y) % 2 == 0)) for x, y in ticTocGen()) size = int(bits[4: 12], 2) return '' . join(chr(int(bits[i: i + 8], 2)) for i in range(12, 12 + 8 * size, 8)) def ticTocGen(): x, y, dx = 20, 20, - 1 while y > 13: yield from ((x, y - dy) for dy in range(2)) x += dx if x == 8 or x > 20: dx *= - 1 y -= 2 x = x == 8 and 9 or 20
Decode the QR-Code
5ef9c85dc41b4e000f9a645f
[ "Algorithms" ]
https://www.codewars.com/kata/5ef9c85dc41b4e000f9a645f
6 kyu
Two kingdoms are at war and, thanks to your codewarrior prowesses, you have been named general by one of the warring states. Your opponent's armies are larger than yours, but maybe you can reach a stalemate or even win the conflict if you are a good strategist. You control the **same number of armies as the rival state**, but theirs are generally larger. **You have to send a single army to fight each of your opponent's ones.** (It implies there will be as many battles as armies). There are no possible David-and-Goliath surprises : the outcome of a battle is always the victory of the larger army (or a standoff if both are of the same size). The winning side is the one which wins the most battles. The outcome can be a stalemate if both win the same number. You have to write a function that takes as input each side's armies as arrays of strictly positive integers which represent the armies' sizes. The function must return the strings `"Defeat"` , `"Stalemate"` or `"Victory"` depending on the outcome of the war for your side with an **optimal** strategy on your behalf. For example, if you have 3 armies of sizes `[1,4,1]` and the rival state has armies of sizes `[1,5,3]` , despite you having smaller forces on average, it is possible to reach a stalemate : ``` 1-1 : standoff 4-3 : victory for you 1-5 : victory for the opposing army ``` when the dust settles, you have won one battle, lost one, and one was indecisive so the result is `"Stalemate"`. ## More examples : * ``` [2, 4, 3, 1] versus [4, 5, 1, 2] ---> Victory ``` because it is possible to win by disposing your armies this way : ``` 2-1 4-4 3-2 1-5 ``` thus winning two battles, deadlocking one and losing one. * ``` [1, 2, 2, 1] versus [3, 1, 2, 3] ---> Defeat ``` because even with an optimal strategy it is not possible to win. The best you can do is one victory and one tie : ``` 1-3 2-1 2-2 1-3 ```
algorithms
def codewar_result(codewarrior, opponent): armies = sorted(codewarrior, reverse=True) opp = sorted(opponent, reverse=True) wins = 0 while opp: if max(armies) < max(opp): opp . remove(max(opp)) armies . remove(min(armies)) wins -= 1 elif max(armies) > min(opp): target = max(i for i in opp if i < max(armies)) optimal = min(i for i in armies if i > target) opp . remove(target) armies . remove(optimal) wins += 1 elif max(armies) == max(opp): opp . remove(max(opp)) armies . remove(max(armies)) if wins == 0: return 'Stalemate' elif wins > 0: return 'Victory' else: return 'Defeat'
Can you win the codewar ?
5e3f043faf934e0024a941d7
[ "Arrays", "Algorithms" ]
https://www.codewars.com/kata/5e3f043faf934e0024a941d7
6 kyu
According to ISO 8601, the first calendar week (1) starts with the week containing the first thursday in january. Every year consists of 52 calendar weeks (53 in case of a year starting on a Thursday or a leap year starting on a Wednesday). **Your task is** to calculate the calendar week (1-53) from a given date. For example, the calendar week for the date `2019-01-01` (string) should be 1 (int). Good luck 👍 See also [ISO week date](https://en.wikipedia.org/wiki/ISO_week_date) and [Week Number](https://en.wikipedia.org/wiki/Week#Week_numbering) on Wikipedia for further information about calendar weeks. On [whatweekisit.org](http://whatweekisit.org/) you may click through the calender and study calendar weeks in more depth. *heads-up:* imports like `require(xxx)` for JS have been disabled Thanks to @ZED.CWT, @Unnamed and @proxya for their feedback.
algorithms
from datetime import datetime def get_calendar_week(date_string): return datetime . strptime(date_string, "%Y-%m-%d"). isocalendar()[1]
Calendar Week
5c2bedd7eb9aa95abe14d0ed
[ "Date Time", "Algorithms" ]
https://www.codewars.com/kata/5c2bedd7eb9aa95abe14d0ed
6 kyu
<span style="color:orange">*For all those times when your mouth says the opposite of what your brain told it to say...*</span> # Kata Task In this Kata you will write a method to return what you **really** meant to say by negating certain words (adding or removing `n't`) The words to be negated are drawn from this pool: * are - aren't * can - can't * could - couldn't * did - didn't * do - don't * had - hadn't * has - hasn't * have - haven't * is - isn't * might - mightn't * must - mustn't * should - shouldn't * was - wasn't * were - weren't * would - wouldn't ## Input * `words` - these are the words your brain has trouble with (contains only lower case positive form of the word) * `speech` - what your mouth said ## Output * What you **meant** to say. This is the `speech` sentence, but with any of the `words` (both positive and negative forms) negated ## Notes * Case rules * when changing negative to positive the replacement word must be same case as the original * when changing positive to negative use `n't` (except if the original word (plus any 've part) was **entirely** uppercase, then use `N'T`) * Beware of the word `can` * Beware of punctuation * Beware of variations with an `'ve` suffix, such as *should've*, *would've*, *could've*, etc # Examples * `words` = ["can", "do", "have", "was", "would"] * `speech` * I do like pizza. ==> I <span style="color:red">don't</span> like pizza. * I haven't seen you wearing that hat before. ==> I <span style="color:red">have</span> seen you wearing that hat before. * I could see why you would say that. ==> I could see why you <span style="color:red">wouldn't</span> say that. * I didn't say it! It wasn't me! ==> I didn't say it! It <span style="color:red">was</span> me! * YES, WE CAN ==> YES, WE <span style="color:red">CAN'T</span> * Wouldn't you believe it? I can't! ==> <span style="color:red">Would</span> you believe it? I <span style="color:red">can</span>! * I must be more careful in future. ==> I must be more careful in future. * I don't see why it WOULD be them ==> I <span style="color:red">do</span> see why it <span style="color:red">WOULDN'T</span> be them <hr style="margin-top:50px;border:none;background-color:white;height:1px;"> <div style="color:orange"> Good Luck!</br> DM </div>
algorithms
import re def correct(m): w, n, v = m . groups() v = v or '' if n: return w + v nt = "N'T" if w . isupper() and (not v or v . isupper()) else "n't" return f" { w }{ nt [ w . lower () == 'can' :]}{ v } " def speech_correction(words, speech): return speech if not words else re . sub(rf"\b( { '|' . join ( words )} )((?<=can)'t|n't)?('ve)?\b", correct, speech, flags=re . I)
I said the word WOULD instead of WOULDN'T
5b4e9d82beb865d4150000b1
[ "Strings", "Algorithms" ]
https://www.codewars.com/kata/5b4e9d82beb865d4150000b1
6 kyu
We are given a certain number ```n``` and we do the product partitions of it. ```[59, 3, 2, 2, 2]``` is a product partition of ```1416``` because: ``` 59 * 3 * 2 * 2 * 2 = 1416 ``` We form a score, ```sc``` for each partition in the following way: - if ```d1, d2, ...., dk``` are the factors of ```n```, and ```f1, f2, ...., fk```, the corresponding frequencies for each factor, we calculate: <a href="http://imgur.com/B8d00BZ"><img src="http://i.imgur.com/B8d00BZ.png?1" title="source: imgur.com" /></a> Suposse that we have that ```n = 1416``` The product partitions of this number with a corresponding special score are as follows: ``` Product Partition Score(sc) [59, 3, 2, 2, 2] 350 # equals to: (59^1 + 3^1 + 2^3) * 5 [177, 2, 2, 2] 740 # equals to: (177^1 + 2^3) * 4 [118, 3, 2, 2] 500 [59, 6, 2, 2] 276 [354, 2, 2] 1074 [59, 4, 3, 2] 272 [236, 3, 2] 723 [177, 4, 2] 549 [118, 6, 2] 378 [59, 12, 2] 219 [708, 2] 1420 <---- maximum value [118, 4, 3] 375 [59, 8, 3] 210 [472, 3] 950 [59, 6, 4] 207 [354, 4] 716 [236, 6] 484 [177, 8] 370 [118, 12] 260 [59, 24] 166 <---- minimum value ``` So we need a function that may give us the product partition with maximum or minimum score. The function ```find_spec_prod_part()``` will receive two arguments: - an integer ```n, n > 0``` - a command as a string, one of the following ones: ```'max' or 'min'``` The function should output a list with two elements: the found product partition (as a list sorted in descendin order) with its corresponding score. ``` find_spec_prod_part(n, com) ---> [prod_partition, score] ``` Let'see some cases: ```python find_spec_prod_part(1416, 'max') == [[708, 2], 1420] find_spec_prod_part(1416, 'min') == [[59, 24], 166] ``` ```d findSpecProdPart(1416, "max") == tuple([708u, 2], 1420u) findSpecProdPart(1416, "min") == tuple([59u, 24], 166u) ``` ```rust find_spec_prod_part(1416, "max") == Some((vec![708, 2], 1420)) find_spec_prod_part(1416, "min") == Some((vec![59, 24], 166)) ``` ```julia find_spec_prod_part(1416, "max") == [[708, 2], 1420] find_spec_prod_part(1416, "min") == [[59, 24], 166] ``` The function should reject prime numbers: ```python find_spec_prod_part(10007 , 'max') == "It is a prime number" ``` ```rust find_spec_prod_part(10007 , "max") == None ``` ```d findSpecProdPart(10007 , "max") == tuple(new uint[](0), 0u) ``` ```julia find_spec_prod_part(10007 , "max") == [] ``` Enjoy it! Hint: In this kata, optimization is one of the purposes or tags. The algorithm to produce the product partition is a key factor in terms of speed. Your code will be tested for an ```n``` value up to ```500000```.
reference
from gmpy2 import is_prime from itertools import starmap from collections import Counter from operator import itemgetter, pow def score(L): return sum(starmap(pow, Counter(L). items())) * len(L) def find_spec_prod_part(n, com): def gen(x, d=2): if x == 1: yield [] for y in range(d, min(n, x + 1)): if x % y == 0: for res in gen(x / / y, y): yield res + [y] if is_prime(n): return "It is a prime number" return eval(com)(([x, score(x)] for x in gen(n)), key=itemgetter(1))
Find Product Partitions With Maximum or Minimum Score
571dd22c2b97f2ce400010d4
[ "Fundamentals", "Data Structures", "Algorithms", "Mathematics", "Logic" ]
https://www.codewars.com/kata/571dd22c2b97f2ce400010d4
4 kyu
You should have done Product Partitions I to do this second part. If you solved it, you should have notice that we try to obtain the multiplicative partitions with ```n ≤ 100 ```. In this kata we will have more challenging values, our ```n ≤ 10000```. So, we need a more optimized a faster code. We need the function ```prod_int_partII()``` that will give all the amount of different products, excepting the number itself multiplied by one. The function ```prod_int_partII()``` will receive two arguments, the number ```n``` for the one we have to obtain all the multiplicative partitions, and an integer s that determines the products that have an amount of factors equals to ```s```. The function will output a list with this structure: ```python [(1), (2), [(3)]] (1) Total amount of different products we can obtain, using the factors of n. (We do not consider the product n . 1) (2) Total amount of products that have an amount of factors equals to s. [(3)] A list of lists with each product represented with by a sorted list of the factors. All the product- lists should be sorted also. If we have only one product-list as a result, the function will give only the list and will not use the list of lists ``` Let's see some cases: ```python prod_int_partII(36, 3) == [8, 3, [[2, 2, 9], [2, 3, 6], [3, 3, 4]]] /// (1) ----> 8 # Amount of different products, they are: [2, 2, 3, 3], [2, 2, 9], [2, 3, 6], [2, 18], [3, 3, 4], [3, 12], [4, 9], [6, 6] (8 products) (2) ----> 3 # Amount of products with three factors (see them bellow) (3) ----> [[2, 2, 9], [2, 3, 6], [3, 3, 4]] # These are the products with 3 factors ``` ```python prod_int_partII(48, 5) == [11, 1, [2, 2, 2, 2, 3]] # Only one list. ``` Again consider that some numbers will not have multiplicative partitions. ```python prod_int_partII(37, 2) == [0, 0, []] ``` Happy coding!! (Recursion is advisable)
reference
def find_factors(nm): res, cur, lnm = [], 2, nm while lnm >= cur * * 2: if lnm % cur == 0: res . append(cur) lnm / /= cur else: cur += 1 return res + [lnm] * (lnm != nm) def prod_int_partII(n, s): fct = find_factors(n) tot, cur, stot, sarr = int(len(fct) > 0), {tuple(fct)}, 0, [] if s == len(fct): stot, sarr = tot, fct for k in range(len(fct) - 2): cset = set() for t in cur: for i, x in enumerate(t): for j, y in enumerate(t[i + 1:], i + 1): cset . add( tuple(sorted(t[: i] + t[i + 1: j] + t[j + 1:] + (t[i] * t[j],)))) cur = cset tot += len(cur) if k == len(fct) - s - 1: stot, sarr = len(cur), sorted(sorted(c) for c in cset) if len(cset) > 1 else sorted(cset . pop()) return [tot, stot, sarr]
Product Partitions II
5614adad2283aa822f0000b3
[ "Fundamentals", "Data Structures", "Mathematics", "Recursion", "Algorithms" ]
https://www.codewars.com/kata/5614adad2283aa822f0000b3
6 kyu
## Task Someone has used a simple substitution cipher to encrypt an extract from Conan Doyle's <a href="http://www.gutenberg.org/files/1661/1661-h/1661-h.htm">A Scandal in Bohemia</a>. Your task is to find the key they used to encrypt it. ## Specifications The key will be random. The key will work the same for uppercase and lowercase but punctuation and spaces will be left alone. The extract will be large (c.85% of the whole text). Input is the encrypted extract as a string (which you can see with `print(extract)`), output is the key as a string. ### What is a Simple Substitution Cipher? A <a href="https://en.wikipedia.org/wiki/Substitution_cipher#Simple_substitution"> simple substitution cipher</a> is a type of <a href="http://practicalcryptography.com/ciphers/monoalphabetic-substitution-category/"> substitution cipher</a> that uses a key 26 characters long which acts as a map. Let's look at an example with key = 'qwertyuiopasdfghjklzxcvbnm': ``` 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| key1: |q|w|e|r|t|y|u|i|o|p|a|s|d|f|g|h|j|k|l|z|x|c|v|b|n|m| ``` Using the aformentioned key = 'qwertyuiopasdfghjklzxcvbnm', we can see that 'a' gets mapped to 'q', 'b' to 'w', 'c' to 'e', 'd' to 'r', 'e' to 't', 'f' to 'y' ... 'y' to 'n', and finally 'z' to 'm'. The key must contain all letters a-z exaclty once. Let's see one more example with key='zyxwvutsrqponmlkjihgfedcba': ``` 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| key2: |z|y|x|w|v|u|t|s|r|q|p|o|n|m|l|k|j|i|h|g|f|e|d|c|b|a| ``` Now that we have a map for our letters we simply translate letter for letter. A capital will be translated like its lowercase counterpart, but will stay in uppercase. Spaces and punctuation will stay as is. The opening to A Tale of Two Cities: ``` It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair. ``` becomes: ``` Ol vqz lit wtzl gy lodtz, ol vqz lit vgkzl gy lodtz, ol vqz lit qut gy vozrgd, ol vqz lit qut gy yggsoziftzz, ol vqz lit thgei gy wtsoty, ol vqz lit thgei gy ofektrxsoln, ol vqz lit ztqzgf gy Souil, ol vqz lit ztqzgf gy Rqkaftzz, ol vqz lit zhkofu gy ight, ol vqz lit vofltk gy rtzhqok. ``` using key1 and: ``` Rh dzg hsv yvgh lu hrnvg, rh dzg hsv dligh lu hrnvg, rh dzg hsv ztv lu drgwln, rh dzg hsv ztv lu ullorgsmvgg, rh dzg hsv vklxs lu yvorvu, rh dzg hsv vklxs lu rmxivwforhb, rh dzg hsv gvzglm lu Ortsh, rh dzg hsv gvzglm lu Wzipmvgg, rh dzg hsv gkirmt lu slkv, rh dzg hsv drmhvi lu wvgkzri. ``` in key2. In the tests, the text will have no new line characters '\n'; this was just for illustrative purposes. The book is preloaded. It may be accessed as ```if:python `a_scandal_in_bohemia` ``` ```if:scala `Preloaded.aScandalInBohemia` ``` There are a set of brackets and an ampersand in the original text. They have been changed to commas and the word 'and' respectively to makes thing a little harder ;) You might want to have a go at <a href="https://www.codewars.com/kata/52eb114b2d55f0e69800078d">this cipher</a> first.
algorithms
from collections import Counter def order_by_frequency(text): frequencies = Counter(filter(str . islower, text . lower())) return sorted(frequencies, key=frequencies . get, reverse=True) def key(extract, ordered=order_by_frequency(a_scandal_in_bohemia)): table = dict(zip(order_by_frequency(extract), ordered)) return '' . join(sorted(table, key=table . get))
A Scandal in Bohemia
5f2dcbbd1b69a9000f225940
[ "Ciphers", "Cryptography", "Security", "Strings", "Algorithms" ]
https://www.codewars.com/kata/5f2dcbbd1b69a9000f225940
5 kyu
This is a sequel to [Solve the Grid! Binary Toggling Puzzle](https://www.codewars.com/kata/5bfc9bf3b20606b065000052). You are given a `N x N` grid of switches that are on (`1`) or off (`0`). The task is to activate all switches using a toggle operation. Executing a toggle operation at coordinates (`x`, `y`) will toggle all switches in the row `y` and column `x` (the origin is in the top left corner). Examples: ```python solve([ [1, 0, 1], [0, 0, 0], [1, 0, 1] ]) >>> [(1, 1)] ``` ```python solve([ [0, 1, 0], [1, 0, 0], [0, 0, 1] ]) >>> [(0, 0), (1, 1)] ``` ```python solve([[1, 0, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [1, 0, 1, 1, 1]]) >>> [(1, 3), (2, 1), (2, 2), (3, 1), (3, 2)] ``` You can solve some of the puzzles yourself in this [interactive version](https://openprocessing.org/sketch/1200708). [Here](https://openprocessing.org/sketch/1540470) you can also find an interactive version of the "complex example" test case. (Credits go to XRFXLP, thanks a lot!) - Puzzle sizes go up to 17 x 17 - Naive DFS or BFS will time out - Input is always a solvable 2D list. - If `N = 0`, return the empty list `[]` - Don't modify the input
algorithms
def solve(grid): n0 = len(grid) n = n0 & ~ 1 rs = [0] * n cs = [0] * n for ir in range(n): for ic in range(n): if grid[ir][ic]: rs[ir] ^= 1 cs[ic] ^= 1 res = [(ic, ir) for ir in range(n) for ic in range(n) if not rs[ir] ^ cs[ic] ^ grid[ir][ic]] if n0 % 2 == 1 and not grid[n][n]: res . append((n, n)) return res
Advanced binary toggling puzzle
6067346f6eeb07003fd82679
[ "Algorithms", "Puzzles", "Mathematics" ]
https://www.codewars.com/kata/6067346f6eeb07003fd82679
4 kyu
## Our Setup Alice and Bob work in an office. When the workload is light and the boss isn't looking, they play simple word games for fun. This is one of those days! ## Today's Game Alice found a little puzzle in the local newspaper and challenged Bob on how many ways it could be solved using two different words. Bob suggested the condition that letters can score different points. Of course, they would then soon both sneak away to write up an algo trying to be first to finish! ## The Puzzle This tiniest of crosswords is just a `2 x 2` grid with one square blocked: ``` < the 4 possible grids, shown here as tuples of 2 strings > ( '#_', ( '_#', ( '__', ( '__', '__' ) '__' ) '#_' ) '_#' ) ``` ## The Words There are `128` valid 2-letter words available to complete this puzzle: ```python "AA" "AB" "AD" "AE" "AG" "AH" "AI" "AL" "AM" "AN" "AR" "AS" "AT" "AW" "AX" "AY" "BA" "BE" "BI" "BO" "BY" "CH" "DA" "DE" "DI" "DO" "EA" "ED" "EE" "EF" "EH" "EL" "EM" "EN" "ER" "ES" "ET" "EW" "EX" "FA" "FE" "FY" "GI" "GO" "GU" "HA" "HE" "HI" "HM" "HO" "ID" "IF" "IN" "IO" "IS" "IT" "JA" "JO" "KA" "KI" "KO" "KY" "LA" "LI" "LO" "MA" "ME" "MI" "MM" "MO" "MU" "MY" "NA" "NE" "NI" "NO" "NU" "NY" "OB" "OD" "OE" "OF" "OH" "OI" "OK" "OM" "ON" "OO" "OP" "OR" "OS" "OU" "OW" "OX" "OY" "PA" "PE" "PI" "PO" "QI" "RE" "SH" "SI" "SO" "ST" "TA" "TE" "TI" "TO" "UG" "UH" "UM" "UN" "UP" "UR" "US" "UT" "WE" "WO" "XI" "XU" "YA" "YE" "YO" "YU" "ZA" "ZE" "ZO" ``` ## The Values The `26` alphabet letters are assigned these values for scoring solutions: ```python A B C D E F G H I J K L M 1 3 3 2 1 4 2 4 1 8 5 1 3 N O P Q R S T U V W X Y Z 1 1 3 10 1 1 1 1 4 4 8 4 10 ``` ## A Snag! One square has a letter in it! You must find words to work with this letter. ## Two Examples ``` puzzle: use'TO' use'DO' puzzle: use'ZA' nothing! # _ # _ # D _ # _ # ? # _ O T O T O Z _ Z A Z A one of many solutions no solution possible score: 5 points (no score) ``` ## Some Notes * each puzzle has `2` spaces, `1` block, `1` letter * underscores `_` represent spaces for squares * the hashtag `#` is the one blocked-out square * placement of blocked square can't be altered * the letter already written in can't be replaced * `across` is left to right, `down` is top to bottom * solution words overlap, thus share one letter * solution words must be two different words * all letters are uppercase and all input is valid ## Input You will be passed a (list) of `2` strings of `2` chars each representing the puzzle grid rows. The `words` and `values` (lists) will be available in your function scope. Consult examples below for data types in your language. ## Output The task is to return all valid _solutions_ for the given puzzle. A _solution_ has 3 elements: an `across` word, a `down` word, and a `score`. The words must be distinct and fit the given puzzle grid. The score is the sum of both letters in both words, so the shared letter is counted twice. The resulting _solutions_ should be sorted first from highest to lowest `score`, and then alphabetically beginning with the `across` word. As the first example shows, some `across` and `down` words can be reversed to form two distinct _solutions_. ```c typedef struct Puzzle_Solution_Data { char across[3]; char down[3]; unsigned score; } psd; const char *words[128]; // available 2-letter words const unsigned values[26]; // point values for letters void crossword_2x2(const char *puzzle[2], psd *solutions, size_t *n); // input: array of strings, psd array pointer, size pointer crossword_2x2({"#_", "_G"}, *solutions, *n); // sets *n to 2, assigns data to *solutions: {(psd){"AG", "UG", 6U}, (psd){"UG", "AG", 6U}}; crossword_2x2({"_V", "_#"}, *solutions, *n); // (*n stays at 0, no data assigned) crossword_2x2({"Q_", "#_"}, *solutions, *n); // sets *n to 6, assigns data to *solutions: {(psd){"QI", "IF", 16U}, (psd){"QI", "ID", 14U}, (psd){"QI", "IN", 13U}, (psd){"QI", "IO", 13U}, (psd){"QI", "IS", 13U}, (psd){"QI", "IT", 13U}}; ``` ```csharp words // an array of 128 available 2-letter words values // a dictionary of letters keyed to points public static List<object[]> Crossword2x2(string[] puzzle); crossword2x2({"#_", "_G"}); // input is an array of 2 strings // should return an array of object arrays: {new object[]{"AG", "UG", 6}, new object[]{"UG", "AG", 6}}; crossword2x2({"_V", "_#"}); // should return {}; crossword2x2({"Q_", "#_"}); // should return {new object[]{"QI", "IF", 16}, new object[]{"QI", "ID", 14}, new object[]{"QI", "IN", 13}, new object[]{"QI", "IO", 13}, new object[]{"QI", "IS", 13}, new object[]{"QI", "IT", 13}}; ``` ```java words // an array of 128 available 2-letter words values // a dictionary of letters keyed to points public static List<Object[]> crossword2x2(String[] puzzle); crossword2x2({"#_", "_G"}); // input is an array of 2 strings // should return an List of object arrays: {new Object[]{"AG", "UG", 6}, new Object[]{"UG", "AG", 6}}; crossword2x2({"_V", "_#"}); // should return {}; crossword2x2({"Q_", "#_"}); // should return {new Object[]{"QI", "IF", 16}, new Object[]{"QI", "ID", 14}, new Object[]{"QI", "IN", 13}, new Object[]{"QI", "IO", 13}, new Object[]{"QI", "IS", 13}, new Object[]{"QI", "IT", 13}}; ``` ```javascript words // an array of 128 available 2-letter words values // an object of letters keyed to points crossword2x2(['#_', '_G']) // input is an array of 2 strings // should return an array of arrays: [['AG', 'UG', 6], ['UG', 'AG', 6]] crossword2x2(['_V', '_#']) // should return [] crossword2x2(['Q_', '#_']) // should return [['QI', 'IF', 16], ['QI', 'ID', 14], ['QI', 'IN', 13], ['QI', 'IO', 13], ['QI', 'IS', 13], ['QI', 'IT', 13]] ``` ```python words # a tuple of 128 available 2-letter words values # a dictionary of letters keyed to points crossword_2x2(('#_', '_G')) # input is a tuple of 2 strings # should return a list of tuples: [('AG', 'UG', 6), ('UG', 'AG', 6)] crossword_2x2(('_V', '_#')) # should return [] crossword_2x2(('Q_', '#_')) # should return [('QI', 'IF', 16), ('QI', 'ID', 14), ('QI', 'IN', 13), ('QI', 'IO', 13), ('QI', 'IS', 13), ('QI', 'IT', 13)] ``` ## Enjoy! You may consider one of the following kata to solve next: * [Playing With Toy Blocks ~ Can you build a 4x4 square?](https://www.codewars.com/kata/5cab471da732b30018968071) * [Four Letter Words ~ Mutations](https://www.codewars.com/kata/5cb5eb1f03c3ff4778402099) * [Interlocking Binary Pairs](https://www.codewars.com/kata/628e3ee2e1daf90030239e8a) * [Is Sator Square?](https://www.codewars.com/kata/5cb7baa989b1c50014a53333)
algorithms
from collections import defaultdict WORDS = defaultdict(lambda: defaultdict(list)) for w in words: for i, c in enumerate(w): WORDS[c][i]. append(w) def crossword_2x2(puzzle): def count(a, b): return (a, b, sum(values[c] for c in a + b)) def hasHash(r): return '#' in r def hasLetter(r): return any(c . isalpha() for c in r) def findPos(pred): return [next(i for i, r in enumerate(arr) if pred(r)) for arr in (puzzle, zip(* puzzle))] (xH, yH), (xL, yL) = map(findPos, (hasHash, hasLetter)) cnds = WORDS[puzzle[xL][yL]] if xH != xL and yH != yL: genAcrossDown = ((a, b) for a in cnds[yL] for b in cnds[xL]) elif xH == xL: genAcrossDown = ((b, a) for a in cnds[xL] for b in WORDS[a[1 ^ xL]][yL]) else: genAcrossDown = ((a, b) for a in cnds[yL] for b in WORDS[a[1 ^ yL]][xL]) return sorted((count(a, b) for a, b in genAcrossDown if a != b), key=lambda x: (- x[- 1], x))
Crossword Puzzle! (2x2)
5c658c2dd1574532507da30b
[ "Puzzles", "Algorithms" ]
https://www.codewars.com/kata/5c658c2dd1574532507da30b
5 kyu
# Story John found a path to a treasure, and while searching for its precise location he wrote a list of directions using symbols `"^"`, `"v"`, `"<"`, `">"` which mean `north`, `east`, `west`, and `east` accordingly. On his way John had to try many different paths, sometimes walking in circles, and even missing the treasure completely before finally noticing it. ___ ## Task Simplify the list of directions written by John by eliminating any loops. **Note**: a loop is any sublist of directions which leads John to the coordinate he had already visited. ___ ## Examples ``` simplify("<>>") == ">" simplify("<^^>v<^^^") == "<^^^^" simplify("") == "" simplify("^<<v") == "^<<v" ``` ___ ## Simplification explanation 1) Let's say John starts at point `A` and goes to point `B`. 2) On his way he passes point `C`. 3) Later he returns to point `B` (remember that John may be going in circles sometimes). 4) The sublist of directions between the first and second visits of point `B` **SHOULD BE REMOVED**, as John doesn't progress by following those. 5) He starts walking around again, and passes through point `C`. 6) These directions **SHOULD NOT BE REMOVED** because after simplifying his path he arrives at point `C` for the first time! (Remember that John doesn't follow the directions he simplifies, so visiting it for the "first time" is hypothetical path, and visiting it for the "second time" is his real path; when hypothetical and real paths intersect, we ignore this fact.) ### Example ``` > > v ^ v > > C > D > > ^ ^ v ^ < B < < ^ A ``` John visits points `A -> B -> C -> D -> B -> C -> D`, realizes that `-> C -> D -> B` steps are meaningless and removes them, getting this path: `A -> B -> (*removed*) -> C -> D`. ``` ∙ ∙ ∙ ∙ ∙ > > C > D > > ^ ∙ ∙ ^ < B ∙ ∙ ^ A ``` Following the final, simplified route John visits points `C` and `D`, but for the first time, not the second (because we ignore the steps made on a hypothetical path), and he doesn't need to alter the directions list anymore.
algorithms
def simplify(p): new_p = [(0, 0)] new_str = '' x = 0 y = 0 for i in p: if i == '<': x -= 1 elif i == '>': x += 1 elif i == '^': y += 1 elif i == 'v': y -= 1 if (x, y) not in new_p: new_p . append((x, y)) new_str += i else: for j in new_p[:: - 1]: if j != (x, y): new_p . pop() new_str = new_str[: - 1] else: break return new_str
The simplest path
56bcafba66a2ab39e6001226
[ "Algorithms" ]
https://www.codewars.com/kata/56bcafba66a2ab39e6001226
6 kyu
An IPv6 address consists of eight parts of four hexadecimal digits, separated by colons (:), for example: ``` 1234:5678:90AB:CDEF:1234:5678:90AB:CDEF ``` As you can see, an IPv6 address is quite long. Luckily, there are a few things we can do to shorten such an address. Firstly, for each of the four-digit parts, we can remove any leading zeros. For example, ```001A``` becomes ```1A```, and ```0000``` simply becomes ```0```. An example of an IPv6 address with all leading zeros removed: ```53BF:009C:0000:0000:120A:09D5:000D:CD29``` becomes ```53BF:9C:0:0:120A:9D5:D:CD29``` This is already a lot shorter than the original address. But there is a second way we can shrink it even more. Any sequence of 4 (or a multiple of 4) zeros between two colons can be shortened to ```::```. For example, ```009C:0000:120A``` can be written as ```9C::120A```. Or an example with multiple consecutive quadruplets of zeros: ```009C:0000:0000:0000:120A``` becomes ```9C::120A```. This can happen only once in an IPv6 address, and it should shorten the longest sequence of zeros: ```1234:0000:5678:0000:0000:90AB:0000:CDEF``` is shortened to ```1234:0:5678::90AB:0:CDEF```. If there are multiple occurrences of sequences of zeros, only shorten the first occurrence: ```1111:0000:0000:2222:0000:0000:3333:4444``` is shortened to ```1111::2222:0:0:3333:4444```. You can figure out how many zeros were shortened by counting the remaining parts. In the previous example, there are 6 parts remaining (```1111```, ```2222```, ```0```, ```0```, ```3333``` and ```4444```), and since an IPv6 address is always 8 parts long, two parts of zeros were removed. Your job is to write the function ```shorten()```, which will receive a valid IPv6 address as input, and should return the shortened version as an output. Good luck!<br><br> If you liked this kata, check out its <a href='http://www.codewars.com/kata/parse-ipv6-address-1/python'>followup</a>, which also incorporates validation and converting from IPv4 to IPv6.
algorithms
def shorten(ip, i=7): ip = ":" + ":" . join([group . lstrip("0") or "0" for group in ip . split(":")]) length = len(ip) while i and len(ip) == length: ip = ip . replace(":0" * i, "::", 1) i -= 1 return ip[1:]. replace(":::", "::")
Shorten IPv6 Address
5735b2b413c205fe39000c68
[ "Algorithms" ]
https://www.codewars.com/kata/5735b2b413c205fe39000c68
6 kyu
In this Kata, we will be taking the first step in solving Nash Equilibria of 2 player games by learning to calculate the Expected Utility of a player in a game of Rock Paper Scissors given the Utilities of the game and the Pure/Mixed Strategy of each Player. Let's first define a few Game Theoretic Definitions: <a href="http://www.codecogs.com/eqnedit.php?latex=\bg_white&space;\fn_cs&space;S_{i}=" target="_blank"><img src="http://latex.codecogs.com/gif.latex?\bg_white&space;\fn_cs&space;S_{i}=" title="S_{i}=" /></a> finite set of actions or choices for player i. <a href="http://www.codecogs.com/eqnedit.php?latex=\bg_white&space;\fn_cs&space;A=&space;S_{1}x...xS_{n}" target="_blank"><img src="http://latex.codecogs.com/gif.latex?\bg_white&space;\fn_cs&space;A=&space;S_{1}x...xS_{n}" title="A= S_{1}x...xS_{n}" /></a> is the set of all possible combinations of actions of all players. Each possible combination of actions is called an action profile. <a href="http://www.codecogs.com/eqnedit.php?latex=\bg_white&space;\fn_cs&space;\sigma&space;_{i}(s)&space;=" target="_blank"><img src="http://latex.codecogs.com/gif.latex?\bg_white&space;\fn_cs&space;\sigma&space;_{i}(s)&space;=" title="\sigma _{i}(s) =" /></a> Probability player i chooses action <a href="http://www.codecogs.com/eqnedit.php?latex=\bg_white&space;\fn_cs&space;s&space;\epsilon&space;S_{i}" target="_blank"><img src="http://latex.codecogs.com/gif.latex?\bg_white&space;\fn_cs&space;s&space;\epsilon&space;S_{i}" title="s \epsilon S_{i}" /></a> <a href="http://www.codecogs.com/eqnedit.php?latex=\bg_white&space;\fn_cs&space;u&space;=" target="_blank"><img src="http://latex.codecogs.com/gif.latex?\bg_white&space;\fn_cs&space;u&space;=" title="u =" /></a> a function mapping each action profile to a vector of utilities for each player. We refer to player i's payoff as <a href="http://www.codecogs.com/eqnedit.php?latex=\bg_white&space;\fn_cs&space;u_{i}" target="_blank"><img src="http://latex.codecogs.com/gif.latex?\bg_white&space;\fn_cs&space;u_{i}" title="u_{i}" /></a> and by convention, <a href="http://www.codecogs.com/eqnedit.php?latex=\bg_white&space;\fn_cs&space;-i" target="_blank"><img src="http://latex.codecogs.com/gif.latex?\bg_white&space;\fn_cs&space;-i" title="-i" /></a> refers to player i's opponents. To compute the expected utility of the game for a player, sum over each action profile the product of each player's probability of playing their action in the action profile, times the player's utility for the action profile: <a href="http://www.codecogs.com/eqnedit.php?latex=\bg_white&space;\fn_cs&space;u_{i}(\sigma&space;_{i},\sigma&space;_{-i})=&space;\sum_{s\epsilon&space;S_{i}}^{s}\sum_{s'\epsilon&space;S_{-i}}^{s'}\sigma&space;_{i}(s)\sigma&space;_{-i}(s')u_{i}(s,s')" target="_blank"><img src="http://latex.codecogs.com/gif.latex?\bg_white&space;\fn_cs&space;u_{i}(\sigma&space;_{i},\sigma&space;_{-i})=&space;\sum_{s\epsilon&space;S_{i}}^{s}\sum_{s'\epsilon&space;S_{-i}}^{s'}\sigma&space;_{i}(s)\sigma&space;_{-i}(s')u_{i}(s,s')" title="u_{i}(\sigma _{i},\sigma _{-i})= \sum_{s\epsilon S_{i}}^{s}\sum_{s'\epsilon S_{-i}}^{s'}\sigma _{i}(s)\sigma _{-i}(s')u_{i}(s,s')" /></a> For example, in Rock-Paper-Scissors, one can represent the utility table as an n-dimensional table, where each dimension has rows/columns corresponding to a single player's actions, each table entry contains a vector of utilities (a.k.a, payoffs or rewards) for each player. The payoff table for Rock-Paper-Scissors is as follows: | R |P |S R| 0,0 |-1,1|1,-1 P|1,-1 | 0,0|-1,1 S|-1,1 |1,-1| 0,0 Which can be expressed in python as follows: ``` utilities = [[0,-1,1],[1,0,-1],[-1,1,0]] ``` If we take those utilities, along with an action profile of each player we can calculate the Expected Utility of Rock-Paper-Scissors for player i. ```python def expected_utility(p0, p1, utilities): '''returns expected Utility of player p0''' utilities = [[0,-1,1],[1,0,-1],[-1,1,0]] p0 = [1,0,0] p1 = [0,1,0] expected_utility(p0,p1,utilities) == -1 ``` ```javascript function expectedUtility(p0, p1, utilities): '''returns expected Utility of player p0''' utilities = [[0,-1,1],[1,0,-1],[-1,1,0]] p0 = [1,0,0] p1 = [0,1,0] expectedUtility(p0,p1,utilities) == -1 ``` The returned value should be rounded to 2 decimal places.
algorithms
def expected_utility(p0, p1, utilities): ln = len(p0) return round(sum(utilities[i][j] * p0[i] * p1[j] for i in range(ln) for j in range(ln)), 2)
Calculating Expected Utility
5543e329a69dcb81b9000111
[ "Algorithms" ]
https://www.codewars.com/kata/5543e329a69dcb81b9000111
6 kyu
Lately you've fallen in love with JSON, and have used it to template different classes. However you feel that doing it by hand is too slow, so you wanted to create a decorator that would do it auto-magically! ## Explanation Your task is to write a decorator that loads a given JSON file object and makes each key-value pair an attribute of the given class. ## Example Given the following data is written in the `/tmp/myClass.json` file: ``` { "foo": "bar", "an_int": 5, "this_kata_is_awesome": true } ``` Here's how you would use the decorator: ``` @jsonattr("/tmp/myClass.json") class MyClass: pass MyClass.foo == "bar" MyClass.an_int == 5 MyClass.this_kata_is_awesome == True ```
reference
import json def jsonattr(filepath): def decorate(cls): with open(filepath) as json_file: for name, value in json . load(json_file). items(): setattr(cls, name, value) return cls return decorate
JSON Class Decorator
55b0fb65e1227b17d60000dc
[ "Fundamentals", "Object-oriented Programming" ]
https://www.codewars.com/kata/55b0fb65e1227b17d60000dc
6 kyu
# YOUR MISSION An [octahedron](https://en.wikipedia.org/wiki/Octahedron) is an 8-sided polyhedron whose faces are triangles. Create a method that outputs a 3-dimensional array of an octahedron in which the height, width, and depth are equal to the provided integer `size`, which is equal to the length from one vertex to the opposite vertex on the octahedron. ## EXAMPLE ```java createOctahedron(7) {{ { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 } }, { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 1, 0, 0, 0 }, { 0, 0, 1, 1, 1, 0, 0 }, { 0, 0, 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 } }, { { 0, 0, 0, 0, 0, 0, 0 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 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]] ] ``` ```r create_octahedron(5) , , 1 [,1] [,2] [,3] [,4] [,5] [1,] 0 0 0 0 0 [2,] 0 0 0 0 0 [3,] 0 0 1 0 0 [4,] 0 0 0 0 0 [5,] 0 0 0 0 0 , , 2 [,1] [,2] [,3] [,4] [,5] [1,] 0 0 0 0 0 [2,] 0 0 1 0 0 [3,] 0 1 1 1 0 [4,] 0 0 1 0 0 [5,] 0 0 0 0 0 , , 3 [,1] [,2] [,3] [,4] [,5] [1,] 0 0 1 0 0 [2,] 0 1 1 1 0 [3,] 1 1 1 1 1 [4,] 0 1 1 1 0 [5,] 0 0 1 0 0 , , 4 [,1] [,2] [,3] [,4] [,5] [1,] 0 0 0 0 0 [2,] 0 0 1 0 0 [3,] 0 1 1 1 0 [4,] 0 0 1 0 0 [5,] 0 0 0 0 0 , , 5 [,1] [,2] [,3] [,4] [,5] [1,] 0 0 0 0 0 [2,] 0 0 0 0 0 [3,] 0 0 1 0 0 [4,] 0 0 0 0 0 [5,] 0 0 0 0 0 ``` where each 1 represents a cubic unit that the octahedron takes up and where 0 is a cubic unit of empty space. # NOTES - The method should return an empty array/list if either - The input size is even (because then it wouldn't be an octahedron. It'd be an irregular polyhedron with 26 sides) - if the input size is 0 or less - if input size is 1 (that's called a cube). - If there's any problems with this kata (*COUGH* [my last Kata](https://www.codewars.com/kata/5bf76f953efcee37e2000061) *COUGH*), I'll try to get them fixed in the evenings before 10pm.
algorithms
def create_octahedron(size): if size <= 1 or size % 2 == 0: return [] m = size / / 2 return [[[int(abs(x - m) + abs(y - m) + abs(z - m) <= m) for z in range(size)] for y in range(size)] for x in range(size)]
Blocky Octahedrons
5bfb0d9b392c5bf79a00015a
[ "Algorithms", "Geometry", "Algebra" ]
https://www.codewars.com/kata/5bfb0d9b392c5bf79a00015a
6 kyu
The [earth-mover's distance](https://en.wikipedia.org/wiki/Earth_mover's_distance) is a measure of the dissimilarity of two probability distributions. The unusual name comes from thinking of the probability attached to an outcome _x_ as a pile of dirt located at _x_. The two probability distributions are then regarded as two different ways of piling up a fixed amount of dirt over a region of space. ![Piles of dirt](https://stat.auckland.ac.nz/~geoff/codewars/emd-graphic-1.png) The earth-mover's distance is the minimum amount of work needed to turn one distribution into the other. The work done to move dirt is the amount of dirt multiplied by the distance it is moved. *Example.* Consider the two probability distributions depicted below. ![Probability distributions](https://stat.auckland.ac.nz/~geoff/codewars/emd-graphic-2.png) The first one is the distribution of results from throwing a die with six sides labelled 1,2,2,3,3, and 5. The second distribution corresponds to labelling the sides 2,3,4,4,5, and 5. To turn the first distribution into the second, you could * Move all the probability (1/6) from 1 to 2; * Move 2/6 probability from 2 to 4; and * Move 1/6 probability from 3 to 5. The work required to do this is (1/6) * (2-1) + (2/6) * (4-2) + (1/6) * (5-3) = 7/6. There are other ways of doing it, but they all require an amount of work at least 7/6. Therefore, the earth-mover's distance between these two distributions is 7/6. The concept generalizes to probability distributions in more than one dimension, and to continuous distributions of probability, but for this kata we'll limit ourselves to discrete distributions on the line. That is, any distribution can be specified by an array of possible values ```x``` and another array ```px``` giving the probabilities attached to those values. The function you need to write takes a probability distribution specified by arrays ```x``` and ```px```, and another similarly specified by arrays ```y``` and ```py```. It should compute and return the earth-mover's distance between them. **Notes.** **1.** All the numbers in the test cases are chosen to be representable in binary floating-point with precision to spare (e.g. 1.5 or 0.375, but not 0.1 or 1.7). This means the test suite can (and does) reasonably expect the answers to be computed exactly, without floating-point round-off error. **2.** Most of the test cases are small, but there are some larger examples with up to 20000 possible values in each of the distributions -- so you need to consider how your code will handle problems of that size.
reference
from itertools import accumulate def earth_movers_distance(x, px, y, py): values, dx, dy = sorted(set(x + y)), dict(zip(x, px)), dict(zip(y, py)) dist = (b - a for a, b in zip(values, values[1:])) diff = accumulate(dy . get(n, 0) - dx . get(n, 0) for n in values) return sum(d * abs(n) for d, n in zip(dist, diff))
Earth-mover's distance
58b34b2951ccdb84f2000093
[ "Fundamentals", "Algorithms", "Mathematics", "Arrays" ]
https://www.codewars.com/kata/58b34b2951ccdb84f2000093
6 kyu
### Vaccinations for children under 5 You have been put in charge of administrating vaccinations for children in your local area. Write a function that will generate a list of vaccines for each child presented for vaccination, based on the child's age and vaccination history, and the month of the year. #### The function takes three parameters: age, status and month - The parameter 'age' will be given in weeks up to 16 weeks, and thereafter in months. You can assume that children presented will be scheduled for vaccination (eg '16 weeks', '12 months' etc). - The parameter 'status' indicates if the child has missed a scheduled vaccination, and the argument will be a string that says 'up-to-date', or a scheduled stage (eg '8 weeks') that has been missed, in which case you need to add any missing shots to the list. Only one missed vaccination stage will be passed in per function call. - If the month is 'september', 'october' or 'november' add 'offer fluVaccine' to the list. - Make sure there are no duplicates in the returned list, and sort it alphabetically. #### Example input and output ~~~~ input ('12 weeks', 'up-to-date', 'december') output ['fiveInOne', 'rotavirus'] input ('12 months', '16 weeks', 'june') output ['fiveInOne', 'hibMenC', 'measlesMumpsRubella', 'meningitisB', 'pneumococcal'] input ('40 months', '12 months', 'october') output ['hibMenC', 'measlesMumpsRubella', 'meningitisB', 'offer fluVaccine', 'preSchoolBooster'] ~~~~ #### To save you typing it up, here is the vaccinations list ~~~~ fiveInOne : ['8 weeks', '12 weeks', '16 weeks'], //Protects against: diphtheria, tetanus, whooping cough, polio and Hib (Haemophilus influenzae type b) pneumococcal : ['8 weeks', '16 weeks'], //Protects against: some types of pneumococcal infection rotavirus : ['8 weeks', '12 weeks'], //Protects against: rotavirus infection, a common cause of childhood diarrhoea and sickness meningitisB : ['8 weeks', '16 weeks', '12 months'], //Protects against: meningitis caused by meningococcal type B bacteria hibMenC : ['12 months'], //Protects against: Haemophilus influenzae type b (Hib), meningitis caused by meningococcal group C bacteria measlesMumpsRubella : ['12 months', '40 months'], //Protects against: measles, mumps and rubella fluVaccine : ['september','october','november'], //Given at: annually in Sept/Oct preSchoolBooster : ['40 months'] //Protects against: diphtheria, tetanus, whooping cough and polio ~~~~
reference
from itertools import chain TOME = { '8 weeks': ['fiveInOne', 'pneumococcal', 'rotavirus', 'meningitisB'], '12 weeks': ['fiveInOne', 'rotavirus'], '16 weeks': ['fiveInOne', 'pneumococcal', 'meningitisB'], '12 months': ['meningitisB', 'hibMenC', 'measlesMumpsRubella'], '40 months': ['measlesMumpsRubella', 'preSchoolBooster'], 'september': ['offer fluVaccine'], 'october': ['offer fluVaccine'], 'november': ['offer fluVaccine'], } def vaccine_list(* args): return sorted(set(chain . from_iterable( TOME . get(s, ()) for s in args )))
VaccineNation
577d0a117a3dbd36170001c2
[ "Arrays", "Sorting", "Fundamentals" ]
https://www.codewars.com/kata/577d0a117a3dbd36170001c2
6 kyu
**See Also** * [Traffic Lights - one car](.) * [Traffic Lights - multiple cars](https://www.codewars.com/kata/5d230e119dd9860028167fa5) --- # Overview A character string represents a city road. Cars travel on the road obeying the traffic lights.. Legend: * `.` = Road * `C` = Car * `G` = <span style='color:black;background:green'>GREEN</span> traffic light * `O` = <span style='color:black;background:orange'>ORANGE</span> traffic light * `R` = <span style='color:black;background:red'>RED</span> traffic light Something like this: <span style='font-family:monospace;font-size:30px;background:black;'> C...<span style='background:red;'>R</span>............<span style='background:green;'>G</span>...... </span><p/> # Rules ## Simulation At each iteration: 1. the lights change, according to the traffic light rules... then 2. the car moves, obeying the car rules ## Traffic Light Rules Traffic lights change colour as follows: * <span style='color:black;background:green'>GREEN</span> for `5` time units... then * <span style='color:black;background:orange'>ORANGE</span> for `1` time unit... then * <span style='color:black;background:red'>RED</span> for `5` time units.... * ... and repeat the cycle ## Car Rules * Cars travel left to right on the road, moving 1 character position per time unit * Cars can move freely until they come to a traffic light. Then: * if the light is <span style='color:black;background:green'>GREEN</span> they can move forward (temporarily occupying the same cell as the light) * if the light is <span style='color:black;background:orange'>ORANGE</span> then they must stop (if they have already entered the intersection they can continue through) * if the light is <span style='color:black;background:red'>RED</span> the car must stop until the light turns <span style='color:black;background:green'>GREEN</span> again # Kata Task Given the initial state of the road, return the states for all iterations of the simiulation. ## Input * `road` = the road array * `n` = how many time units to simulate (n >= 0) ## Output * An array containing the road states at every iteration (including the initial state) * Note: If a car occupies the same position as a traffic light then show only the car ## Notes * There is only one car * For the initial road state * the car is always at the first character position * traffic lights are either <span style='color:black;background:green'>GREEN</span> or <span style='color:black;background:red'>RED</span>, and are at the beginning of their countdown cycles * There are no reaction delays - when the lights change the car drivers will react immediately! * If the car goes off the end of the road it just disappears from view * There will always be some road between adjacent traffic lights # Example Run simulation for 10 time units **Input** * `road = "C...R............G......"` * `n = 10` **Result** ```java [ "C...R............G......", // 0 initial state as passed ".C..R............G......", // 1 "..C.R............G......", // 2 "...CR............G......", // 3 "...CR............G......", // 4 "....C............O......", // 5 show the car, not the light "....GC...........R......", // 6 "....G.C..........R......", // 7 "....G..C.........R......", // 8 "....G...C........R......", // 9 "....O....C.......R......" // 10 ] ``` --- Good luck! DM
algorithms
def traffic_lights(road, n): lightsIdx = [(i, 6 * (c != 'G')) for i, c in enumerate(road) if c in 'RG'] car, ref = road . find('C'), road . replace('C', '.') mut, out = list(ref), [road] for turn in range(1, n + 1): for i, delta in lightsIdx: # Update all lights state = (delta + turn) % 11 mut[i] = 'G' if state < 5 else 'O' if state == 5 else 'R' # Move the car if possible (even if outside of the road) car += car + 1 >= len(road) or mut[car + 1] in '.G' if car < len(road): # Update, archive, then restore the road state old, mut[car] = mut[car], 'C' out . append('' . join(mut)) if car < len(road): mut[car] = old return out
Traffic Lights - one car
5d0ae91acac0a50232e8a547
[ "Algorithms" ]
https://www.codewars.com/kata/5d0ae91acac0a50232e8a547
6 kyu
In this Kata, you will be given a number `n` (`n > 0`) and your task will be to return the smallest square number `N` (`N > 0`) such that `n + N` is also a perfect square. If there is no answer, return `-1` (`nil` in Clojure, `Nothing` in Haskell, `None` in Rust). ```clojure solve 13 = 36 ; because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49 solve 3 = 1 ; 3 + 1 = 4, a perfect square solve 12 = 4 ; 12 + 4 = 16, a perfect square solve 9 = 16 solve 4 = nil ``` ```csharp solve(13) = 36 //because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49 solve(3) = 1 // 3 + 1 = 4, a perfect square solve(12) = 4 // 12 + 4 = 16, a perfect square solve(9) = 16 solve(4) = -1 ``` ```cpp solve(13) = 36 //because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49 solve(3) = 1 // 3 + 1 = 4, a perfect square solve(12) = 4 // 12 + 4 = 16, a perfect square solve(9) = 16 solve(4) = -1 ``` ```rust solve(13) = 36 //because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49 solve(3) = Some(1) // 3 + 1 = 4, a perfect square solve(12) = Some(4) // 12 + 4 = 16, a perfect square solve(9) = Some(16) solve(4) = None ``` ```haskell solve 13 = Just 36 -- because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49 solve 3 = Just 1 -- 3 + 1 = 4, a perfect square solve 12 = Just 4 -- 12 + 4 = 16, a perfect square solve 9 = Just 16 solve 4 = Nothing ``` ```elixir solve(13) = 36 # because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49 solve(3) = 1 # 3 + 1 = 4, a perfect square solve(12) = 4 # 12 + 4 = 16, a perfect square solve(9) = 16 solve(4) = -1 ``` ```python solve(13) = 36 # because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49 solve(3) = 1 # 3 + 1 = 4, a perfect square solve(12) = 4 # 12 + 4 = 16, a perfect square solve(9) = 16 solve(4) = -1 ``` ```ruby solve(13) = 36 # because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49 solve(3) = 1 # 3 + 1 = 4, a perfect square solve(12) = 4 # 12 + 4 = 16, a perfect square solve(9) = 16 solve(4) = -1 ``` ```javascript solve(13) = 36 //because 36 is the smallest perfect square that can be added to 13 to form a perfect square => 13 + 36 = 49 solve(3) = 1 // 3 + 1 = 4, a perfect square solve(12) = 4 // 12 + 4 = 16, a perfect square solve(9) = 16 solve(4) = -1 ``` More examples in test cases. Good luck!
algorithms
def solve(n): for i in range(int(n * * 0.5), 0, - 1): x = n - i * * 2 if x > 0 and x % (2 * i) == 0: return ((n - i * * 2) / / (2 * i)) * * 2 return - 1
Simple square numbers
5edc8c53d7cede0032eb6029
[ "Algorithms" ]
https://www.codewars.com/kata/5edc8c53d7cede0032eb6029
6 kyu
[Sharkovsky's Theorem](https://en.wikipedia.org/wiki/Sharkovskii%27s_theorem) involves the following ordering of the natural numbers: ```math 3 ≺ 5 ≺ 7 ≺ 9 ≺ ... \\ ≺ 2 · 3 ≺ 2 · 5 ≺ 2 · 7 ≺ 2 · 9 ≺ ... \\ ≺ 2^n · 3 ≺ 2^n · 5 ≺ 2^n · 7 ≺ 2^n · 9 ≺ ... \\ ≺ 2^{n+1} · 3 ≺ 2^{n+1} · 5 ≺ 2^{n+1} · 7 ≺ 2^{n+1} · 9 ≺ ... \\ ≺ 2^n ≺ 2^{n-1} ≺ 2^{n-2} ≺ 2^{n-3} ≺ ... \\ < 8 ≺ 4 ≺ 2 ≺ 1 \\ ``` Your task is to complete the function which returns `true` if `$a≺b$` according to this ordering, and `false` otherwise. You may assume both `$a$` and `$b$` are non-zero positive integers.
algorithms
def sharkovsky(a, b): return f(a) < f(b) def f(n, p=0): while n % 2 == 0: n >>= 1 p += 1 return n == 1, p * (- 1) * * (n == 1), n
Sharkovsky's Theorem
5f579a3b34d5ad002819eb9e
[ "Mathematics", "Algorithms" ]
https://www.codewars.com/kata/5f579a3b34d5ad002819eb9e
6 kyu
_Yet another easy kata!_ ## Task: You are given a word `target` and list of sorted(by length(increasing), number of upper case letters(decreasing), natural order) unique words `words` which always contains `target`, your task is to find the index(0 based) of `target` in `words`,which would always be in the list. --- ## Examples: ```python words = ['JaCk', 'Jack', 'jack', 'jackk', 'COdewars', 'codeWars', 'abcdefgh', 'codewars'] ''' (list is sorted by length(small to big), then by number of uppercase letters(maximum to minimum) and then by natural order) ''' target = 'codewars' #result should be 7 #Another example: words = ['cP', 'rE', 'sZ', 'am', 'bt', 'ev', 'hq', 'rx', 'yi', 'akC', 'nrcVpx', 'iKMVqsj'] target = 'akC' #result should be 9 ``` --- ## Constraints: * python - 4 < len(words) <= 200000 - 1 < len(search) <= 10 - Number of random tests are around 6000. - Reference solution passes in 8s. * Javascript - Your solution must pass in less than `ref.solution+10ms` speed. - This is because generating long list of unique words in js is slow. - If you think you've got an correct approach and timing test is not passing then submit again. ---
reference
def keyer(w): return (len(w), - sum(map(str . isupper, w)), w) def index_of(words, target): def cmp(i, base=keyer(target)): o = keyer(words[i]) return (o > base) - (o < base) l, h = 0, len(words) while l < h: m = h + l >> 1 v = cmp(m) if not v: return m if v < 0: l = m else: h = m
Word search
5f05e334a0a6950011e72a3a
[ "Fundamentals" ]
https://www.codewars.com/kata/5f05e334a0a6950011e72a3a
6 kyu
In this Kata you will be given position of King `K` and Bishop `B` as strings on chess board using standard chess notation. Your task is to return a list of positions at which Rook would pin the Bishop to the King. > What is pin? https://en.wikipedia.org/wiki/Pin_(chess) > What is standard chess notation? https://en.wikipedia.org/wiki/Algebraic_notation_(chess) ### Example: ### ```python Input = 'Kb5', 'Be5' Output = ['Rf5', 'Rg5', 'Rh5'] ``` <svg width="450.00000000000006" height="450.00000000000006" xmlns="http://www.w3.org/2000/svg"> <g> <title>background</title> </g> <g> <title>Layer 1</title> <rect y="19.28571" fill="#769656" stroke-width="0" x="75" width="50" height="50" id="svg_1" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="25" y="19.28571" width="50" height="50" id="svg_2" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="125" y="19.28571" width="50" height="50" id="svg_4" stroke="#fff"/> <rect y="19.28571" fill="#769656" stroke-width="0" x="275" width="50" height="50" id="svg_3" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="225" y="19.28571" width="50" height="50" id="svg_6" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="325" y="19.28571" width="50" height="50" id="svg_7" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="175" y="19.28571" width="50" height="50" id="svg_8" stroke="#fff"/> <rect y="69.28572" fill="#769656" stroke-width="0" x="125" width="50" height="50" id="svg_9" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="75" y="69.28572" width="50" height="50" id="svg_10" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="175" y="69.28572" width="50" height="50" id="svg_11" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="25" y="69.28572" width="50" height="50" id="svg_12" stroke="#fff"/> <rect y="69.28572" fill="#769656" stroke-width="0" x="325.00001" width="50" height="50" id="svg_13" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="275.00001" y="69.28572" width="50" height="50" id="svg_14" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="375.00001" y="69.28572" width="50" height="50" id="svg_15" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="225.00001" y="69.28572" width="50" height="50" id="svg_16" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="375" y="19.28571" width="50" height="50" id="svg_17" stroke="#fff"/> <rect y="119.28572" fill="#769656" stroke-width="0" x="75" width="50" height="50" id="svg_18" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="25" y="119.28572" width="50" height="50" id="svg_19" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="125" y="119.28572" width="50" height="50" id="svg_20" stroke="#fff"/> <rect y="119.28572" fill="#769656" stroke-width="0" x="275" width="50" height="50" id="svg_21" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="225" y="119.28572" width="50" height="50" id="svg_22" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="325" y="119.28572" width="50" height="50" id="svg_23" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="175" y="119.28572" width="50" height="50" id="svg_24" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="375" y="119.28572" width="50" height="50" id="svg_25" stroke="#fff"/> <rect y="169.28572" fill="#769656" stroke-width="0" x="125" width="50" height="50" id="svg_26" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="75" y="169.28572" width="50" height="50" id="svg_27" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="175" y="169.28572" width="50" height="50" id="svg_28" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="25" y="169.28572" width="50" height="50" id="svg_29" stroke="#fff"/> <rect y="169.28572" fill="#769656" stroke-width="0" x="325.00001" width="50" height="50" id="svg_30" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="275.00001" y="169.28572" width="50" height="50" id="svg_31" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="375.00001" y="169.28572" width="50" height="50" id="svg_32" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="225.00001" y="169.28572" width="50" height="50" id="svg_33" stroke="#fff"/> <rect y="219.28572" fill="#769656" stroke-width="0" x="75" width="50" height="50" id="svg_34" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="25" y="219.28572" width="50" height="50" id="svg_35" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="125" y="219.28572" width="50" height="50" id="svg_36" stroke="#fff"/> <rect y="219.28572" fill="#769656" stroke-width="0" x="275" width="50" height="50" id="svg_37" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="225" y="219.28572" width="50" height="50" id="svg_38" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="325" y="219.28572" width="50" height="50" id="svg_39" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="175" y="219.28572" width="50" height="50" id="svg_40" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="375" y="219.28572" width="50" height="50" id="svg_41" stroke="#fff"/> <rect y="269.28572" fill="#769656" stroke-width="0" x="125" width="50" height="50" id="svg_42" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="75" y="269.28572" width="50" height="50" id="svg_43" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="175" y="269.28572" width="50" height="50" id="svg_44" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="25" y="269.28572" width="50" height="50" id="svg_45" stroke="#fff"/> <rect y="269.28572" fill="#769656" stroke-width="0" x="325.00001" width="50" height="50" id="svg_46" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="275.00001" y="269.28572" width="50" height="50" id="svg_47" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="375.00001" y="269.28572" width="50" height="50" id="svg_48" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="225.00001" y="269.28572" width="50" height="50" id="svg_49" stroke="#fff"/> <rect y="319.28572" fill="#769656" stroke-width="0" x="75" width="50" height="50" id="svg_50" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="25" y="319.28572" width="50" height="50" id="svg_51" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="125" y="319.28572" width="50" height="50" id="svg_52" stroke="#fff"/> <rect y="319.28572" fill="#769656" stroke-width="0" x="275" width="50" height="50" id="svg_53" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="225" y="319.28572" width="50" height="50" id="svg_54" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="325" y="319.28572" width="50" height="50" id="svg_55" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="175" y="319.28572" width="50" height="50" id="svg_56" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="375" y="319.28572" width="50" height="50" id="svg_57" stroke="#fff"/> <rect y="369.28572" fill="#769656" stroke-width="0" x="125" width="50" height="50" id="svg_58" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="75" y="369.28572" width="50" height="50" id="svg_59" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="175" y="369.28572" width="50" height="50" id="svg_60" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="25" y="369.28572" width="50" height="50" id="svg_61" stroke="#fff"/> <rect y="369.28572" fill="#769656" stroke-width="0" x="325.00001" width="50" height="50" id="svg_62" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="275.00001" y="369.28572" width="50" height="50" id="svg_63" stroke="#fff"/> <rect fill="#eeeed2" stroke-width="0" x="375.00001" y="369.28572" width="50" height="50" id="svg_64" stroke="#fff"/> <rect fill="#769656" stroke-width="0" x="225.00001" y="369.28572" width="50" height="50" id="svg_65" stroke="#fff"/> <text style="cursor: move;" xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_77" y="50.24469" x="5.0664" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">8</text> <text style="cursor: move;" stroke="#fff" xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_79" y="100.31234" x="5.0664" fill-opacity="null" stroke-opacity="null" stroke-width="0" fill="#769656">7</text> <text style="cursor: move;" xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_80" y="149.87523" x="4.52625" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">6</text> <text style="cursor: move;" xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_81" y="200.44539" x="5.02876" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">5</text> <text style="cursor: move;" xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_82" y="250" x="5" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">4</text> <text style="cursor: move;" xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_83" y="300" x="5" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">3</text> <text style="cursor: move;" xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_84" y="350" x="5" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">2</text> <text style="cursor: move;" xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_85" y="400" x="5" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">1</text> <text xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_88" y="440.70364" x="39.57281" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">a</text> <text xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_90" y="440.51256" x="90" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">b</text> <text xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_91" y="440.51256" x="140" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">c</text> <text xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_92" y="440.51256" x="190" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">d</text> <text xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_94" y="440.51256" x="240" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">e</text> <text xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_95" y="440.51256" x="290" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">f</text> <text xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_96" y="440.51256" x="340" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">g</text> <text xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_97" y="440.51256" x="390" fill-opacity="null" stroke-opacity="null" stroke-width="0" stroke="#fff" fill="#769656">h</text> <path stroke="#fff" id="svg_98" d="m89.45071,215.56146c-1.1726,-1.43003 1.83669,-1.4683 1.36391,-3.05352c0.86439,-2.10062 3.1119,-3.37212 3.44288,-5.75914c-0.91154,-0.66343 -1.4358,-2.26789 0.30327,-2.0774c1.27533,-1.00286 1.11594,-3.0551 1.49947,-4.56114c0.35928,-2.43079 0.44064,-4.89109 0.59496,-7.34185c-1.47563,-0.1184 -2.98777,-0.03593 -4.42559,-0.43094c0.04136,-1.62986 2.96698,-1.00447 3.10014,-2.54244c2.1272,-0.04016 0.11782,-3.35934 -0.74845,-4.15125c-1.10883,-1.33589 -1.84736,-3.44475 -1.00442,-5.09455c1.20568,-0.83688 3.93183,-0.32747 3.80861,-2.52675c-0.81997,-0.48828 -1.86104,-0.1782 -2.78006,-0.26456c0.05652,-1.02553 0.11303,-2.05105 0.16955,-3.07658c1.2154,-0.09766 2.43079,-0.19533 3.64619,-0.29301c-0.61692,-0.66982 -1.5402,-1.16277 -1.77125,-2.11027c0.78586,-1.34957 2.67985,-1.23044 4.03668,-1.21768c1.31937,-0.09507 3.7249,0.8243 1.92652,2.30514c-0.14576,0.36365 -1.56434,1.26788 -0.68768,1.1693c1.12246,0 2.24492,0 3.36738,0c-0.00323,1.00255 -0.02902,2.01505 0.19635,2.99617c-0.85681,0.6666 -3.63521,-0.56942 -2.84411,1.48738c0.89077,0.85993 2.25503,0.83723 3.38485,1.21595c0.65901,0.06878 1.18325,0.24818 0.94577,1.05292c0.12387,1.49412 -0.23698,2.99711 -1.22006,4.13131c-0.69591,1.18349 -2.25891,2.66509 -1.79621,4.035c0.87541,-0.14887 1.57863,0.45161 0.87942,1.1269c0.71755,0.55502 3.2443,0.42792 2.6978,1.81745c-1.28018,0.4427 -2.65542,0.25827 -3.9836,0.30345c0.35364,3.7929 0.84261,7.58616 1.65966,11.30039c0.47739,0.82418 2.37375,1.45763 0.81743,2.53209c-0.58082,2.00094 1.27435,3.49916 2.43947,4.78341c1.28104,1.00232 0.65951,3.01906 2.4718,3.3407c1.42726,1.44437 -1.95953,1.40591 -2.82905,1.40905c-5.75633,0.06484 -11.51887,0.15556 -17.27295,-0.03821c-0.47104,-0.0621 -1.053,-0.0479 -1.38869,-0.46732l0,0l0.00001,0.00001l0,-0.00001z" fill="#455634"/> <path stroke="#fff" id="svg_99" d="m239.24627,214.8217c0.05227,-1.34269 2.42351,-0.68076 1.11809,-1.98887c0.43544,-1.61361 1.78753,-2.68824 2.60478,-4.07243c0.6265,-1.17839 2.03775,-2.59849 1.35535,-4.05549c-1.25323,-0.7636 -0.89759,-2.46145 0.63528,-2.08856c0.9857,-1.03716 1.05357,-2.76964 1.38711,-4.18182c0.30275,-1.69021 0.48802,-3.41104 0.4397,-5.13792c-1.79678,0.005 -3.62733,-0.09321 -5.36025,-0.64915c0.33569,-1.53149 2.4994,-1.20236 3.38591,-2.14319c-0.82373,-0.84516 1.6653,-0.76064 1.01401,-2.09739c-0.04469,-1.53091 -1.10187,-1.97391 -1.9488,-3.09012c-1.13145,-1.74428 0.64239,-3.48712 1.62757,-4.66636c1.09813,-1.28165 2.35407,-2.64719 2.69019,-4.45994c-0.45222,-0.42393 -1.48524,-1.03093 -0.43115,-1.61046c1.43963,-0.27843 2.97547,-0.31235 4.38636,0.14441c0.93648,1.04097 -1.42938,1.09774 -0.41145,2.41025c1.20693,1.65002 -0.42029,2.50156 -1.38105,3.45534c-0.55923,0.80592 -2.22835,1.86874 -1.94118,2.70409c1.63416,-0.065 2.58634,-1.86981 3.75197,-2.93831c1.27849,-1.87081 2.51533,1.15238 3.33288,2.17973c1.00717,1.55697 0.31231,3.64959 -1.20475,4.31826c-0.7524,0.88398 -1.25197,3.40196 0.54834,3.02709c1.0455,0.43356 -1.02195,0.48027 0.16487,0.88107c0.7887,0.34552 3.86484,1.13524 2.17025,2.19443c-1.43828,0.37092 -2.92398,0.35561 -4.38505,0.20583c-0.0901,2.53205 0.22702,5.05411 0.88113,7.47607c0.16236,0.68906 0.32472,1.37811 0.48707,2.06716c0.78131,-0.01763 2.39448,-0.21252 1.64896,1.25519c-1.5683,0.98676 -0.6085,3.06338 0.26087,4.24467c1.07762,1.55437 2.68473,3.0095 2.75357,5.13759c0.431,0.29306 1.86537,1.09814 1.45047,1.72844c-6.86599,-0.04014 -13.73592,0.11604 -20.59841,-0.17092l-0.2383,-0.02494l-0.19434,-0.05377l0,0l0,0.00001l0,0.00001z" fill="#455634"/> <rect id="svg_107" height="59.79901" width="158.2915" y="163.96793" x="270.72866" stroke-width="NaN" stroke="#ff7f00" fill="none"/> <path stroke="#000000" id="svg_103" d="m340.1747,215.04926c-1.89985,0.39021 -1.93649,-2.68762 -0.23045,-2.78584c-0.5114,-1.32051 -0.11997,-2.9406 0.63586,-4.16273c1.08392,-2.04179 2.71409,-4.07128 2.37729,-6.6274c-0.1166,-1.32981 -1.59507,-3.71405 0.69697,-3.37261c0.6197,-1.32611 0.2593,-3.27849 0.72408,-4.80168c0.40587,-2.88746 1.30925,-5.96852 0.34832,-8.83123c-0.60585,-1.52384 -2.14533,-2.52687 -1.98009,-4.38973c-0.17401,-1.8166 -0.11643,-3.64703 0.07359,-5.45831c0.73979,0.06915 1.56305,-0.17358 2.23756,0.20011c-0.00506,1.75835 1.49361,1.36882 1.31388,-0.12547c0.39426,-0.17399 1.04689,-0.02498 1.54062,-0.07463c2.19508,0 4.39018,0 6.58525,0c-0.25114,1.01943 0.42842,2.33335 1.28895,1.13316c-0.2354,-1.59442 1.73574,-1.06677 1.26337,0.30483c0.02782,1.81724 0.22768,3.6974 -0.23031,5.46694c-0.74594,0.70662 -0.7577,2.09736 -1.6922,2.93066c-0.75096,1.56239 -0.42002,3.45036 -0.33651,5.14748c0.31805,2.51164 0.84318,4.992 0.9741,7.53252c-0.09363,1.38123 2.45765,0.97471 1.35757,2.67482c-1.20227,1.14114 -0.49853,3.06827 -0.02242,4.43103c0.93964,2.35541 2.9203,4.47117 2.62135,7.23365c-0.23706,1.20687 1.72443,0.79882 1.21456,2.35293c-0.01479,1.9154 -2.56868,0.68407 -3.69998,1.08639c-5.68651,0.07686 -11.37479,0.19555 -17.06138,0.1351l0,0l0.00001,0.00001l0.00001,0z" fill="#FFFFFF"/> <text xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_108" y="152.79892" x="309.47531" stroke-width="NaN" fill="#ff7f00">Output</text> </g> <g> <title>background</title> </g> <g> <title>background</title> </g> <g> <title>background</title> </g> <g> <title>background</title> <rect fill="none" id="canvas_background" height="362.00153" width="362.00153" y="-1" x="-1"/> </g> </svg> ### Input/Output ### Input will always be 2 non-empty strings. Output must be a list of: - All Rook's positions where pin is possible - If the is more than one position, sort them in ascending order - If such position not possible - return empty list `[]`
games
def pin_rook(* kb): (_, x, y), (_, i, j) = kb if x == i: return [f"R { x }{ r } " for r in '12345678' if y < j < r or r < j < y] if y == j: return [f"R { r }{ y } " for r in 'abcdefgh' if x < i < r or r < i < x] return []
Chess - Pin with Rook
5fc85f4d682ff3000e1c4305
[ "Puzzles" ]
https://www.codewars.com/kata/5fc85f4d682ff3000e1c4305
6 kyu
[Generala](https://en.wikipedia.org/wiki/Generala) is a dice game popular in South America. It's very similar to [Yahtzee](https://en.wikipedia.org/wiki/Yahtzee) but with a different scoring approach. It is played with 5 dice, and the possible results are: | Result | Points | Rules | Samples | |---------------|--------|------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------| | GENERALA | 50 | When all rolled dice are of the same value. | 66666, 55555, 44444, 11111, 22222, 33333. | | POKER | 40 | Four rolled dice are of the same value. | 44441, 33233, 22262. | | FULLHOUSE | 30 | Three rolled dice are of the same value, the remaining two are of a different value, but equal among themselves. | 12121, 44455, 66116. | | STRAIGHT | 20 | Rolled dice are in sequential order. Dice with value `1` is a wildcard that can be used at the beginning of the straight before a `2`, or at the end of it after a `6`. | 12345, 23456, 34561, 13654, 62534. | | Anything else | 0 | Anything else will return `0` points. | 44421, 61623, 12346. | Please note that dice are not in order; for example `12543` qualifies as a `STRAIGHT`. Also, No matter what string value you get for the dice, you can always reorder them any order you need to make them qualify as a `STRAIGHT`. I.E. `12453`, `16543`, `15364`, `62345` all qualify as valid `STRAIGHT`s. Complete the function that is given the rolled dice as a string of length `5` and return the points scored in that roll. You can safely assume that provided parameters will be valid: * String of length 5, * Each character will be a number between `1` and `6`
algorithms
def points(dice): dice = sorted([int(d) for d in dice]) counts = [dice . count(i) for i in range(1, 7)] if 5 in counts: # GENERALA return 50 if 4 in counts: # POKER return 40 if 3 in counts and 2 in counts: # FULLHOUSE return 30 if counts . count(1) == 5 and counts . index(0) not in [2, 3, 4]: # STRAIGHT return 20 return 0
Generala - Dice Game
5f70c55c40b1c90032847588
[ "Games", "Algorithms" ]
https://www.codewars.com/kata/5f70c55c40b1c90032847588
6 kyu
# Leaderboard climbers In this kata you will be given a leaderboard of unique names for example: ```python ['John', 'Brian', 'Jim', 'Dave', 'Fred'] ``` ```haskell [ "John" , "Brian" , "Jim" , "Dave" , "Fred" ] ``` ```rust [ "John", "Brian", "Jim", "Dave", "Fred" ] ``` Then you will be given a list of strings for example: ```python ['Dave +1', 'Fred +4', 'Brian -1'] ``` ```haskell [ "Dave +1", "Fred +4", "Brian -1" ] ``` ```rust [ "Dave +1", "Fred +4", "Brian -1" ] ``` Then you sort the leaderboard. The steps for our example would be: ```python # Dave up 1 ['John', 'Brian', 'Dave', 'Jim', 'Fred'] ``` ```haskell -- Dave up 1 [ "John" , "Brian" , "Dave" , "Jim" , "Fred" ] ``` ```rust // Dave up 1 [ "John", "Brian", "Dave", "Jim", "Fred" ] ``` ```python # Fred up 4 ['Fred', 'John', 'Brian', 'Dave', 'Jim'] ``` ```haskell -- Fred up 4 [ "Fred" , "John" , "Brian" , "Dave" , "Jim" ] ``` ```rust // Fred up 4 [ "Fred", "John", "Brian", "Dave", "Jim" ] ``` ```python # Brian down 1 ['Fred', 'John', 'Dave', 'Brian', 'Jim'] ``` ```haskell -- Brian down 1 [ "Fred" , "John" , "Dave" , "Brian" , "Jim" ] ``` ```rust // Brian down 1 [ "Fred", "John", "Dave", "Brian", "Jim" ] ``` Then once you have done this you need to return the leaderboard. All inputs will be valid. All strings in the second list will never ask to move a name up higher or lower than possible eg. `"John +3"` could not be added to the end of the second input list in the example above. The strings in the second list will always be something in the leaderboard followed by a space and a `+` or `-` sign followed by a number.
reference
def leaderboard_sort(leaderboard, changes): for change in changes: name, delta = change . split() idx = leaderboard . index(name) leaderboard . insert(idx - int(delta), leaderboard . pop(idx)) return leaderboard
Leaderboard climbers
5f6d120d40b1c900327b7e22
[ "Lists", "Fundamentals" ]
https://www.codewars.com/kata/5f6d120d40b1c900327b7e22
6 kyu
### History You are a great investigator. You are spending Christmas holidays with your family when you receive a series of postcards. At first glance the text on the postcards doesn't make sense (why send random quotes?), but after a closer look you notice something strange. *Maybe there is a hidden message!* ### Technical details Your task is to create a class `Investigator` with at least these two methods: - `postcard(self, text)` - analyzes `text` (a string); return value doesn't matter. - `hidden_message(self)` - returns the hidden message (a string). Typical usage: ```python investigator = ... # new instance of Investigator investigator.postcard(text of first postcard) investigator.postcard(text of second postcard) investigator.postcard(...) investigator.postcard(text of last postcard) investigator.hidden_message() # return value is checked # investigator goes out of scope ``` - 1-15 postcards per instance - one hidden message per instance
games
import re class Investigator: def __init__(self): self . decoded = [] def postcard(self, s): self . decoded . append( '' . join(re . findall(r'(?<=\w)[A-Z]| (?= )', s))) def hidden_message(self): return '' . join(self . decoded)
Investigator's holidays and hidden messages
5fe382d3e01a94000d54916a
[ "Strings", "Puzzles" ]
https://www.codewars.com/kata/5fe382d3e01a94000d54916a
6 kyu
Complete the function which accepts a string and return an array of character(s) that have the most spaces to their right and left. **Notes:** * the string can have leading/trailing spaces - you **should not** count them * the strings contain only unique characters from `a` to `z` * the order of characters in the returned array doesn't matter ## Examples ```javascript "a b c" --> ["b"] "a bcs d k" --> ["d"] " a b sc p t k" --> ["p"] "a b c de" --> ["b", "c"] " a b c de " --> ["b"] "abc" --> ["a", "b", "c"] ``` Good luck!
algorithms
import regex def loneliest(s): ss = regex . findall(r'(?<!\s)\s*\S\s*', s . strip(), overlapped=True) max_len = max(map(len, ss)) return [s . strip() for s in ss if len(s) == max_len]
Loneliest character
5f885fa9f130ea00207c7dc8
[ "Strings", "Algorithms" ]
https://www.codewars.com/kata/5f885fa9f130ea00207c7dc8
6 kyu
Let there be `k` different types of weather, where we denote each type of weather by a positive integer. For example, sunny = 0, rainy = 1, ..., cloudy = k. ### Task Find the probability of having weather `j` in `n` days from now given weather `i` today and conditional on some daily weather transition probabilities, a `k*k` matrix, where `i` and `j` are integers less than or equal to `k`. ### Example There are two types of weather 0 and 1. Transition probabilities: ``` [[0.6, 0.4], [0.3, 0.7]] ``` - The probability of weather 0 tomorrow if weather 0 today: 60% - The probability of weather 1 tomorrow if weather 0 today: 40% - The probability of weather 0 tomorrow if weather 1 today: 30% - The probability of weather 1 tomorrow if weather 1 today: 70% The probability of weather 0 *two* days from now if we start in weather 0 becomes: 60% * 60% + 40% * 30% = 48%. Because either we stay in 0 for two days or we go from 0 to 1 and then from 1 to 0. ### Note We will have `k` &le; 10 and `n` &le; 50.
algorithms
import numpy as np ''' Parameters: - days (n) number of days for prediction, an integer - weather_today (i), an integer - final_whether (j) we want to predict in n days, an integer - P = [[p_11, ..., p_1k], [p_21, ..., p_2k], ..., [p_k1, ..., p_kk]], tranistion matrix, where p_xy is probability going from weather x to y in one day ''' def weather_prediction(days, weather_today, final_weather, P): return np . linalg . matrix_power(np . array(P). transpose(), days)[final_weather, weather_today]
Weather prediction
602d1d769a1edc000cf59e4c
[ "Probability", "Algorithms", "Data Science" ]
https://www.codewars.com/kata/602d1d769a1edc000cf59e4c
6 kyu
This Kata is about spotting cyclic permutations represented in two-line notation. ### Introduction - A **permutation** of a set is a rearrangement of its elements. It is often the permutations of the set `(1, 2,...,n)` that are considered for studying permutations. - One way to represent a permutation is **two-line notation**, in which there are two rows of numbers and the `i`th element in the first row maps to the `i`th element in the second row. - A **cycle** of a permutation is a series of elements where each element maps to the following element and the final one maps to the first one. A permutation is called a **cyclic permutation** if and only if it has a **single** nontrivial cycle (a cycle of length > 1). ### Examples ```python >>> from typing import Tuple >>> def is_cyclic(p: Tuple[Tuple[int]]) -> bool: ... # Your code here... ... pass ... >>> p = ( ... (1, 2, 3, 4, 5, 6), ... (4, 3, 6, 2, 1, 5) ... ) >>> is_cyclic(p) True >>> p = ( ... (1, 2, 3, 4, 5, 6), ... (4, 6, 3, 2, 1, 5) ... ) >>> is_cyclic(p) False >>> p = ( ... (2, 8), ... (8, 2) ... ) >>> is_cyclic(p) True >>> p = ( ... (1, 2, 3, 4, 5, 6), ... (3, 1, 2, 5, 6, 4) ... ) >>> is_cyclic(p) False ``` ### Assumptions 1. Input will always be valid. 2. `n > 1 and n < 101`, where `n` is number of elements in each row of `p`. 3. You will enjoy this kata.
reference
def is_cyclic(p): links = dict(zip(* p)) m = next(iter(links)) while m in links: m = links . pop(m) return not links
Cyclic Permutation Spotting
5f9d63c2ac08cb00338510f7
[ "Fundamentals", "Recursion" ]
https://www.codewars.com/kata/5f9d63c2ac08cb00338510f7
6 kyu
# Task You get a list of non-zero integers A, its length is always even and always greater than one. Your task is to find such non-zero integers W that the weighted sum ```math A_0 \cdot W_0 + A_1 \cdot W_1 + .. + A_n \cdot W_n ``` is equal to `0`. # Examples ```python # One of the possible solutions: W = [-10, -1, -1, 1, 1, 1] # 1*(-10) + 2*(-1) + 3*(-1) + 4*1 + 5*1 + 6*1 weigh_the_list([1, 2, 3, 4, 5, 6]) # One of the possible solutions: W = [4, 1] # -13*4 + 52*1 = 0 weigh_the_list([-13, 52]) # One of the possible solutions: W = [1, 1] # -1*1 + 1*1 = 0 weigh_the_list([-1, 1]) ``` ```haskell weights [ 1, 2, 3, 4, 5, 6 ] -> [ -10, -1, -1, 1, 1, 1 ] -- other solution are possible -- 1 * (-10) + 2 * (-1) + 3 * (-1) + 4 * 1 + 5 * 1 + 6 * 1 == 0 weights [-13, 52] -> [ 4, 1 ] -- other solutions are possible -- (-13) * 4 + 52 * 1 == 0 weights [-1, 1] -> [ 1, 1 ] -- other solutions are possible -- (-1) * 1 + 1 * 1 == 0 ``` ```javascript weights([ 1, 2, 3, 4, 5, 6 ]) => [ -10, -1, -1, 1, 1, 1 ] // other solution are possible // 1 * -10 + 2 * -1 + 3 * -1 + 4 * 1 + 5 * 1 + 6 * 1 == 0 weights([-13, 52]) => [ 4, 1 ] // other solutions are possible // -13 * 4 + 52 * 1 == 0 weights([-1, 1]) => [ 1, 1 ] // other solutions are possible // -1 * 1 + 1 * 1 == 0 ``` ```rust // One of the possible solutions: W = [-10, -1, -1, 1, 1, 1] // 1*(-10) + 2*(-1) + 3*(-1) + 4*1 + 5*1 + 6*1 weigh_the_list([1, 2, 3, 4, 5, 6]); // One of the possible solutions: W = [4, 1] // -13*4 + 52*1 = 0 weigh_the_list([-13, 52]); // One of the possible solutions: W = [1, 1] // -1*1 + 1*1 = 0 weigh_the_list([-1, 1]); ``` Have fun! :)
reference
def weigh_the_list(a): return [w for i in range(0, len(a), 2) for w in [a[i + 1], - a[i]]]
Weigh The List #1
5fad2310ff1ef6003291a951
[ "Mathematics", "Fundamentals" ]
https://www.codewars.com/kata/5fad2310ff1ef6003291a951
6 kyu
_Yet another easy kata!_ ##### If you are newbie on CodeWars then I suggest you to go through [this](https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution). # Background: _this kata is sort of educational too so, it you don't want to learn go away!_ \ CPU scheduling is a process which allows one process to use the CPU while the execution of another process is on hold (or in waiting state) due to unavailability of any resource like I/O etc, thereby making full use of CPU. The aim of CPU scheduling is to make the system efficient, fast and fair.[_read more about scheduling in operating system_]('https://en.wikipedia.org/wiki/Scheduling_(computing)') * Non-Preemptive Scheduling: - Under non-preemptive scheduling, once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state. * Preemptive Scheduling - In this type of Scheduling, the tasks are usually assigned with priorities. At times it is necessary to run a certain task that has a higher priority before another task although it is running. Therefore, the running task is interrupted for some time and resumed later when the priority task has finished its execution. * Scheduling Algorithms - To decide which process to execute first and which process to execute last to achieve maximum CPU utilisation, you will implement these algorithms in follow-up series, they are - [First Come First Serve(FCFS) Scheduling]('https://www.codewars.com/kata/5f0ea61fd997db00327e6c25/train/cpp') (_current kata_) - Shortest-Job-First(SJF) Scheduling (Non Pre-emptive) - Shortest-Job-First(SJF) Scheduling (Pre-emptive) - Priority Scheduling (Non Pre-emptive) - Priority Scheduling (Pre-emptive) - Round Robin(RR) Scheduling - Multilevel Queue Scheduling - Multilevel Feedback Queue Scheduling <hr> # Task: First Come First Serve(FCFS) Scheduling ### Input: * Implement a function `fcfs` with given processes `processes`(vector) which consist of `arrival time` and `burst time` as single pair for each process and given processes will be sorted by arrival time.(`i.e [Arrival time, Burst time]`). (_No two processes will have the same arrival time_) <hr> ### Terms: As the name suggests, the process which arrives first, gets executed first, or we can say that the process which requests the CPU first, gets the CPU allocated first. (just like FIFO if you will) * Arrival time : Point of time at which process enters into ready queue (or ram). * Burst Time : Time duration required by process to get executed on CPU. * Completion Time : Point of time at which process completes it's execution. * Response Time : RT = Time at which the CPU starts the execution of the process - Arrival Time * Turn Around Time : total time taken by process to get executed (including waiting time and all), formula : TAT = Completion TIme - Arrival Time * Waitng Time : WT = Turn Around Time (total time) - Burst Time(useful time) * Throughput : Throughput means the efficiency of the scheduling algo that is the average "useful time" (time where the CPU is actually used) per process. Note: for the current task, RT and WT are actually the very same value. <hr> ### General Steps: * CPU locates very first process arrived in ready queue and start executing it and complete it;s execution depending upon Burst time of that process and if there;s no process arrived in ready queue then CPU have to wait until next process arrives in ready queue. (NOTE: note various timing to get expected output (see example below)) * Start again for next process in ready queue. <hr> ### Output: * Return Average Completion Time, Average Turn Around Time, Average Waiting Time and Throughput in vector `(A-CT, A-TAT, A-WT, Throughput)` all rounded to two decimal places. <hr> ### Example: ``` processes = [[0, 2], [1, 2], [5, 3], [6, 4], [7, 9]] first process is considered as p1 and second as p2 and so on.. (I used gnatt chart to explain this process) process p1's arrival time is 0th second (process p1 arrives at 0th second in ready queue) and burst time(executing time) is 2 seconds. ready queue = [p1] CPU starts executing process p1 and p1 takes 2 seconds to complete it;s task so, gnatt chart : -------------------------- | p1 | | | | | -------------------------- 0 2 during executing process p1 another process p2 enters ready queue (since, process p2;s arrival time is at 1st second) and it takes also 2 seconds to get executed. ready queue = [p2] gnatt chart : -------------------------- | p1 | p2 | | | | -------------------------- 0 2 4 at the end of 4th second, no other processes arrived in ready queue (p3's arrival time is 5 and p4;s 6) ready queue = [] since, there;s no process arrived in ready queue the CPU is ideal(free) so, CPU wait for the process to be arrived in ready queue. gnatt chart : -------------------------- | p1 | p2 | -- | | | -------------------------- 0 2 4 5 at 5th second process p3 arrives in ready queue and takes 3 seconds to get executed. ready queue = [p3] gnatt chart : -------------------------- | p1 | p2 | -- | p3 | | -------------------------- 0 2 4 5 8 while CPU was executing p3, process p4 and p5 arrived in ready queue at 6th and 7th second respectively. ready queue = [p4, p5] (CPU chooses process which arrived first in ready queue) gnatt chart : -------------------------- | p1 | p2 | -- | p3 | p4 | -------------------------- 0 2 4 5 8 12 ready queue = [p5] gnatt chart : ------------------------------- | p1 | p2 | -- | p3 | p4 | p5 | ------------------------------- 0 2 4 5 8 12 21 - left side of process in gnatt chart is a point of time at which process got CPU for the first time. - right side of process in gnatt chart is a point of time at which process completes it;s execution. (AT = Arival Time, BT = Burst Time, CT = Completion Time, TAT = Turn Around Time, WT = Waiting Time, RT = Response Time) (see formula above) Process | AT | BT | CT | TAT | WT | RT p1 | 0 | 2 | 2 | 2 | 0 | 0 p2 | 1 | 2 | 4 | 3 | 1 | 1 p3 | 5 | 3 | 8 | 3 | 0 | 0 p4 | 6 | 4 | 12 | 6 | 2 | 2 p5 | 7 | 9 | 21 | 14 | 5 | 5 Average CT = 9.4 Average TAT = 5.6 Average WT = 1.6 Average RT = 1.6 Throughput = (2+2+3+4+9)/5 = 4 seconds (NOTE : Response Time is not tested in this kata (explained here for follow-up series)) ``` <hr> ##### Have Fun! _There is lot of information which is not required for this kata but required for follow-up series so, it;s best to put these basic information in very first kata of series._
reference
def fcfs(lst): t, CT, TAT, WRT, dTP = (0,) * 5 for at, bt in sorted(lst): if t < at: dTP, t = dTP - (at - t), at ct = t + bt CT += ct WRT += t - at TAT += ct - at t += bt return tuple(round(v / len(lst), 2) for v in (CT, TAT, WRT, dTP + t))
Operating System Scheduling #1 : FCFS scheduling
5f0ea61fd997db00327e6c25
[ "Fundamentals" ]
https://www.codewars.com/kata/5f0ea61fd997db00327e6c25
6 kyu
**Introduction** Consider the first 16 terms of the series below: `11,32,53,94,135,176,217,298,379,460,541,622,703,784,865,1026...` which is generated by this sequence: `11,21,21,41,41,41,41,81,81,81,81,81,81,81,81,161...`. Each term `u` of the sequence is obtained by finding the: `(last power of 2) * 10 + 1` if `u` is not a power of 2. or`u * 10 + 1` if `u` is a power of 2. *Please note that `u` starts at 1 and not 0.* **Task** Given variable `n`, calculate the `n`th term of the series shown above. **Tests** * 10 fixed tests: First 10 terms * 100 random tests: 1e100 < n < 1e101 <br> *Notes:* * *Naive solutions won't pass, so don't try to generate the sequence.* * *Aim for a sublinear solution (constant time is possible but not required).*
algorithms
from itertools import count def squared_digits_series(n): s = n for p in count(): p = 2 * * p x = min(p, n) s += 10 * p * x n -= x if n < 1: return s
Sequence of squared digits
5f8584916ddaa300013e1592
[ "Algorithms", "Mathematics", "Logic" ]
https://www.codewars.com/kata/5f8584916ddaa300013e1592
6 kyu
In this kata, you have an integer array which was ordered by ascending except one number. For Example: [1,2,3,4,17,5,6,7,8] For Example: [19,27,33,34,112,578,116,170,800] You need to figure out the first breaker. Breaker is the item, when removed from sequence, sequence becomes ordered by ascending. For Example: [1,2,3,4,17,5,6,7,8] => 17 is the only breaker. For Example: [19,27,33,34,112,578,116,170,800] => 578 is the only breaker. For Example: [105, 110, 111, 112, 114, 113, 115] => 114 and 113 are breakers. 114 is the first breaker. When removed 114, sequence becomes ordered by ascending => [105, 110, 111, 112, 113, 115] When removed 113, sequence becomes ordered by ascending => [105, 110, 111, 112, 114, 115] For Example: [1, 0, 2] => 1 and 0 are the breakers. 1 is the first breaker. When removed 1, sequence becomes ordered by ascending => [0, 2] When removed 0, sequence becomes ordered by ascending => [1, 2] For Example: [1, 2, 0, 3, 4] => 0 is the only breaker. When removed 0, sequence becomes ordered by ascending. => [1, 2, 3, 4] TASK: Write a function that returns the first breaker. **Notes:** * Input array does not contain any duplicate element.
reference
INF = float('inf') def order_breaker(lst): return next(b for a, b, c in zip([- INF] + lst, lst, lst[1:] + [INF]) if a <= c and (a > b or b > c))
Find the Order Breaker
5fc2a4b9bb2de30012c49609
[ "Fundamentals" ]
https://www.codewars.com/kata/5fc2a4b9bb2de30012c49609
6 kyu
<h2>Description</h2> Bob really likes to write his casual notes using a basic text editor.<br> He often uses tables to organize his informations but building them takes some time.<br> Would you help him to automatize the process ?<br> (No? Then keep an eye on your data 👀) <br><br> For example he would like the following text : ``` ABBREVIATION|MEANING LOL|Laughing Out Loud BRB|Be Right Back IDK|I Don't Know ``` to be written as : ``` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !__ABBREVIATION__|_______MEANING_______! !______LOL_______|__Laughing_Out_Loud__! !______BRB_______|____Be_Right_Back____! !______IDK_______|____I_Don't_Know_____! ``` <h2>Task</h2> Create a function which receives some text and returns it enclosed into a table.<br> The text is already splitted for you (see below).<br> <h3>Input</h3> `text` --> list of lists of strings<br> `style` -> Style object <h3>Output</h3> `res` ---> string <br> Your output and the expected result will be printed if not too long. <h3>Style</h3> The purpose of the `Style` object you are given is to contain informations about the customization of the table.<br> A `Style` object is an instance of the following `dataclass` (Python 3.7+ from the module `dataclasses`):<br> ```python @dataclass(frozen=True) # immutable after creation class Style: off_min : int # minimum number of sep_hi to be applied to each side of the text in each table cell sep_he : str # Separator Horizontal Extern sep_hi : str # Separator Horizontal Intern sep_ve : str # Separator Vertical Extern sep_vi : str # Separator Vertical Intern align : str # how to align text, is one of : "left", "mid", "right" ``` <h4><font color="red">Important notes:</font></h4> <ul> <li> if `align=="mid"` and there is an odd number of `sep_hi` to be inserted, the "extra" one goes to right. </li> <li> `sep_hi` should be used <b>also</b> to replace the spaces inside strings. </li> <li> from a text could derive a table with more than 2 columns<br> ranges, <b>extremes included</b> : ``` ____________________________________________ |_________________|:|__ROWS__|:|__COLUMNS__| |__MIN_NUMBER_OF__|:|___0____|:|_____0_____| note that it's not possible to receive |__MAX_NUMBER_OF__|:|___11___|:|____11_____| the following input -> [[], ... , []] ______________________________________________________ |__________________|:|__MIN_LENGTH__|:|__MAX_LENGTH__| |__STRING__________|:|__0___________|:|__20__________| |__SEP_HE,_SEP_HI__|:|__1___________|:|__1___________| |__SEP_VE,_SEP_VI__|:|__0___________|:|__4___________| ``` </li> </ul> <h2>Clarifications</h2> <h3>Description Example</h3> input : ```python [ ["ABBREVIATION", "MEANING"], ["LOL", "Laughing Out Loud"], ["BRB", "Be Right Back"], ["IDK", "I Don't Know"] ] ``` style object configuration : ```python off_min = 2 sep_he = '~' sep_hi = '_' sep_ve = "!" sep_vi = "|" align = "mid" ``` output (no ending '\n' in the last line) : ```python "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"\ "!__ABBREVIATION__|_______MEANING_______!\n"\ "!______LOL_______|__Laughing_Out_Loud__!\n"\ "!______BRB_______|____Be_Right_Back____!\n"\ "!______IDK_______|____I_Don't_Know_____!" ``` <h3>Alignment</h3> ``` "left" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !__ABBREVIATION__|__MEANING____________! !__LOL___________|__Laughing_Out_Loud__! !__BRB___________|__Be_Right_Back______! !__IDK___________|__I_Don't_Know_______! "mid" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !__ABBREVIATION__|_______MEANING_______! !______LOL_______|__Laughing_Out_Loud__! !______BRB_______|____Be_Right_Back____! !______IDK_______|____I_Don't_Know_____! "right" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !__ABBREVIATION__|____________MEANING__! !___________LOL__|__Laughing_Out_Loud__! !___________BRB__|______Be_Right_Back__! !___________IDK__|_______I_Don't_Know__! ``` <h3>My other Katas :</h3> <a href="https://www.codewars.com/kata/5ebad92cd3c72f00181a8a5a">Explosive Table</a><br> <a href="https://www.codewars.com/kata/5e78df9c1f936d00321485ab">Techno Barman</a><br> <a href="https://www.codewars.com/kata/5e614d3ffa2602002922a5ad">Odd-Even Compositions</a><br>
reference
def build_table(lst, style): if not lst: return '' align = {'left': '<', 'mid': '^', 'right': '>'}[style . align] pad = style . sep_hi * style . off_min sizes = [max(map(len, r)) for r in zip(* lst)] fullsize = sum(sizes) + style . off_min * 2 * len(sizes) + \ (len(sizes) - 1) * len(style . sep_vi) + 2 * len(style . sep_ve) def buildCell( w, size): return f' { pad }{ w . replace ( " " , style . sep_hi ) :{ style . sep_hi }{ align }{ size }}{ pad } ' def buildRow(r): return style . sep_vi . join(buildCell(w, size) for w, size in zip(r, sizes)) return '\n' . join((style . sep_he * fullsize, * ("{ve}{row}{ve}" . format(ve=style . sep_ve, row=buildRow(r)) for r in lst)) )
Table Builder
5ff369c8ee41be0021770fee
[ "Algorithms", "ASCII Art", "Fundamentals" ]
https://www.codewars.com/kata/5ff369c8ee41be0021770fee
6 kyu
## The task ~~~if:python,javascript, Consider a sequence, which is formed of re-sorted series of natural numbers. The terms of sequence are sorted by `steps to reach 1 (in Collatz iterations)` (ascending) and then by `value` (ascending). You are asked to write a generator, that yields the terms of the sequence in order. Your generator will be tested up to 20000-th term. Furthermore, the length of solution is limited to 5000 symbols to prevent hardcoding. ~~~ ~~~if:haskell, Consider a sequence, which is formed of re-sorted series of natural numbers. The terms of sequence are sorted by `steps to reach 1 (in Collatz iterations)` (ascending) and then by `value` (ascending). You are asked to define a list, whose values are the terms of the sequence in order. Your list will be tested up to 20000-th term. Furthermore, the length of solution is limited to 5000 symbols to prevent hardcoding. ~~~ ## Example Here is how the beginning of the sequence looks like: `1, 2, 4, 8, 16, 5, 32, 10, 64, 3, 20, 21, 128, ...` - 1 takes 0 steps, 2 takes 1 step, 4 takes 2 steps, 8 takes 3 steps, and 16 takes 4 steps; - 5 and 32 take 5 steps; - 10, 64 take 6 steps; - 3, 20, 21, 128 take 7 steps each; - etc (in each subsequence, where numbers have same number of steps in terms of Collatz conjecture, they are ordered by value)... ## Collatz conjecture As you probably know, the yet unproved Collatz conjecture states that if you take any positive integer number `x`, it will eventually reach `1` if you continuously apply the following operations: - if `x` is odd: `x := 3 * x + 1` - if `x` is even: `x := x / 2` In this task, the sorting key `steps to reach 1` means the number of abovementioned steps before `x == 1`.
algorithms
def collatz(): seq = {1} while True: yield from sorted(seq) seq = {2 * x for x in seq} | {~ - x / / 3 for x in seq if x % 6 == 4} - {1}
Yet another Collatz kata
5fbfa1f738c33e00082025e0
[ "Mathematics", "Algorithms" ]
https://www.codewars.com/kata/5fbfa1f738c33e00082025e0
6 kyu
# Make Chocolates Halloween is around the corner and we have to distribute chocolates. We need to assemble a parcel of `goal` grams of chocolates. The `goal` can be assumed to be always a positive integer value. - There are small chocolates (2 grams each) and big chocolates (5 grams each) - To reach the goal, the chocolates (big and small) must be used as-is, meaning, the chocolates cannot be broken into smaller pieces - Maximize the use of big chocolates that are available to achieve the desired goal. And only then should you proceed to use the small chocolates. - NOTE: "Maximize" does not imply you have to use all the available big chocolates before using the small chocolates - For example, consider the goal of `6`, and `big=1`, `small=3`. Using the existing one big chocolate, it is _not_ possible to achieve the remainder of the weight of 1. Therefore, avoid using the big chocolate. Use the existing 3 small chocolates and achieve the goal. Determine the number of small chocolates that are required to achieve the desired parcel weight. Write a function `make_chocolates` that will accept three integer values as arguments, in the following order: - `small` -> number of small chocolates available - `big` -> number of big chocolates available - `goal` -> the desired weight of the final parcel The function should return the number of small chocolates required to achieve the `goal`. The function should return `-1` only if the goal cannot be achieved by any possible combination of big chocolates and small chocolates. ## Example make_chocolates (4, 1, 13) => 4 make_chocolates (4, 1, 14) => -1 make_chocolates (2, 1, 7) => 1 # using the big chocolate prevents goal # accomplishment, therefore don't use it! make_chocolates (3, 1, 6) => 3
reference
def make_chocolates(s, b, n): bigs = min(n / / 5, b) n -= 5 * bigs if n & 1 and bigs: n += 5 smalls = min(s, n / / 2) return - 1 if n - 2 * smalls else smalls
Pack Some Chocolates
5f5daf1a209a64001183af9b
[ "Fundamentals" ]
https://www.codewars.com/kata/5f5daf1a209a64001183af9b
6 kyu
# Story You want to play a spinning wheel with your friend. Unfortunately, you have used all of your money to buy things that are more useful than a spinning wheel. So you have to create the rule and the spinning wheel yourself. # Task Your spinning wheel consists of sections which could be either __"Win"__ or __"Not Win"__. If you get __"Win"__, you win right away. But If you get __"Not Win"__, it's now your friend's turn to spin the wheel. This goes on forever until someone wins. You will be given a string which each character represent a section of the wheel. *(Imagine getting that string up into the real world, and wrap it around a spinning wheel. The first character of the string is connected with the last character.)* the __"Win"__ section is transform to 'W' and the __"Not Win"__ section is transform to 'N'. Find the probability of you winning the game if you go first in percentage, rounding down. # Example ### Ex.1 Given a string `"WWWWWW"`, all of the section is __"Win"__. If you go first, you will always win. So in this example, you have to return `100` for 100% winning probability. ### Ex.2 Given a string `"NNN"`, all of the section is __"Not Win"__. In this scenario, no one will ever win. So your probability of winning is 0%. So you have to return `0`. ### Ex.3 If you calculate the probability and get 31.6%, you have to return `31` because .6% gets round down. # Extra ##### >The probability can never be more than 100% or less than 0%. ##### >The string will only consists of 'W' or 'N'. # Note about rounding For any valid input string there exists one and only one correct integer answer. Hint: it is possible to solve this problem without floating-point arithmetic.
games
def spinning_wheel(wheel): n, k = len(wheel), wheel . count('W') return 100 * n / / (2 * n - k) if k else 0
Probability #1 : The Infinite Spinning Wheel
605d58ab7f229d001bac446e
[ "Mathematics", "Games", "Puzzles", "Probability" ]
https://www.codewars.com/kata/605d58ab7f229d001bac446e
6 kyu
Your job is to change the given string `s` using a non-negative integer `n`. Each bit in `n` will specify whether or not to swap the case for each alphabetic character in `s`: if the bit is `1`, swap the case; if its `0`, leave it as is. When you finish with the last bit of `n`, start again with the first bit. You should skip the checking of bits when a non-alphabetic character is encountered, but they should be preserved in their original positions. ## Examples ``` swap("Hello world!", 11) --> "heLLO wORLd!" ``` ...because `11` is `1011` in binary, so the 1st, 3rd, 4th, 5th, 7th, 8th and 9th alphabetical characters have to be swapped: ``` H e l l o w o r l d ! 1 0 1 1 1 x 0 1 1 1 0 x ^ ^ ^ ^ ^ ^ ^ ``` ## More examples ``` swap("gOOd MOrniNg", 7864) --> "GooD MorNIng" swap("", 11345) --> "" swap("the lord of the rings", 0) --> "the lord of the rings" ```
reference
from itertools import cycle def swap(s, n): b = cycle(bin(n)[2:]) return "" . join(c . swapcase() if c . isalpha() and next(b) == '1' else c for c in s)
Swap Case Using N
5f3afc40b24f090028233490
[ "Fundamentals" ]
https://www.codewars.com/kata/5f3afc40b24f090028233490
6 kyu
#### Problem `b` boys and `g` girls went to the cinema and bought tickets for consecutive seats in the same row. Write a function that will tell you how to sit down for boys and girls, so that at least one girl sits next to each boy, and at least one boy sits next to each girl. ![picture](https://github.com/LarisaOvchinnikova/markdown-examples/blob/master/boys1.png?raw=true) #### The format of the input data The input contains two numbers: `b` and `g` (both numbers are natural). #### Output format The function should return any string that contains exactly `b` characters `'B'` (denoting boys) and `g` characters `'G'` (denoting girls), satisfying the condition of the problem. You do not need to print spaces between characters. If it is not possible to seat boys and girls according to the task conditions, the function should return `null`, `None`, etc. depending on programming language. #### Examples ```javascript cinema(1,1) === "BG" (the result like "GB" is also valid) cinema(5,5) === "BGBGBGBGBG" (the result like "GBGBGBGBGB" is also valid) cinema(5,3) === "BGBGBBGB" (the results like "BGBBGBBG" or "BGBBGBGB" and so on are also valid) cinema(3,3) === "BGBGBG" (the result like "GBGBGB" is also valid) cinema(100,3) === null ``` ```python cinema(1,1) == "BG" (the result like "GB" is also valid) cinema(5,5) == "BGBGBGBGBG" (the result like "GBGBGBGBGB" is also valid) cinema(5,3) == "BGBGBBGB" (the results like "BGBBGBBG" or "BGBBGBGB" and so on are also valid) cinema(3,3) == "BGBGBG" (the result like "GBGBGB" is also valid) cinema(100,3) == None ``` ```haskell cinema 1 1 -> Just "BG" (the result like "GB" is also valid) cinema 5 5 -> Just "BGBGBGBGBG" (the result like "GBGBGBGBGB" is also valid) cinema 5 3 -> Just "BGBGBBGB" (the results like "BGBBGBBG" or "BGBBGBGB" and so on are also valid) cinema 3 3 -> Just "BGBGBG" (the result like "GBGBGB" is also valid) cinema 100 3 -> Nothing ```
reference
def cinema(x, y): if 2 * x >= y and 2 * y >= x: return "BGB" * (x - y) + "GBG" * (y - x) + "BG" * (min(x, y) - abs(x - y))
A Cinema
603301b3ef32ea001c3395d0
[ "Strings", "Fundamentals" ]
https://www.codewars.com/kata/603301b3ef32ea001c3395d0
6 kyu
What date corresponds to the `n`<sup>th</sup> day of the year? The answer depends on whether the year is a leap year or not. Write a function that will help you determine the date if you know the number of the day in the year, as well as whether the year is a leap year or not. The function accepts the day number and a boolean value `isLeap` as arguments, and returns the corresponding date of the year as a string `"Month, day"`. Only valid combinations of a day number and `isLeap` will be tested. #### Examples: ``` * With input `41, false` => return "February, 10" * With input `60, false` => return "March, 1 * With input `60, true` => return "February, 29" * With input `365, false` => return "December, 31" * With input `366, true` => return "December, 31" ``` ~~~if:c In C, the returned string will be freed. ~~~ ![calendar](https://github.com/LarisaOvchinnikova/markdown-examples/blob/master/calendar1.png?raw=true)
reference
from datetime import * def get_day(days, is_leap): return (date(2019 + is_leap, 1, 1) + timedelta(days - 1)). strftime("%B, %-d")
Determine the date by the day number
602afedfd4a64d0008eb4e6e
[ "Fundamentals", "Date Time", "Algorithms" ]
https://www.codewars.com/kata/602afedfd4a64d0008eb4e6e
6 kyu
# Context In Dungeons and Dragons, a tabletop roleplaying game, movement is limited in combat. Characters can only move a set amount of distance per turn, meaning the distance you travel is very important. In the 5th edition of the rulebook, the board is commonly organized into a grid, but for ease of counting, movement is non-euclidian. Each square is 5 ft, and moving diagonally counts the same as moving in a cardinal direction. ``` +------------------------+ | 10 | 10 | 10 | 10 | 10 | +------------------------+ | 10 | 5 | 5 | 5 | 10 | +------------------------+ | 10 | 5 | :) | 5 | 10 | +------------------------+ | 10 | 5 | 5 | 5 | 10 | +------------------------+ | 10 | 10 | 10 | 10 | 10 | +------------------------+ Distance of each grid cell from the player, in feet ``` # Your task Create an algorithm to calculate the distance of a movement path. You will be provided with the path as a series of absolute grid points (x, y, z). Take in to account both horizontal (x, y) as well as vertical (z) movement. Vertical movement is governed by the same rules, for the sake of simplicity.
algorithms
def calc_distance(path): return 5 * sum( max(abs(a - b) for a, b in zip(p1, p2)) for p1, p2 in zip(path, path[1:]))
D&D: Non-Euclidian Movement
60ca2ce44875c5004cda5c74
[ "Algorithms", "Data Structures" ]
https://www.codewars.com/kata/60ca2ce44875c5004cda5c74
6 kyu
Would you believe me if I told you these particular tuples are special? (1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31) (2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31) (4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31) (8, 9, 10, 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30, 31) (16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31) You want to know why? Ok, I'll tell you: If you think of a number, between 1 and 31, I can tell what number you are thinking, just by asking you in which tuple you can find that number. You don't believe me? What if I tell you the trick? This is the trick: - sum all the first elements of the tuples where you can find the number you are thinking of. If you do it correctly you will get your number. So for example, let's say I am thinking about the number 5. It can be found in the first and third tuple, which have respectively the numbers 1 and 4 as first element. The sum of 1 and 4 is 5! You don't believe me yet? Maybe you think it only works for the number 5. Try it for yourself, so that we can continue our journey. I'll wait. ........ Did it work? Of course it did! This is know as "Brown's Criterion". It works for all numbers from 1 to 31. Your task is to create two functions: - The first one is called "guess_number", it gives you a list of answers. These answers can be integers values (1 or 0), and correspond respectively to Yes and No. The sequence values are the answer to "Do you see your number?" for each one of the above tuples. You are given the sequence and must return the number which originated that sequence of answers. Example: for the sequence [1, 0, 1, 0, 0] you must return the number 5. ----------------------------------------------------------------------------------- - The second one is called "answers_sequence". It is the exact opposite of the first function. You are given a number and must return the sequence of answers for that number. -------------------------------------- Notes ---------------------------------------- - The argument for the function "Guess_Number" will always be a list; - The argument for the function "Answers_Sequence" will always be a number; Good Luck!
games
def guess_number(answers): return int('' . join(map(str, reversed(answers))), 2) def answers_sequence(n): return list(map(int, reversed(f" { n :0 5 b } ")))
Impress your friends with Brown's Criterion!
604693a112b42a0016828d03
[ "Mathematics", "Logic", "Puzzles" ]
https://www.codewars.com/kata/604693a112b42a0016828d03
6 kyu
# Goal Print the Top Of Book of an orderbook # Introduction The state of each stock on a stock market is kept in a data structure called an orderbook. The orderbook consists of two sides, the "Buy Side", which represents offers to buy a stock, and the "Sell Side", which represents offers to sell a stock. The Buy Side is listed starting with the highest price and is ordered in decreasing price. The Sell Side is listed starting with the lowest price and is ordered in increasing price. ``` Buy Side : Sell Side -------- ---------- 4@10 18@16 <-------- Top Of Book 3@6 2@20 2@4 ``` The notation used is ```Qty@Price```, so for example ```4@10``` on the Buy Side indicates that someone is offering to buy 4 shares at a price of 10. Similarly, ```18@16``` on the Sell Side indicates that someone is willing to sell 18 shares at a price of 16. The 'Top Of Book' denotes the top level of the orderbook, that is the offer on the Buy Side with the highest price and the offer on the Sell Side with the lowest price. In this example, the Top of Book is ```4@10 : 18@16```. # Data Feed All updates to the orderbook (new order, modifications, cancellations, and trades) can be represented by two messages: Add and Cancel. ## Add Messages Add messages have the following format: ``` message_type: 'a' order_side: 'b' for buy or 's' for sell order_id: integer unique per order quantity: integer value price: integer value ``` The order id is unique per trading day and therefore won't repeat in this exercise. There are no fractional quantities and all prices are integer values. When various orders have the same price, their quantities are aggregated and all of those orders appear at the same level in the orderbook. ## Cancel Messages Cancel messages have the following format: ``` message_type: 'c' order_id: integer corresponding to an existing order ``` You can assume that all order ids in the cancel message correspond to an existing order. # Input Format In Python, the messages are stored sequentially as tuples in a list. For example, the input ``` [('a', 'b', 1, 2, 3), ('c', 1)] ``` describes an add order on the Buy Side with an order id of 1, a quantity of 2, and a price of 3 followed by a cancellation for the order with id 1. # Output Format Your goal in this exercise is to print the Top Of Book for the orderbook after you receive a data feed containing add and cancel messages. The output should be a string with the following format ``` "4@20 : 2@40" ``` where the Buy Side is on the left and the Sell Side is on the right. If there are no orders on a particular side, it should be represented as ```0@0```. For example, a top of book with no sell orders would look like ```"4@20 : 0@0"```. # Example At the start, the orderbook is empty. ``` Buy Side : Sell Side -------- ---------- 0@0 0@0 ``` An add order on the buy side is received: ```message_type='a' side='b' order_id=1 qty=1 price=5``` ``` Buy Side : Sell Side -------- ---------- 1@5 0@0 ``` An add order on the sell side is received: ```message_type='a' side='s' order_id=2 qty=8 price=10``` ``` Buy Side : Sell Side -------- ---------- 1@5 8@10 ``` Another add order on the buy side is received: ```message_type='a' side='b' order_id=3 qty=2 price=4``` ``` Buy Side : Sell Side -------- ---------- 1@5 8@10 2@4 ``` Another add order on the sell side is received: ```message_type='a' side='s' order_id=4 qty=2 price=10``` ``` Buy Side : Sell Side -------- ---------- 1@5 10@10 2@4 ``` An order on the buy side is cancelled: ```message_type='c' order_id=3``` ``` Buy Side : Sell Side -------- ---------- 1@5 10@10 ``` An order on the sell side is cancelled: ```message_type='c' order_id=2``` ``` Buy Side : Sell Side -------- ---------- 1@5 2@10 ```
algorithms
from collections import defaultdict def print_tob(feed): memo = {} for order in feed: if order[0] == 'c': del memo[order[1]] else: memo[order[2]] = (order[1], order[3], order[4]) res = defaultdict(lambda: defaultdict(int)) for side, quantity, price in memo . values(): res[side][price] += quantity a, b = max(res['b']. items(), default=(0, 0)) c, d = min(res['s']. items(), default=(0, 0)) return f" { b } @ { a } : { d } @ { c } "
Manage an Orderbook
5f3e7df1e0be5a00018a008c
[ "Algorithms" ]
https://www.codewars.com/kata/5f3e7df1e0be5a00018a008c
6 kyu
#### The following task has two parts. First you must figure out the principle behind the following encoding of natural numbers. The table below displays the encoding of the numbers from 0 to 11. **Number** -------> **Code** * `0 -------> '.'` * `1 -------> '()'` * `2 -------> '(())'` * `3 -------> '(.())'` * `4 -------> '((()))'` * `5 -------> '(..())'` * `6 -------> '(()())'` * `7 -------> '(...())'` * `8 -------> '((.()))'` * `9 -------> '(.(()))'` * `10 -------> '(().())'` * `11 -------> '(....())'` Once you understand how the numbers are encoded, write a program which encodes a given natural number and return it as a string. ##### **Values from 0 to 10000 will be checked** ### **Please, rate my Kata after completion**
games
def puzzle(i): ps = set() def sp(i, p=2): if i == 1: return '' d = ps . add(p) or 0 while i % p == 0: d, i = d + 1, i / / p while any(p % q == 0 for q in ps): p += 1 return puzzle(d) + sp(i, p) return f'( { sp ( i )} )' if i else '.'
The Dots and Parentheses
5fe26f4fc09ce8002224e95d
[ "Algorithms", "Puzzles", "Strings" ]
https://www.codewars.com/kata/5fe26f4fc09ce8002224e95d
5 kyu
<h1>Task</h1> For given <strong style="color: red;">n</strong> (>0) points on the arc AB , and <strong style="color: green;">m</strong> (m>0) points on the diametr BA ,<br> write a function <strong>combinations(n , m)</strong> which returns a tuple of 2 numbers (or const array in JavaScript case) representing: <br> a) All possible combinations of triangles composed from the points on arc and diametr <br> b) All possible quadrilaterals composed from points on arc and diametr <h1>Note:<h1/> Points A and B are available for combinations. It means that you can create triangle or <br>quadrilateral with the help of these points. If there is no any combination for any of shapes , <br>just put 0 into the tuple. <h1>Example :</h1> Suppose we have 3 points on arc(n=3) and 2 points on diametr(m=2). So, totally we have <br>7 points(A and B considered). Hence, number of all possible combinations of triangles would <br>be 31 and all possible combinations of quadrilaterlas would be 22. Thus , combinations(3,2) --> (31,22) <h3>Some more examples:</h3> <br>combinations(2,1) -->(9,3) , <br>combinations(1,1) -->(3,0) , <br>combinations(100,50) -->(551700,18893325). <h1>Example on image:</h1> ![example image](https://i.ibb.co/3csDzWx/codewars-kata.png) <p>In the picture above we see red points on the arc (n==2 in this case) and green points on the diametr(m==2 in this case). Total number of points is 6. <br> So, basically the combinations of triangles created by points A,B,C,D,E,F will be the following: <br> ACD , ACE, ACB, DCE, DCB, ECB, AFD, AFE, AFB, DFE, DFB, EFB, ACF, DCF, ECF, BCF <br> Combinations of quadrilaterals: <br> ACFD, ACFE, ACFB, DCFE, DCFB, ECFB <br> Hence, we have <em>combinations(2,2) --> (16,6)</em>.
reference
from math import comb def combinations(n, m): return ( sum(comb(m + 2, i) * comb(n, 3 - i) for i in range(3)), sum(comb(m + 2, i) * comb(n, 4 - i) for i in range(3)), )
Combinations on semicircle
5f0f14348ff9dc0035690f34
[ "Combinatorics", "Fundamentals" ]
https://www.codewars.com/kata/5f0f14348ff9dc0035690f34
6 kyu
# Squared Spiral #1 Given the sequence of positive integers (0,1,2,3,4...), find out the coordinates (x,y) of a number on a square spiral, like the drawings bellow. ### Numbers ... ← 013 ← 012 ↑ ↑ ↑ 004 ← 003 ← 002 011 ↓ ↑ ↑ ↓ ↑ ↑ ↓ ↑ ↑ 005 000 → 001 010 ↓ ↑ ↓ ↑ ↓ ↑ 006 → 007 → 008 → 009 ### Coordinates ... ← 1,2 ← 2,2 ↑ ↑ ↑ -1,1 ← 0,1 ← 1,1 2,1 ↓ ↑ ↑ ↓ ↑ ↑ ↓ ↑ ↑ -1,0 0,0 → 1,0 2,0 ↓ ↑ ↓ ↑ ↓ ↑ -1,-1 → 0,-1 → 1,-1 → 2,-1 The spiral starts at 0 which is located at coordinates (0,0), number 1 is at (1,0), number 2 is at (1,1), number 3 is at (0,1) and so on. The spiral always starts to the right and goes in an anti-clockwise direction. The returned value should be a tuple (for Python) and an array (for Javascript) in the (x,y) format. `100 fixed tests and another 500.000 random tests are performed with small numbers ranging from 0 to 100,000 .Another 500.000 random tests are performed with large numbers ranging from 100,000,000,000 to 100,000,000,000,000.`
algorithms
def squared_spiral(n): b = round(n * * .5) e = (b / / 2 + b % 2 - max(0, b * * 2 - n), - (b / / 2) + max(0, n - b * * 2)) return e if b % 2 else (- e[0], - e[1])
Squared Spiral #1
60a38f4df61065004fd7b4a7
[ "Geometry", "Performance", "Algorithms" ]
https://www.codewars.com/kata/60a38f4df61065004fd7b4a7
6 kyu
You need to write a function that takes array of ```n``` colors and converts them to a linear gradient for example gradient from ```[r1, g1, b1]``` with position ```p1``` to ```[r2, g2, b2]``` with position ```p2``` in order to get the color of the gradient from ```p1``` to ```p2```, you need to find three functions ```Fr```, ```Fg``` and ```Fb``` of the form ```f(x) = a + bx``` for red, green and blue with ```[Fr(p1), Fg(p1), Fb(p1)] = gradient(p1)``` and ```[Fr(p2), Fg(p2), Fb(p2)] = gradient(p2)``` gradient can contain more than two colors, in which case ```gradient (p)``` returns a color that is interpolated between two colors with positions ```p1``` and ```p2``` such that ```p1 < p < p2``` (see usage) ## Input Array of colors in RGB format and its positions ```[[r, g, b], position]``` ```r```, ```g```, ```b``` - float numbers from 0 to 255 ```position``` - float number from 0 to 1 ## Output Function that map float ```number``` in range ```[0, 1]``` to color ```[r, g, b]```. ```r```, ```g``` and ```b``` is a float numbers <br /> if there is no color with the position ```p < number``` return the color with the lowest position<br /> if there is no color with the position ```p > number``` return the color with the highest position<br /> if two or more colors has a same position take last <br /> if array is empty gradient must return ```[0, 0, 0]``` ## Usage ![](https://assets.hongkiat.com/uploads/css3-linear-gradient/gradient-rainbow.jpg) ```javascript // red, yellow, green, etc. - [r,g,b] arrays // for example red = [255, 0, 0] let rainbowGradient = createGradient([ [red, 0], [yellow, 0.2], [green, 0.4], [blue, 0.8], [violet, 1] ]) // from 0 to 0.2 gradient between red and yellow rainbowGradient(0.1) // orange = [255, 127, 0] // from 0.4 to 0.8 gradient between green and blue rainbowGradient(0.6) // [0, 127, 127] ```
algorithms
from itertools import groupby def create_gradient(colors): col_grad = sorted(colors, key=lambda x: x[1]) col_grad = [[* g][- 1] for k, g in groupby(col_grad, key=lambda x: x[1])] def lin_grad(pos): if not col_grad: return [0, 0, 0] ind = next((k for k, x in enumerate(col_grad) if x[1] >= pos), len(col_grad)) if ind == len(col_grad): return col_grad[len(col_grad) - 1][0] elif ind == 0 or col_grad[ind][1] == pos: return col_grad[ind][0] else: (y1, x1), (y2, x2) = col_grad[ind - 1], col_grad[ind] aplha = (x2 - pos) / (x2 - x1) return [aplha * a + (1 - aplha) * b for a, b in zip(y1, y2)] return lin_grad
Linear Color Gradient
607218fd3d84d3003685d78c
[ "Algorithms" ]
https://www.codewars.com/kata/607218fd3d84d3003685d78c
6 kyu
*Challenge taken from the [code.golf](https://code.golf/12-days-of-christmas) site* Return the lyrics of the song [The Twelve Days of Christmas](https://en.wikipedia.org/wiki/The_Twelve_Days_of_Christmas_(song)): ``` On the First day of Christmas My true love sent to me A partridge in a pear tree. On the Second day of Christmas My true love sent to me Two turtle doves, and A partridge in a pear tree. ... On the Twelfth day of Christmas My true love sent to me Twelve drummers drumming, Eleven pipers piping, Ten lords a-leaping, Nine ladies dancing, Eight maids a-milking, Seven swans a-swimming, Six geese a-laying, Five gold rings, Four calling birds, Three French hens, Two turtle doves, and A partridge in a pear tree. ``` ```if:python,javascript Your code can be maximum 510 ~~characters~~ bytes long. Oh, and no imports, please! ``` ```if:ruby Your code can be maximum 500 ~~characters~~ bytes long. Oh, and no imports, please! ``` ```if:haskell Your code can be a maximum of 534 characters long (510 characters, plus the module declaration). And no imports please! ``` ```if:c Your code can be maximum 610 characters long. ``` --- ### My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/users/anter69/authored)! :-) #### *Translations are welcome!*
games
A = """Twelve drummers drumming, Eleven pipers piping, Ten lords a-leaping, Nine ladies dancing, Eight maids a-milking, Seven swans a-swimming, Six geese a-laying, Five gold rings, Four calling birds, Three French hens, Two turtle doves, and A partridge in a pear tree.""" . split("\n") B = "First,Second,Third,Fourth,Fifth,Sixth,Seventh,Eighth,Ninth,Tenth,Eleventh,Twelfth" . split( ",") def f(): return "\n\n" . join( f"On the { B [ i ]} day of Christmas\nMy true love sent to me\n" + "\n" . join(A[- i - 1:]) for i in range(12))
[Code Golf] The Twelve Days of Christmas
6001a06c6aad37000873b48f
[ "Restricted", "Puzzles" ]
https://www.codewars.com/kata/6001a06c6aad37000873b48f
6 kyu
Reverse Number is a number which is the same when reversed. For example, the first 20 Reverse Numbers are: ``` 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101 ``` ```if:php In PHP, the parameter `$n` will be passed to the function `find_reverse_number` as a string, and the result should be returned as a string, as PHP has trouble with quite large integers. ``` **TASK:** - You need to return the nth reverse number. (Assume that reverse numbers start from 0 as shown in the example.) **NOTES:** * 1 < n <= 100000000000 ```if:javascript * You need to use BigInt as return type in JS since it exceeds max integer size. **If this is too hard, you can try https://www.codewars.com/kata/600bfda8a4982600271d6069** ```if:rust * 1 < n <= 10000000000 ```
algorithms
def find_reverse_number(n): """ Return the nth number in sequence of reversible numbers. For reversible numbers, a pattern emerges when compared to n: if we subtract a number made of a sequence of the digit 9 (i.e. 9, 99, 999, our magic number) from n, the result forms the left half of the nth reversible number starting from 0. The number of digits "9" in the magic number increases every time n reaches an order of magnitude of the number 11; the width of that order of magnitude is the width of the magic number. That width also tells us how many digits of the left half must be mirrored to form the final, nth reversible number. Examples (_ digits get mirrored, | digits remain static) n = 109 -> 100 -> 1001 -9 _|| _||_ n = 110 -> 11 -> 1111 -99 __ ____ n = 1099 -> 1000 -> 100001 -99 __|| __||__ n = 1100 -> 101 -> 101101 -999 ___ ______ """ n = n - 1 # this kata assumes 1-based indices if n < 10: # tiny optimization return n x = n / / 11 # order of magnitude width = len(str(x)) # width of x nines = int("9" * width) # the magic number lh = str(n - nines) # the left side of the result rh = lh[: width][:: - 1] # the right side of the result result = int(lh + rh) return result
Find the nth Reverse Number (Extreme)
600c18ec9f033b0008d55eec
[ "Algorithms" ]
https://www.codewars.com/kata/600c18ec9f033b0008d55eec
4 kyu
Reverse Number is a number which is the same when reversed. For Example; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101 => First 20 Reverse Numbers **TASK:** - You need to return the nth reverse number. (Assume that reverse numbers start from 0 as shown in the example.) **NOTES:** * 0 < n <= 1000000 **If this is too easy, you can try https://www.codewars.com/kata/600c18ec9f033b0008d55eec**
algorithms
from itertools import count memo = [] def palgen(): yield 0 for digits in count(1): first = 10 * * ((digits - 1) / / 2) for s in map(str, range(first, 10 * first)): yield int(s + s[- (digits % 2) - 1:: - 1]) def gen_memo(): global memo for n in palgen(): memo . append(n) if len(memo) > 1000000: break def find_reverse_number(n): global memo if memo == []: gen_memo() return memo[n - 1]
Find the nth Reverse Number
600bfda8a4982600271d6069
[ "Algorithms" ]
https://www.codewars.com/kata/600bfda8a4982600271d6069
6 kyu
## Problem All integers can be uniquely expressed as a sum of powers of 3 using each power of 3 **at most once**. For example: ```python 17 = (-1) + 0 + (-9) + 27 = (-1 * 3^0) + ( 0 * 3^1) + (-1 * 3^2) + (1 * 3^3) -8 = 1 + 0 + (-9) = ( 1 * 3^0) + ( 0 * 3^1) + (-1 * 3^2) 25 = 1 + (-3) + 0 + 27 = ( 1 * 3^0) + (-1 * 3^1) + ( 0 * 3^2) + (1 * 3^3) ``` We can use the string `+-0+` to represent 25 as the sum of powers of 3: ```python Symbols : "+" "-" "0" "+" Powers of 3 : 1 3 9 27 Values : 1 -3 0 27 ``` Given an integer `n` (not necessarily strictly positive), we want to write a function that expresses `n` as a sum of powers of 3 using the symbols `-0+`: ```python n = 17 -> "-0-+" n = -8 -> "+0-" ``` Note: The last symbol in the solution string represents the largest power of 3 used (added `+` or subtracted `-`) and will never be `0`, except if the integer is `0` itself.
reference
def as_sum_of_powers_of_3(n): if not n: return '0' r = '' while n != 0: k = n % 3 r += '0+-' [k] if k == 2: k = - 1 n = (n - k) / / 3 return r
Expressing Integers as Sum of Powers of Three
6012457c0aa675001d4d560b
[ "Fundamentals" ]
https://www.codewars.com/kata/6012457c0aa675001d4d560b
6 kyu
Ryomen Sukuna has entered your body, and he will only leave if you can solve this problem. Given an integer `n`, how many integers between `1` and `n` (inclusive) are unrepresentable as `$a^b$`, where `$a$` and `$b$` are integers not less than 2? Example: if `n` equals 10 then output must be 7, as 4 is representable as 2<sup>2</sup>, 8 as 2<sup>3</sup> and 9 as 3<sup>2</sup>. So the numbers left are 1, 2, 3, 5, 6, 7 and 10. Note: Optimize your solution for `n` as large as 10<sup>10</sup>.
reference
def sukuna(n): all_numbers, square = set(), int(n * * .5) + 1 for i in range(2, square): for j in range(2, square): if i * * j <= n: all_numbers . add(i * * j) else: break return n - len(all_numbers)
Ryomen Sukuna
607a8f270f09ea003a38369c
[ "Mathematics", "Fundamentals" ]
https://www.codewars.com/kata/607a8f270f09ea003a38369c
6 kyu
# Convert Lambda To Def in this kata, you will be given a string with a lambda function in it. Your task is to convert that lambda function to a def function, with the exact same variables, the exact same name, and the exact same function it does. The function, like a normal `def` function should be returned on a separate line. The output should be returned as a string. # Examples given an input of: ```python "func = lambda a: a * 1" ``` The output expected would be: ```python """ def func(a): return a * 1 """ ``` the code would be like so: ```python convert_lambda_to_def("func = lambda a: a * 1") # the output should == "def func(a):\n return a * 1" ``` you need to put 4 four spaces before the `return` part of your output. variable numbers of spaces, positional/keyword arguments, or zero arguments will not be tested. double parameters will not be tested Happy Coding! _If you liked this, you can also check out the opposite of this kata: [Convert Def To Lambda](https://www.codewars.com/kata/60b3d25bcfaf610006e3b909)_
reference
def convert_lambda_to_def(s): sheet = 'def {}({}):\n return{}' s = s . replace(' = lambda ', ':') name, arg, ret = s . split(':', 2) return sheet . format(name, arg, ret)
Convert Lambda To Def
605d25f4f24c030033da9afb
[ "Fundamentals", "Strings", "Regular Expressions" ]
https://www.codewars.com/kata/605d25f4f24c030033da9afb
6 kyu
## Task You are looking for teammates for an oncoming intellectual game in which you will have to answer some questions. It is known that each question belongs to one of the `n` categories. A team is called perfect if for each category there is at least one team member who knows it perfectly. You don't know any category well enough, but you are going to build a perfect team. You consider several candidates, and you are aware of the categories each of them knows perfectly. There is no restriction on the team size, but smaller teams gain additional bonus points. Thus, you want to build a perfect team of minimal possible size. Find this size (and don't forget to count yourself!) or determine that it is impossible to form a perfect team from the candidates you have. ## Input/Output `[input]` integer `n` representing the number of categories `1 ≤ n ≤ 10.` `[input]` 2D integer array `candidates` For each valid `i`, `candidates[i]` is an array of different integers representing indices of the categories which the i<sup>th</sup> candidate knows perfectly. `0 ≤ candidates.length ≤ 10,` `0 ≤ candidates[i].length < n,` `0 ≤ candidates[i][j] < n.` `[output]` an integer The minimal possible size of the perfect team, or `-1` ( or `Nothing` or a similar empty value ) if you can't build it. ## Example For `n = 3` and ``` candidates = [[0, 2], [1, 2], [0, 1], [0]] the output should be 3. You can build a perfect team of size 3 in any of the following ways: yourself, candidate number 1 (1-based) and candidate number 2 [] + [0, 2] + [1, 2] = [0, 1, 2] yourself, candidate number 1 and candidate number 3 [] + [0, 2] + [0, 1] = [0, 1, 2] yourself, candidate number 2 and candidate number 3 [] + [1, 2] + [0, 1] = [0, 1, 2] yourself, candidate number 2 and candidate number 4 [] + [1, 2] + [0] = [0, 1, 2] ```
algorithms
from itertools import combinations def perfect_team_of_minimal_size(n, candidates): for j in range(1, len(candidates) + 1): if any(len(set(sum(i, []))) >= n for i in combinations(candidates, j)): return j + 1 return - 1
Simple Fun #243: Perfect Team Of MinimalSize
590a924c7dfc1a238d000047
[ "Algorithms" ]
https://www.codewars.com/kata/590a924c7dfc1a238d000047
6 kyu
# Description Your task is to create a class `Function`, that will be provided with 2 arguments - `f` & `df` - representing a function and its derivative. You should be able to do function algebra with this class, i.e. they can be added, subtracted, multiplied, divided and composed to give another `Function` object with a valid function and a derivative. When the function is called, it must have a optional `grad` argument. The functions will be called with only one argument. If then function is called without the `grad` argument, return the value of the function, and if `grad = True`, return the value of its derivative. The class should behave like given below: ```py square = Function(lambda x: x**2, lambda x: 2*x) identity = Function(lambda x: x, lambda x: 1) square(1) # => 1 square(1, grad = True) # => 2 ``` The class should also exibit these behaviours: ```py f = square + identity f(1) # => 2 f(1, grad = True) # => 3 g = square - identity g(1) # => 0 g(1, grad = True) # => 1 h = square * identity h(1) # => 1 h(1, grad = True) # => 3 i = square / identity i(1) # => 1 i(1, grad = True) # => 1 j = square @ identity # f @ g means f(g(x)) j(1) # => 1 j(1, grad = True) # => 2 ``` Have fun!
reference
class Function: def __init__(self, f, df): self . f = f self . df = df def __add__(self, other): def f(x): return self . f(x) + other . f(x) def df(x): return self . df(x) + other . df(x) return Function(f, df) def __sub__(self, other): def f(x): return self . f(x) - other . f(x) def df(x): return self . df(x) - other . df(x) return Function(f, df) def __mul__(self, other): def f(x): return self . f(x) * other . f(x) def df(x): return self . df(x) * other . f(x) + self . f(x) * other . df(x) return Function(f, df) def __truediv__(self, other): def f(x): return self . f(x) / other . f(x) def df(x): return (self . df(x) * other . f(x) - self . f(x) * other . df(x)) / other . f(x) * * 2 return Function(f, df) def __matmul__(self, other): def f(x): return self . f(other . f(x)) def df(x): return other . df(x) * self . df(other . f(x)) return Function(f, df) def __call__(self, x, grad=False): return (self . f, self . df)[grad](x)
Function Algebra
605f4035f38ca800072b6d06
[ "Fundamentals", "Mathematics" ]
https://www.codewars.com/kata/605f4035f38ca800072b6d06
5 kyu
<h1><u>Gangs</u></h1> <p>Your math teacher is proposing a game with divisors, so that you can understand it better. The teacher gives you a <u>list of divisors</u> and a number <u>k</u>. You should find all the gangs in the range 1 to k.</p> <h4><u>What is a gang?</u></h4> <p>The numbers, which have the same subset of divisors from the list, form a gang. The gang can have any number of members. Any number from the range can only be in one gang. You are given the <u>list of divisors</u> as the first argument and the number <u>k</u> as the second argument.</p> <h4><u>Task</u></h4> <p>Find how many gangs can be formed from numbers in range from 1 to k.</p> <h4><u>Example</u></h4> <pre> Gangs([2, 3], 6) => 4 Gangs([2, 3, 6, 5], 15) => 7 </pre> <h4><u>Explanation</u></h4> <p>The first example:<br> The numbers 1 and 5 form a gang because they don't have divisors in [2,3].<br> The 2 and 4 form a gang because they both share the subset [2] from [2,3].<br> The number 3 has subset [3] from [2,3] (forms a gang by itself).<br> The number 6 has subset [2,3] from [2,3] (also forms a gang on its own).<br> Thus, the numbers 1 through 6 are split into 4 gangs: (1,5), (2,4), (3), (6).</p> <p>In the same manner, for second example the gangs are: (1,7,11,13), (2,4,8,14), (3,9), (5), (6,12), (10), (15).</p>
reference
def gangs(divisors, k): return len({tuple(y for y in divisors if x % y == 0) for x in range(1, k + 1)})
Gangs
60490a215465720017ab58fa
[ "Algorithms", "Fundamentals" ]
https://www.codewars.com/kata/60490a215465720017ab58fa
6 kyu
### Task Given three sides `a`, `b` and `c`, determine if a triangle can be built out of them. ### Code limit Your code can be up to `40` characters long. ### Note Degenerate triangles are not valid in this kata.
games
triangle = lambda * a: 2 * max(a) < sum(a)
[Code Golf] A Triangle?
60d20fe1820f1b004188ceed
[ "Puzzles", "Restricted" ]
https://www.codewars.com/kata/60d20fe1820f1b004188ceed
7 kyu
You have a function that takes an integer `n` and returns a list of length `n` of function objects that take an integer `x` and return `x` multiplied by the index of that object in this list(remember that in python the indexes of elements start from 0): ```python [f_0, f_1, ... f_n] ``` ``` f_0 returns x * 0, f_1 returns x * 1, ... f_n returns x * n, ``` ```python def create_multiplications(n): return [lambda x : i * x for i in range(n)] ``` This code: ```python for m in create_multiplications(3): print(m(3), ' ... ') ``` should output: ```python >>> 0 ... 3 ... 6 ... ``` But it outputs: ```python >>> 6 ... 6 ... 6 ... ``` You need to fix this bug. ## Input/Output All inputs will be integers, output must be list of `function` objects. #### Good luck! # Please rate this kata.
bug_fixes
def create_multiplications(l): return [lambda x, i=i: i * x for i in range(l)]
Bugs with late binding closure
60b775debec5c40055657733
[ "Debugging" ]
https://www.codewars.com/kata/60b775debec5c40055657733
6 kyu
## Task A list S will be given. You need to generate a list T from it by following the given process: 1) Remove the first and last element from the list S and add them to the list T. 2) Reverse the list S 3) Repeat the process until list S gets emptied. The above process results in the depletion of the list S. Your task is to generate list T **without mutating** the input List S. ## Example ``` S = [1,2,3,4,5,6] T = [] S = [2,3,4,5] => [5,4,3,2] T = [1,6] S = [4,3] => [3,4] T = [1,6,5,2] S = [] T = [1,6,5,2,3,4] return T ``` ## Note ```if:d * size of S goes up to `300,000` * Keep the efficiency of your code in mind. ``` ```if-not:bf,d * size of S goes up to `10^6` * Keep the efficiency of your code in mind. * Do not mutate the Input. ``` ```if:bf * Input will be a string * 1<=Input string length<100 * The Input will consist of alphabets (Upper and lowercase), Numbers and special characters. * The input will be terminated with a null character for EOF. ```
reference
from collections import deque def arrange(s): q = deque(s) return [q . pop() if 0 < i % 4 < 3 else q . popleft() for i in range(len(s))]
Back and forth then Reverse!
60cc93db4ab0ae0026761232
[ "Algorithms", "Performance", "Arrays" ]
https://www.codewars.com/kata/60cc93db4ab0ae0026761232
6 kyu
## How does an abacus work? An abacus is a mechanical tool for counting and performing simple mathematical operations. It consists of vertical poles with beads, where the position of the beads indicates the value stored on the abacus. The abacus in the image below, for example, is storing the number `1703`. <svg viewBox="79.929 79.544 371.217 201.419" width="371.217" height="201.419"> <linearGradient id="gradient-1" gradientUnits="userSpaceOnUse" x1="285.5996" y1="828.5994" x2="309.5996" y2="828.5994" gradientTransform="matrix(0.208638, 0, 0, -0.183017, 121.164387, 331.900299)"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0309" style="stop-color:#A46309"></stop> <stop offset="0.0816" style="stop-color:#B27922"></stop> <stop offset="0.146" style="stop-color:#C99D4A"></stop> <stop offset="0.2207" style="stop-color:#E9CF82"></stop> <stop offset="0.2527" style="stop-color:#F8E69C"></stop> <stop offset="0.3748" style="stop-color:#D0AD68"></stop> <stop offset="0.4952" style="stop-color:#AD7C3B"></stop> <stop offset="0.6004" style="stop-color:#94581B"></stop> <stop offset="0.6861" style="stop-color:#854307"></stop> <stop offset="0.7418" style="stop-color:#7F3B00"></stop> <stop offset="1" style="stop-color:#5F3D00"></stop> </linearGradient> <linearGradient id="gradient-14" gradientUnits="userSpaceOnUse" x1="285.5996" y1="828.5994" x2="309.5996" y2="828.5994" gradientTransform="matrix(0.208638, 0, 0, -0.183017, 80.002743, 331.913208)"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0309" style="stop-color:#A46309"></stop> <stop offset="0.0816" style="stop-color:#B27922"></stop> <stop offset="0.146" style="stop-color:#C99D4A"></stop> <stop offset="0.2207" style="stop-color:#E9CF82"></stop> <stop offset="0.2527" style="stop-color:#F8E69C"></stop> <stop offset="0.3748" style="stop-color:#D0AD68"></stop> <stop offset="0.4952" style="stop-color:#AD7C3B"></stop> <stop offset="0.6004" style="stop-color:#94581B"></stop> <stop offset="0.6861" style="stop-color:#854307"></stop> <stop offset="0.7418" style="stop-color:#7F3B00"></stop> <stop offset="1" style="stop-color:#5F3D00"></stop> </linearGradient> <linearGradient id="gradient-27" gradientUnits="userSpaceOnUse" x1="285.5996" y1="828.5994" x2="309.5996" y2="828.5994" gradientTransform="matrix(0.208638, 0, 0, -0.183017, 162.398792, 331.851501)"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0309" style="stop-color:#A46309"></stop> <stop offset="0.0816" style="stop-color:#B27922"></stop> <stop offset="0.146" style="stop-color:#C99D4A"></stop> <stop offset="0.2207" style="stop-color:#E9CF82"></stop> <stop offset="0.2527" style="stop-color:#F8E69C"></stop> <stop offset="0.3748" style="stop-color:#D0AD68"></stop> <stop offset="0.4952" style="stop-color:#AD7C3B"></stop> <stop offset="0.6004" style="stop-color:#94581B"></stop> <stop offset="0.6861" style="stop-color:#854307"></stop> <stop offset="0.7418" style="stop-color:#7F3B00"></stop> <stop offset="1" style="stop-color:#5F3D00"></stop> </linearGradient> <linearGradient id="gradient-40" gradientUnits="userSpaceOnUse" x1="285.5996" y1="828.5994" x2="309.5996" y2="828.5994" gradientTransform="matrix(0.208638, 0, 0, -0.183017, 203.760746, 331.851807)"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0309" style="stop-color:#A46309"></stop> <stop offset="0.0816" style="stop-color:#B27922"></stop> <stop offset="0.146" style="stop-color:#C99D4A"></stop> <stop offset="0.2207" style="stop-color:#E9CF82"></stop> <stop offset="0.2527" style="stop-color:#F8E69C"></stop> <stop offset="0.3748" style="stop-color:#D0AD68"></stop> <stop offset="0.4952" style="stop-color:#AD7C3B"></stop> <stop offset="0.6004" style="stop-color:#94581B"></stop> <stop offset="0.6861" style="stop-color:#854307"></stop> <stop offset="0.7418" style="stop-color:#7F3B00"></stop> <stop offset="1" style="stop-color:#5F3D00"></stop> </linearGradient> <linearGradient id="gradient-53" gradientUnits="userSpaceOnUse" x1="285.5996" y1="828.5994" x2="309.5996" y2="828.5994" gradientTransform="matrix(0.208638, 0, 0, -0.183017, 286.398762, 331.93808)"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0309" style="stop-color:#A46309"></stop> <stop offset="0.0816" style="stop-color:#B27922"></stop> <stop offset="0.146" style="stop-color:#C99D4A"></stop> <stop offset="0.2207" style="stop-color:#E9CF82"></stop> <stop offset="0.2527" style="stop-color:#F8E69C"></stop> <stop offset="0.3748" style="stop-color:#D0AD68"></stop> <stop offset="0.4952" style="stop-color:#AD7C3B"></stop> <stop offset="0.6004" style="stop-color:#94581B"></stop> <stop offset="0.6861" style="stop-color:#854307"></stop> <stop offset="0.7418" style="stop-color:#7F3B00"></stop> <stop offset="1" style="stop-color:#5F3D00"></stop> </linearGradient> <linearGradient id="gradient-56" gradientUnits="userSpaceOnUse" x1="285.5996" y1="828.5994" x2="309.5996" y2="828.5994" gradientTransform="matrix(0.208638, 0, 0, -0.183017, 245.23711, 331.950989)"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0309" style="stop-color:#A46309"></stop> <stop offset="0.0816" style="stop-color:#B27922"></stop> <stop offset="0.146" style="stop-color:#C99D4A"></stop> <stop offset="0.2207" style="stop-color:#E9CF82"></stop> <stop offset="0.2527" style="stop-color:#F8E69C"></stop> <stop offset="0.3748" style="stop-color:#D0AD68"></stop> <stop offset="0.4952" style="stop-color:#AD7C3B"></stop> <stop offset="0.6004" style="stop-color:#94581B"></stop> <stop offset="0.6861" style="stop-color:#854307"></stop> <stop offset="0.7418" style="stop-color:#7F3B00"></stop> <stop offset="1" style="stop-color:#5F3D00"></stop> </linearGradient> <linearGradient id="gradient-59" gradientUnits="userSpaceOnUse" x1="285.5996" y1="828.5994" x2="309.5996" y2="828.5994" gradientTransform="matrix(0.208638, 0, 0, -0.183017, 327.633167, 331.889282)"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0309" style="stop-color:#A46309"></stop> <stop offset="0.0816" style="stop-color:#B27922"></stop> <stop offset="0.146" style="stop-color:#C99D4A"></stop> <stop offset="0.2207" style="stop-color:#E9CF82"></stop> <stop offset="0.2527" style="stop-color:#F8E69C"></stop> <stop offset="0.3748" style="stop-color:#D0AD68"></stop> <stop offset="0.4952" style="stop-color:#AD7C3B"></stop> <stop offset="0.6004" style="stop-color:#94581B"></stop> <stop offset="0.6861" style="stop-color:#854307"></stop> <stop offset="0.7418" style="stop-color:#7F3B00"></stop> <stop offset="1" style="stop-color:#5F3D00"></stop> </linearGradient> <linearGradient id="gradient-62" gradientUnits="userSpaceOnUse" x1="285.5996" y1="828.5994" x2="309.5996" y2="828.5994" gradientTransform="matrix(0.208638, 0, 0, -0.183017, 368.995106, 331.889587)"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0309" style="stop-color:#A46309"></stop> <stop offset="0.0816" style="stop-color:#B27922"></stop> <stop offset="0.146" style="stop-color:#C99D4A"></stop> <stop offset="0.2207" style="stop-color:#E9CF82"></stop> <stop offset="0.2527" style="stop-color:#F8E69C"></stop> <stop offset="0.3748" style="stop-color:#D0AD68"></stop> <stop offset="0.4952" style="stop-color:#AD7C3B"></stop> <stop offset="0.6004" style="stop-color:#94581B"></stop> <stop offset="0.6861" style="stop-color:#854307"></stop> <stop offset="0.7418" style="stop-color:#7F3B00"></stop> <stop offset="1" style="stop-color:#5F3D00"></stop> </linearGradient> <linearGradient id="gradient-105" gradientUnits="userSpaceOnUse" x1="285.5996" y1="828.5994" x2="309.5996" y2="828.5994" gradientTransform="matrix(0.208638, 0, 0, -0.183017, 38.702137, 331.93869)"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0309" style="stop-color:#A46309"></stop> <stop offset="0.0816" style="stop-color:#B27922"></stop> <stop offset="0.146" style="stop-color:#C99D4A"></stop> <stop offset="0.2207" style="stop-color:#E9CF82"></stop> <stop offset="0.2527" style="stop-color:#F8E69C"></stop> <stop offset="0.3748" style="stop-color:#D0AD68"></stop> <stop offset="0.4952" style="stop-color:#AD7C3B"></stop> <stop offset="0.6004" style="stop-color:#94581B"></stop> <stop offset="0.6861" style="stop-color:#854307"></stop> <stop offset="0.7418" style="stop-color:#7F3B00"></stop> <stop offset="1" style="stop-color:#5F3D00"></stop> </linearGradient> <linearGradient id="gradient-106" gradientUnits="userSpaceOnUse" x1="297.6006" y1="278.5994" x2="297.6006" y2="398.5994" gradientTransform="matrix(1.856105, 0, 0, -0.183017, -286.843868, 331.93869)"> <stop offset="0.3681" style="stop-color:#000000"></stop> <stop offset="0.4331" style="stop-color:#050505"></stop> <stop offset="0.5099" style="stop-color:#131313"></stop> <stop offset="0.5926" style="stop-color:#2B2B2B"></stop> <stop offset="0.6797" style="stop-color:#4C4C4C"></stop> <stop offset="0.77" style="stop-color:#777777"></stop> <stop offset="0.8632" style="stop-color:#ACACAC"></stop> <stop offset="0.9569" style="stop-color:#E8E8E8"></stop> <stop offset="0.989" style="stop-color:#FFFFFF"></stop> <stop offset="0.9901" style="stop-color:#DBDBDB"></stop> <stop offset="0.9922" style="stop-color:#999999"></stop> <stop offset="0.9941" style="stop-color:#636363"></stop> <stop offset="0.996" style="stop-color:#383838"></stop> <stop offset="0.9976" style="stop-color:#191919"></stop> <stop offset="0.999" style="stop-color:#070707"></stop> <stop offset="1" style="stop-color:#000000"></stop> </linearGradient> <linearGradient id="gradient-107" gradientUnits="userSpaceOnUse" x1="297.5996" y1="1378.0994" x2="297.5996" y2="1229.0994" gradientTransform="matrix(1.854086, 0, 0, -0.183017, -286.444973, 331.93869)"> <stop offset="0" style="stop-color:#000000"></stop> <stop offset="0.011" style="stop-color:#FFFFFF"></stop> <stop offset="0.1106" style="stop-color:#D0D0D0"></stop> <stop offset="0.2419" style="stop-color:#9A9A9A"></stop> <stop offset="0.3745" style="stop-color:#6B6B6B"></stop> <stop offset="0.5055" style="stop-color:#444444"></stop> <stop offset="0.6346" style="stop-color:#262626"></stop> <stop offset="0.7613" style="stop-color:#111111"></stop> <stop offset="0.8844" style="stop-color:#040404"></stop> <stop offset="1" style="stop-color:#000000"></stop> </linearGradient> <rect x="180.751" y="79.593" fill="url(#gradient-1)" stroke="#F2F2F2" width="5.007" height="201.319" style=""></rect> <g transform="matrix(0.208638, 0, 0, 0.183017, 162.391083, 79.501076)" style=""> <radialGradient id="gradient-3" cx="156.3662" cy="484.2776" r="205.1986" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-3)" stroke="#F2F2F2" points="88.601,860.5 5,920.5 195,920.5 111.404,860.5 "></polygon> <radialGradient id="gradient-4" cx="452.9785" cy="423.26" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-4)" stroke="#F2F2F2" points="111.404,980.5 195,920.5 5,920.5 88.601,980.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 162.391083, 79.501076)" style=""> <radialGradient id="gradient-5" cx="156.3672" cy="592.2791" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-5)" stroke="#F2F2F2" points="88.601,740.5 5,800.5 195,800.5 111.404,740.5 "></polygon> <radialGradient id="gradient-6" cx="452.9785" cy="531.26" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-6)" stroke="#F2F2F2" points="111.404,860.5 195,800.5 5,800.5 88.601,860.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 162.391083, 79.501076)" style=""> <radialGradient id="gradient-7" cx="156.3672" cy="700.2781" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-7)" stroke="#F2F2F2" points="88.601,620.5 5,680.5 195,680.5 111.404,620.5 "></polygon> <radialGradient id="gradient-8" cx="452.9785" cy="639.2625" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-8)" stroke="#F2F2F2" points="111.404,740.5 195,680.5 5,680.5 88.601,740.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 162.391083, 79.501076)" style=""> <radialGradient id="gradient-9" cx="156.3672" cy="808.281" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-9)" stroke="#F2F2F2" points="88.601,500.5 5,560.5 195,560.5 111.404,500.5 "></polygon> <radialGradient id="gradient-10" cx="452.9785" cy="747.2644" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-10)" stroke="#F2F2F2" points="111.404,620.5 195,560.5 5,560.5 88.601,620.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 162.391083, 79.501076)" style=""> <radialGradient id="gradient-11" cx="156.3672" cy="1123.2849" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-11)" stroke="#F2F2F2" points="88.602,150.5 5,210.5 195,210.5 111.404,150.5 "></polygon> <radialGradient id="gradient-12" cx="452.9785" cy="1062.2664" r="196.6118" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-12)" stroke="#F2F2F2" points="111.404,270.5 195,210.5 5,210.5 88.601,270.5 "></polygon> </g> <rect x="139.59" y="79.606" fill="url(#gradient-14)" stroke="#F2F2F2" width="5.007" height="201.319" style=""></rect> <g transform="matrix(0.208638, 0, 0, 0.183017, 121.229454, 79.513977)" style=""> <radialGradient id="gradient-17" cx="156.3662" cy="484.2776" r="205.1986" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-17)" stroke="#F2F2F2" points="88.601,860.5 5,920.5 195,920.5 111.404,860.5 "></polygon> <radialGradient id="gradient-18" cx="452.9785" cy="423.26" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-18)" stroke="#F2F2F2" points="111.404,980.5 195,920.5 5,920.5 88.601,980.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 121.229454, 79.513977)" style=""> <radialGradient id="gradient-19" cx="156.3672" cy="592.2791" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-19)" stroke="#F2F2F2" points="88.601,740.5 5,800.5 195,800.5 111.404,740.5 "></polygon> <radialGradient id="gradient-20" cx="452.9785" cy="531.26" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-20)" stroke="#F2F2F2" points="111.404,860.5 195,800.5 5,800.5 88.601,860.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 121.229454, 79.513977)" style=""> <radialGradient id="gradient-21" cx="156.3672" cy="700.2781" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-21)" stroke="#F2F2F2" points="88.601,620.5 5,680.5 195,680.5 111.404,620.5 "></polygon> <radialGradient id="gradient-22" cx="452.9785" cy="639.2625" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-22)" stroke="#F2F2F2" points="111.404,740.5 195,680.5 5,680.5 88.601,740.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 121.229454, 79.513977)" style=""> <radialGradient id="gradient-23" cx="156.3672" cy="808.281" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-23)" stroke="#F2F2F2" points="88.601,500.5 5,560.5 195,560.5 111.404,500.5 "></polygon> <radialGradient id="gradient-24" cx="452.9785" cy="747.2644" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-24)" stroke="#F2F2F2" points="111.404,620.5 195,560.5 5,560.5 88.601,620.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 121.229454, 79.513977)" style=""> <radialGradient id="gradient-25" cx="156.3672" cy="1123.2849" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-25)" stroke="#F2F2F2" points="88.602,150.5 5,210.5 195,210.5 111.404,150.5 "></polygon> <radialGradient id="gradient-26" cx="452.9785" cy="1062.2664" r="196.6118" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-26)" stroke="#F2F2F2" points="111.404,270.5 195,210.5 5,210.5 88.601,270.5 "></polygon> </g> <rect x="221.986" y="79.544" fill="url(#gradient-27)" stroke="#F2F2F2" width="5.007" height="201.319" style=""></rect> <g transform="matrix(0.208638, 0, 0, 0.183017, 203.625519, 79.452286)" style=""> <radialGradient id="gradient-30" cx="156.3662" cy="484.2776" r="205.1986" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-30)" stroke="#F2F2F2" points="88.601,860.5 5,920.5 195,920.5 111.404,860.5 "></polygon> <radialGradient id="gradient-31" cx="452.9785" cy="423.26" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-31)" stroke="#F2F2F2" points="111.404,980.5 195,920.5 5,920.5 88.601,980.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 203.625519, 79.452286)" style=""> <radialGradient id="gradient-32" cx="156.3672" cy="592.2791" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-32)" stroke="#F2F2F2" points="88.601,740.5 5,800.5 195,800.5 111.404,740.5 "></polygon> <radialGradient id="gradient-33" cx="452.9785" cy="531.26" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-33)" stroke="#F2F2F2" points="111.404,860.5 195,800.5 5,800.5 88.601,860.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 203.625519, 79.452286)" style=""> <radialGradient id="gradient-34" cx="156.3672" cy="700.2781" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-34)" stroke="#F2F2F2" points="88.601,620.5 5,680.5 195,680.5 111.404,620.5 "></polygon> <radialGradient id="gradient-35" cx="452.9785" cy="639.2625" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-35)" stroke="#F2F2F2" points="111.404,740.5 195,680.5 5,680.5 88.601,740.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 203.625519, 79.452286)" style=""> <radialGradient id="gradient-36" cx="156.3672" cy="808.281" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-36)" stroke="#F2F2F2" points="88.601,500.5 5,560.5 195,560.5 111.404,500.5 "></polygon> <radialGradient id="gradient-37" cx="452.9785" cy="747.2644" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-37)" stroke="#F2F2F2" points="111.404,620.5 195,560.5 5,560.5 88.601,620.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 203.625519, 79.452286)" style=""> <radialGradient id="gradient-38" cx="156.3672" cy="1123.2849" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-38)" stroke="#F2F2F2" points="88.602,150.5 5,210.5 195,210.5 111.404,150.5 "></polygon> <radialGradient id="gradient-39" cx="452.9785" cy="1062.2664" r="196.6118" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-39)" stroke="#F2F2F2" points="111.404,270.5 195,210.5 5,210.5 88.601,270.5 "></polygon> </g> <rect x="263.348" y="79.545" fill="url(#gradient-40)" stroke="#F2F2F2" width="5.007" height="201.319" style=""></rect> <g transform="matrix(0.208638, 0, 0, 0.183017, 244.987473, 79.452583)" style=""> <radialGradient id="gradient-43" cx="156.3662" cy="484.2776" r="205.1986" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-43)" stroke="#F2F2F2" points="88.601,860.5 5,920.5 195,920.5 111.404,860.5 "></polygon> <radialGradient id="gradient-44" cx="452.9785" cy="423.26" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-44)" stroke="#F2F2F2" points="111.404,980.5 195,920.5 5,920.5 88.601,980.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 244.987473, 79.452583)" style=""> <radialGradient id="gradient-45" cx="156.3672" cy="592.2791" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-45)" stroke="#F2F2F2" points="88.601,740.5 5,800.5 195,800.5 111.404,740.5 "></polygon> <radialGradient id="gradient-46" cx="452.9785" cy="531.26" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-46)" stroke="#F2F2F2" points="111.404,860.5 195,800.5 5,800.5 88.601,860.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 244.987473, 79.452583)" style=""> <radialGradient id="gradient-47" cx="156.3672" cy="700.2781" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-47)" stroke="#F2F2F2" points="88.601,620.5 5,680.5 195,680.5 111.404,620.5 "></polygon> <radialGradient id="gradient-48" cx="452.9785" cy="639.2625" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-48)" stroke="#F2F2F2" points="111.404,740.5 195,680.5 5,680.5 88.601,740.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 244.987473, 79.452583)" style=""> <radialGradient id="gradient-49" cx="156.3672" cy="808.281" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-49)" stroke="#F2F2F2" points="88.601,500.5 5,560.5 195,560.5 111.404,500.5 "></polygon> <radialGradient id="gradient-50" cx="452.9785" cy="747.2644" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-50)" stroke="#F2F2F2" points="111.404,620.5 195,560.5 5,560.5 88.601,620.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 244.987473, 79.452583)" style=""> <radialGradient id="gradient-51" cx="156.3672" cy="1123.2849" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-51)" stroke="#F2F2F2" points="88.602,150.5 5,210.5 195,210.5 111.404,150.5 "></polygon> <radialGradient id="gradient-52" cx="452.9785" cy="1062.2664" r="196.6118" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-52)" stroke="#F2F2F2" points="111.404,270.5 195,210.5 5,210.5 88.601,270.5 "></polygon> </g> <rect x="345.986" y="79.631" fill="url(#gradient-53)" stroke="#F2F2F2" width="5.007" height="201.319" style=""></rect> <g transform="matrix(0.208638, 0, 0, 0.183017, 327.625488, 79.538857)" style=""> <radialGradient id="gradient-65" cx="156.3662" cy="484.2776" r="205.1986" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-65)" stroke="#F2F2F2" points="88.601,860.5 5,920.5 195,920.5 111.404,860.5 "></polygon> <radialGradient id="gradient-66" cx="452.9785" cy="423.26" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-66)" stroke="#F2F2F2" points="111.404,980.5 195,920.5 5,920.5 88.601,980.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 327.625488, 79.538857)" style=""> <radialGradient id="gradient-67" cx="156.3672" cy="592.2791" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-67)" stroke="#F2F2F2" points="88.601,740.5 5,800.5 195,800.5 111.404,740.5 "></polygon> <radialGradient id="gradient-68" cx="452.9785" cy="531.26" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-68)" stroke="#F2F2F2" points="111.404,860.5 195,800.5 5,800.5 88.601,860.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 327.625488, 64.538857)" style=""> <radialGradient id="gradient-69" cx="156.3672" cy="700.2781" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-69)" stroke="#F2F2F2" points="88.601,620.5 5,680.5 195,680.5 111.404,620.5 "></polygon> <radialGradient id="gradient-70" cx="452.9785" cy="639.2625" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-70)" stroke="#F2F2F2" points="111.404,740.5 195,680.5 5,680.5 88.601,740.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 327.625488, 63.538857)" style=""> <radialGradient id="gradient-71" cx="156.3672" cy="808.281" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-71)" stroke="#F2F2F2" points="88.601,500.5 5,560.5 195,560.5 111.404,500.5 "></polygon> <radialGradient id="gradient-72" cx="452.9785" cy="747.2644" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-72)" stroke="#F2F2F2" points="111.404,620.5 195,560.5 5,560.5 88.601,620.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 327.625488, 95.538857)" style=""> <radialGradient id="gradient-73" cx="156.3672" cy="1123.2849" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-73)" stroke="#F2F2F2" points="88.602,150.5 5,210.5 195,210.5 111.404,150.5 "></polygon> <radialGradient id="gradient-74" cx="452.9785" cy="1062.2664" r="196.6118" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-74)" stroke="#F2F2F2" points="111.404,270.5 195,210.5 5,210.5 88.601,270.5 "></polygon> </g> <rect x="304.825" y="79.644" fill="url(#gradient-56)" stroke="#F2F2F2" width="5.007" height="201.319" style=""></rect> <g transform="matrix(0.208638, 0, 0, 0.183017, 286.463837, 79.551765)" style=""> <radialGradient id="gradient-75" cx="156.3662" cy="484.2776" r="205.1986" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-75)" stroke="#F2F2F2" points="88.601,860.5 5,920.5 195,920.5 111.404,860.5 "></polygon> <radialGradient id="gradient-76" cx="452.9785" cy="423.26" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-76)" stroke="#F2F2F2" points="111.404,980.5 195,920.5 5,920.5 88.601,980.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 286.463837, 79.551765)" style=""> <radialGradient id="gradient-77" cx="156.3672" cy="592.2791" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-77)" stroke="#F2F2F2" points="88.601,740.5 5,800.5 195,800.5 111.404,740.5 "></polygon> <radialGradient id="gradient-78" cx="452.9785" cy="531.26" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-78)" stroke="#F2F2F2" points="111.404,860.5 195,800.5 5,800.5 88.601,860.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 286.463837, 79.551765)" style=""> <radialGradient id="gradient-79" cx="156.3672" cy="700.2781" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-79)" stroke="#F2F2F2" points="88.601,620.5 5,680.5 195,680.5 111.404,620.5 "></polygon> <radialGradient id="gradient-80" cx="452.9785" cy="639.2625" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-80)" stroke="#F2F2F2" points="111.404,740.5 195,680.5 5,680.5 88.601,740.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 286.463837, 63.551765)" style=""> <radialGradient id="gradient-81" cx="156.3672" cy="808.281" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-81)" stroke="#F2F2F2" points="88.601,500.5 5,560.5 195,560.5 111.404,500.5 "></polygon> <radialGradient id="gradient-82" cx="452.9785" cy="747.2644" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-82)" stroke="#F2F2F2" points="111.404,620.5 195,560.5 5,560.5 88.601,620.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 286.463837, 79.551765)" style=""> <radialGradient id="gradient-83" cx="156.3672" cy="1123.2849" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-83)" stroke="#F2F2F2" points="88.602,150.5 5,210.5 195,210.5 111.404,150.5 "></polygon> <radialGradient id="gradient-84" cx="452.9785" cy="1062.2664" r="196.6118" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-84)" stroke="#F2F2F2" points="111.404,270.5 195,210.5 5,210.5 88.601,270.5 "></polygon> </g> <rect x="387.221" y="79.582" fill="url(#gradient-59)" stroke="#F2F2F2" width="5.007" height="201.319" style=""></rect> <g transform="matrix(0.208638, 0, 0, 0.183017, 368.859924, 79.490074)" style=""> <radialGradient id="gradient-85" cx="156.3662" cy="484.2776" r="205.1986" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-85)" stroke="#F2F2F2" points="88.601,860.5 5,920.5 195,920.5 111.404,860.5 "></polygon> <radialGradient id="gradient-86" cx="452.9785" cy="423.26" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-86)" stroke="#F2F2F2" points="111.404,980.5 195,920.5 5,920.5 88.601,980.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 368.859924, 79.490074)" style=""> <radialGradient id="gradient-87" cx="156.3672" cy="592.2791" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-87)" stroke="#F2F2F2" points="88.601,740.5 5,800.5 195,800.5 111.404,740.5 "></polygon> <radialGradient id="gradient-88" cx="452.9785" cy="531.26" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-88)" stroke="#F2F2F2" points="111.404,860.5 195,800.5 5,800.5 88.601,860.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 368.859924, 79.490074)" style=""> <radialGradient id="gradient-89" cx="156.3672" cy="700.2781" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-89)" stroke="#F2F2F2" points="88.601,620.5 5,680.5 195,680.5 111.404,620.5 "></polygon> <radialGradient id="gradient-90" cx="452.9785" cy="639.2625" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-90)" stroke="#F2F2F2" points="111.404,740.5 195,680.5 5,680.5 88.601,740.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 368.859924, 79.490074)" style=""> <radialGradient id="gradient-91" cx="156.3672" cy="808.281" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-91)" stroke="#F2F2F2" points="88.601,500.5 5,560.5 195,560.5 111.404,500.5 "></polygon> <radialGradient id="gradient-92" cx="452.9785" cy="747.2644" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-92)" stroke="#F2F2F2" points="111.404,620.5 195,560.5 5,560.5 88.601,620.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 368.859924, 79.490074)" style=""> <radialGradient id="gradient-93" cx="156.3672" cy="1123.2849" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-93)" stroke="#F2F2F2" points="88.602,150.5 5,210.5 195,210.5 111.404,150.5 "></polygon> <radialGradient id="gradient-94" cx="452.9785" cy="1062.2664" r="196.6118" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-94)" stroke="#F2F2F2" points="111.404,270.5 195,210.5 5,210.5 88.601,270.5 "></polygon> </g> <rect x="428.583" y="79.583" fill="url(#gradient-62)" stroke="#F2F2F2" width="5.007" height="201.319" style=""></rect> <g transform="matrix(0.208638, 0, 0, 0.183017, 410.221863, 79.490364)" style=""> <radialGradient id="gradient-95" cx="156.3662" cy="484.2776" r="205.1986" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-95)" stroke="#F2F2F2" points="88.601,860.5 5,920.5 195,920.5 111.404,860.5 "></polygon> <radialGradient id="gradient-96" cx="452.9785" cy="423.26" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-96)" stroke="#F2F2F2" points="111.404,980.5 195,920.5 5,920.5 88.601,980.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 410.221863, 63.490364)" style=""> <radialGradient id="gradient-97" cx="156.3672" cy="592.2791" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-97)" stroke="#F2F2F2" points="88.601,740.5 5,800.5 195,800.5 111.404,740.5 "></polygon> <radialGradient id="gradient-98" cx="452.9785" cy="531.26" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-98)" stroke="#F2F2F2" points="111.404,860.5 195,800.5 5,800.5 88.601,860.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 410.221863, 63.490364)" style=""> <radialGradient id="gradient-99" cx="156.3672" cy="700.2781" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-99)" stroke="#F2F2F2" points="88.601,620.5 5,680.5 195,680.5 111.404,620.5 "></polygon> <radialGradient id="gradient-100" cx="452.9785" cy="639.2625" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-100)" stroke="#F2F2F2" points="111.404,740.5 195,680.5 5,680.5 88.601,740.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 410.221863, 63.490364)" style=""> <radialGradient id="gradient-101" cx="156.3672" cy="808.281" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-101)" stroke="#F2F2F2" points="88.601,500.5 5,560.5 195,560.5 111.404,500.5 "></polygon> <radialGradient id="gradient-102" cx="452.9785" cy="747.2644" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-102)" stroke="#F2F2F2" points="111.404,620.5 195,560.5 5,560.5 88.601,620.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 410.221863, 79.490364)" style=""> <radialGradient id="gradient-103" cx="156.3672" cy="1123.2849" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-103)" stroke="#F2F2F2" points="88.602,150.5 5,210.5 195,210.5 111.404,150.5 "></polygon> <radialGradient id="gradient-104" cx="452.9785" cy="1062.2664" r="196.6118" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-104)" stroke="#F2F2F2" points="111.404,270.5 195,210.5 5,210.5 88.601,270.5 "></polygon> </g> <rect x="98.29" y="79.632" fill="url(#gradient-105)" stroke="#F2F2F2" width="5.007" height="201.319" style=""></rect> <rect y="258.989" fill="url(#gradient-106)" width="371.216" height="21.962" x="79.93" style=""></rect> <g transform="matrix(1.854635, 0, 0, 0.183017, 79.928871, 79.539436)" style=""> <rect x="0.001" y="360.5" width="200" height="50"></rect> <rect y="370.5" fill="#FFFFFF" width="200" height="30"></rect> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 79.928871, 79.539436)" style=""> <radialGradient id="gradient-108" cx="156.3662" cy="484.2776" r="205.1986" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-108)" stroke="#F2F2F2" points="88.601,860.5 5,920.5 195,920.5 111.404,860.5 "></polygon> <radialGradient id="gradient-109" cx="452.9785" cy="423.26" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-109)" stroke="#F2F2F2" points="111.404,980.5 195,920.5 5,920.5 88.601,980.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 79.928871, 79.539436)" style=""> <radialGradient id="gradient-110" cx="156.3672" cy="592.2791" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-110)" stroke="#F2F2F2" points="88.601,740.5 5,800.5 195,800.5 111.404,740.5 "></polygon> <radialGradient id="gradient-111" cx="452.9785" cy="531.26" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-111)" stroke="#F2F2F2" points="111.404,860.5 195,800.5 5,800.5 88.601,860.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 79.928871, 79.539436)" style=""> <radialGradient id="gradient-112" cx="156.3672" cy="700.2781" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-112)" stroke="#F2F2F2" points="88.601,620.5 5,680.5 195,680.5 111.404,620.5 "></polygon> <radialGradient id="gradient-113" cx="452.9785" cy="639.2625" r="196.6131" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-113)" stroke="#F2F2F2" points="111.404,740.5 195,680.5 5,680.5 88.601,740.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 79.928871, 79.539436)" style=""> <radialGradient id="gradient-114" cx="156.3672" cy="808.281" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-114)" stroke="#F2F2F2" points="88.601,500.5 5,560.5 195,560.5 111.404,500.5 "></polygon> <radialGradient id="gradient-115" cx="452.9785" cy="747.2644" r="196.6101" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-115)" stroke="#F2F2F2" points="111.404,620.5 195,560.5 5,560.5 88.601,620.5 "></polygon> </g> <g transform="matrix(0.208638, 0, 0, 0.183017, 79.928871, 79.539436)" style=""> <radialGradient id="gradient-116" cx="156.3672" cy="1123.2849" r="205.1978" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-116)" stroke="#F2F2F2" points="88.602,150.5 5,210.5 195,210.5 111.404,150.5 "></polygon> <radialGradient id="gradient-117" cx="452.9785" cy="1062.2664" r="196.6118" gradientTransform="matrix(0.95 0 0 -1.1111 -192.6259 1415.8875)" gradientUnits="userSpaceOnUse"> <stop offset="0" style="stop-color:#9F5B00"></stop> <stop offset="0.0719" style="stop-color:#A26006"></stop> <stop offset="0.1668" style="stop-color:#AC6F16"></stop> <stop offset="0.2745" style="stop-color:#BB8732"></stop> <stop offset="0.3917" style="stop-color:#D1A958"></stop> <stop offset="0.5152" style="stop-color:#EDD588"></stop> <stop offset="0.5604" style="stop-color:#F8E69C"></stop> <stop offset="0.6078" style="stop-color:#F0DA92"></stop> <stop offset="0.6945" style="stop-color:#DCB878"></stop> <stop offset="0.8109" style="stop-color:#BB834F"></stop> <stop offset="0.9511" style="stop-color:#8F3915"></stop> <stop offset="1" style="stop-color:#7E1E00"></stop> </radialGradient> <polygon fill="url(#gradient-117)" stroke="#F2F2F2" points="111.404,270.5 195,210.5 5,210.5 88.601,270.5 "></polygon> </g> <rect y="79.723" fill="url(#gradient-107)" width="370.812" height="27.27" x="79.93" style=""></rect> </svg> Each pole represents a decimal digit of the number, where the rightmost pole indicates the ones digit, the second to the right the tens digit, the third to the right the hundreds digit, and so on. Each pole is split into an upper and a lower portion. Each bead in the lower portion represents a single unit for the pole (1 for the ones pole, 10 for the tens pole, 100 for the hundreds pole, etc.) The bead in the upper portion represents 5 units for the pole (5 for the ones pole, 50 for the tens pole, 500 for the hundreds pole, etc.) For the upper portion of the pole, the bead is counted if it is in the down position. For the lower portion of the pole, a bead is counted if it is in the up position. --- ## Task For this kata you will need to write two functions: * An encoding function which will take an int as input and return a string representing that number stored on an abacus * A decoding function which will take as input a string representing an abacus and return the number on the abacus as an int An abacus will be represented as a string where a `'*'` character represents a bead, a `' '` (space) character represents an empty spot on the pole, and a `'-'` character represents the dividing line between the upper and lower portions. For example, the abacus in the image above (representing the number `1703`) would be represented as: ``` ****** ** * --------- ** * ***** *** ****** ** ******** ********* ``` or ``` '****** **\n * \n---------\n ** *\n***** ***\n****** **\n******** \n*********' ``` #### Notes: * All abacus representations will have 9 poles * Input to the encoding function will be constrained to `0 <= n <= 999999999` * Input to the decoding function will always be a valid abacus representation
reference
def create_abacus(n): n, res = map(int, str(n). zfill(9)), [] for d in n: a, b = divmod(d, 5) res . append(list("**-*****")) res[- 1][not a] = res[- 1][b + 3] = " " return "\n" . join(map("" . join, zip(* res))) def read_abacus(abacus): m, n = map("" . join, zip(* abacus . split("\n"))), "" for r in m: a, b = not r . index(" "), r . rfind(" ") - 3 n += str(5 * a + b) n = n . lstrip("0") return int(n) if n else 0
Representing Numbers on an Abacus
60d7a52b57c9d50055b1a1f7
[ "Strings", "Fundamentals" ]
https://www.codewars.com/kata/60d7a52b57c9d50055b1a1f7
6 kyu
![a truth table](https://storage.googleapis.com/dycr-web/image/topic/logic-gate/xor-xnor/xor-table.png "XOR truth table") You are given a Boolean function (i.e. a function that takes boolean parameters and returns a boolean). You have to return a string representing the function's truth table. ~~~if:c In C, you will receive a structure that contains the function's name, arguments count, and pointer. The boolean function takes an array of Booleans as argument, with the first argument at the index 0 and so on. ```c typedef struct { unsigned argc; bool (*function)(bool argv[]); const char *name; } BoolFuncStruct; ``` You have to return a malloced, null-terminated string. ~~~ # Formatting rules : * Variables should be named A, B, C, D ... and so on, **in the same order as they are passed to the boolean function** * There won't be more than 26 (A...Z) parameters * Boolean values will be represented by either 1 (true) or 0 (false) * If the function is anonymous, use the letter `f` as a name. ~~~if:c In C, function names will always be valid. ~~~ * The first line will consist of, in order: <ul> <li>the variables' names, separated by a space ( )</li> <li>two tabulations (\t) characters</li> <li>the function name with, inside parentheses, its parameters separated by commas (,)</li> <li>two newline (\n) characters</li> </ul> * The following lines will consist of, in order: <ul> <li>the variables' values, separated by a space ( )</li> <li>two tabulations (\t) characters</li> <li>the function result for this arrangement of variables</li> <li>a newline (\n) character</li> </ul> # Examples <pre> A B AND(A,B) 0 0 0 0 1 0 1 0 0 1 1 1 </pre> # Values ordering : Pay attention to the way the values are ordered. If we group the variables' values together so as to form a binary number, that number will be incremented by 1 at each row. For instance with 3 variables : <pre> 000 001 010 011 100 101 110 111 </pre>
algorithms
def truth_table(f): vars = f . __code__ . co_varnames name = n if (n := f . __code__ . co_name) != "<lambda>" else "f" lines = [ f" { ' ' . join ( vars )} \t\t { name } ( { ',' . join ( vars )} )\n\n"] for i in range(0, 2 * * len(vars)): arg_values = tuple([int(x) for x in f" { i : 0 > { len ( vars )} b } "]) result = int(f(* arg_values)) lines . append( f" { ' ' . join ( str ( x ) for x in arg_values )} \t\t { result } \n") return "" . join(lines)
Boolean function truth table
5e67ce1b32b02d0028148094
[ "Binary", "Algorithms" ]
https://www.codewars.com/kata/5e67ce1b32b02d0028148094
6 kyu
<h1 align="center">Subsequence Sums</h1> <hr> <h2> Task </h2> Given a sequence of integers named `arr`, find the number of continuous subsequences (sublist or subarray) in `arr` that sum up to `s`. A continuous subsequence can be defined as a sequence inbetween a start index and stop index (inclusive) of the sequence. For instance, `[2, 3, 4]` is a continuous subsequence of `[1, 2, 3, 4, 5]` , but `[3, 5]` and `[4, 1]` are not. **PERFORMANCE REQUIREMENTS** The length of `arr` is `$\le$` 10,000. The contents of `arr` can range from -10000 to 10000. <hr> **SAMPLE INPUTS & OUTPUTS** ```python arr = [1, 2, 3, -3, -2, -1], s = 0 -> 3 # [3, -3], [2, 3, -3, -2], [1, 2, 3, -3, -2, -1] ------------------------------------------------------------ arr = [1, 5, -2, 4, 0, -7, -3, 6], s = 4 -> 4 # [1, 5, -2], [4], [4, 0], [1, 5, -2, 4, 0, -7, -3, 6] ------------------------------------------------------------ arr = [9, -2, -5, 8, 6, -10, 0, -4], s = -1 -> 2 # [-5, 8, 6, -10], [-5, 8, 6, -10, 0] ```
algorithms
from collections import defaultdict from itertools import accumulate def subsequence_sums(arr, s): res, memo = 0, defaultdict(int) for x in accumulate(arr, initial=0): res += memo[x - s] memo[x] += 1 return res
Subsequence Sums
60df63c6ce1e7b0023d4af5c
[ "Dynamic Programming", "Mathematics", "Algorithms" ]
https://www.codewars.com/kata/60df63c6ce1e7b0023d4af5c
5 kyu
### Task Consider a series of functions `$S_m(n)$` where: `$S_0(n) = 1$`<br> `$S_{m+1}(n) = \displaystyle\sum^n_{k=1}S_m(k)$` Write a function `s` which takes two integer arguments `m` and `n` and returns the value defined by `$S_m(n)$`. #### Inputs `0 <= m <= 100`<br> `1 <= n <= 10**100`
algorithms
from math import comb def S(m, n): return comb(m + n - 1, m)
Nth Order Summation
60d5b5cd507957000d08e673
[ "Mathematics", "Performance" ]
https://www.codewars.com/kata/60d5b5cd507957000d08e673
6 kyu
Your task is to find the last non-zero digit of `$n!$` (factorial). ``$n! = 1 \times 2 \times 3 \times \dots \times n$`` Example: If `$n = 12$`, your function should return `$6$` since `$12 != 479001\bold{6}00$` ### Input ```if:python,ruby,elixir Non-negative integer n Range: 0 - 2.5E6 ``` ```if:cpp,nasm,javascript Non-negative integer n Range: 0 - 2.5E9 ``` ### Output Last non-zero digit of `$n!$` #### Note Calculating the whole factorial will timeout.
algorithms
last_digit = l = lambda n, d = (1, 1, 2, 6, 4, 2, 2, 4, 2, 8): n < 10 and d[n] or ((6 - n / / 10 % 10 % 2 * 2) * l(n / / 5) * d[n % 10]) % 10
Last non-zero digit of factorial
5f79b90c5acfd3003364a337
[ "Mathematics", "Algorithms" ]
https://www.codewars.com/kata/5f79b90c5acfd3003364a337
6 kyu
### Delta Generators In mathematics, the symbols `Δ` and `d` are often used to denote the difference between two values. Similarly, differentiation takes the ratio of changes (ie. `dy/dx`) for a linear relationship. This method can be applied multiple times to create multiple 'levels' of rates of change. (A common example is `x (position) -> v (velocity) -> a (acceleration)`). Today we will be creating a similar concept. Our function `delta` will take a sequence of `values` and a positive integer `level`, and return a sequence with the 'differences' of the original `values`. (Differences here means strictly `b - a`, eg. `[1, 3, 2] => [2, -1]`) The argument `level` is the 'level' of difference, for example `acceleration` is the 2nd 'level' of difference from `position`. The specific encoding of input and output lists is specified below. The example below shows three different 'levels' of the same input. ```typescript input = [1, 2, 4, 7, 11, 16, 22] [...delta(input, 1)] # [1, 2, 3, 4, 5, 6] [...delta(input, 2)] # [1, 1, 1, 1, 1] [...delta(input, 3)] # [0, 0, 0, 0] ``` ```python input = [1, 2, 4, 7, 11, 16, 22] list(delta(input, 1)) # [1, 2, 3, 4, 5, 6] list(delta(input, 2)) # [1, 1, 1, 1, 1] list(delta(input, 3)) # [0, 0, 0, 0] ``` ```haskell let input = [1, 2, 4, 7, 11, 16, 22] delta input 1 -> [1, 2, 3, 4, 5, 6] delta input 2 -> [1, 1, 1, 1, 1] delta input 3 -> [0, 0, 0, 0] ``` ```csharp int[] input = new [] {1, 2, 4, 7, 11, 16, 22}; Delta(input, 1); // new [] {1, 2, 3, 4, 5, 6} Delta(input, 2); // new [] {1, 1, 1, 1, 1} Delta(input, 3); // new [] {0, 0, 0, 0} ``` ```rust let input = vec![1, 2, 4, 7, 11, 16, 22]; delta(input.clone(), 1).collect(); // vec![1, 2, 3, 4, 5, 6] delta(input.clone(), 2).collect(); // vec![1, 1, 1, 1, 1] delta(input.clone(), 3).collect(); // vec![0, 0, 0, 0] ``` ```factor { 1 2 4 7 11 16 22 } :> input input 1 delta take-all ! { 1 2 3 4 5 6 } input 2 delta take-all ! { 1 1 1 1 1 } input 3 delta take-all ! { 0 0 0 0 } ``` ```javascript input = [1, 2, 4, 7, 11, 16, 22] [...delta(input, 1)] // [1, 2, 3, 4, 5, 6] [...delta(input, 2)] // [1, 1, 1, 1, 1] [...delta(input, 3)] // [0, 0, 0, 0] ``` We do not assume any 'starting value' for the input, so the output for each subsequent level will be one item shorter than the previous (as shown above). If an _infinite_ input is provided, then the output must _also_ be infinite. #### Input/Output encoding ~~~if:typescript, Input and output can be any, possibly infinite, `Iterable<any>`. Possibilities include finite lists and possibly infinite generator objects, but any `Iterable<any>` must be accepted as input and is acceptable as output. ~~~ ~~~if:python, Input and output can be any, possibly infinite, `iterable`. Possibilities include finite lists and possibly infinite generator objects, but any `iterable` must be accepted as input and is acceptable as output. ~~~ ~~~if:haskell, Input and output lists are, possibly infinite, native lists. ~~~ ~~~if:csharp, Input and output lists can be any, possibly infinite, `IEnumerable<int>`. Possibilities include finite lists and possibly infinite generator objects, but any `Enumerable<int>` must be accepted as input and is acceptable as output. ~~~ ~~~if:rust, - Input is an `IntoIterator`, including finite collections and infinite iterators. - Output is an `Iterator`. ~~~ ~~~if:factor, Input and output are (possibly endless) [generators](https://docs.factorcode.org/content/article-generators.html). ~~~ ~~~if:javascript, Input and output can be any iterable, possibly infinite. Possibilities include finite lists and possibly infinite generator objects, but any iterable must be accepted as input and is acceptable as output. ~~~ #### Difference implementation ~~~if:typescript, - `delta` must work for iterables of any objects/types that support the `-` operator (e.g. number, BigInteger). ~~~ ~~~if:python, - `delta` must work for iterables of any objects/types that implement `__sub__` (eg `int`, `float`, `set`, etc). ~~~ ~~~if:haskell, - `delta` must work for lists of any `Num` instance. ~~~ ~~~if:csharp, - `Delta` must work for lists of any `int` instance. ~~~ ~~~if:rust, - `delta` must work with any element type `T: Sub<Output = T> + Copy`. That is, the type will support subtraction and will be trivially copyable. - Note that since subtracting two values of type `T` results in another `T`, `T` in general will be the owned type, not a reference (e.g. `i32`, not `&i32`). ~~~ ~~~if:factor, - `delta` must work for generators of any `number` type. ~~~ ~~~if:javascript, - `delta` must work for iterables of types number and BigInt, which support the `-` operator. ~~~ #### Additional Requirements/Notes: ~~~if-not:rust,factor - `delta` must work for inputs which are infinite - `values` will always be valid, and will always produce consistent classes/types of object - `level` will always be valid, and `1 <= level <= 400` ~~~ ~~~if:rust,factor - `delta` must work with inputs that are infinite - `values` will always be valid - `level` will always be valid, and `1 <= level <= 50` ~~~ #### Additional examples: ```typescript function* up(): Generator<bigint> { let a = 0n, b = 1n; while (true) { yield a; [a, b] = [a + b, b + 3n]; } } delta(up(), 1); // 1,4,7,10,13,16,19,22,25,28,... delta(up(), 2); // 3,3,3,3,3,3,3,... delta(up(), 3); // 0,0,0,0,0,0,0,... ``` ```python def count(): c = 0 while True: yield c c += 1 # count() => [0, 1, 2, 3, 4, ...] delta(count(), 1) # [1, 1, 1, 1, ...] delta(count(), 2) # [0, 0, 0, 0, ...] def cosine(): c = 0 while True: yield [1, 0, -1, -1, 0, 1][c] c = (c+1)%6 # cosine() => [1, 0, -1, -1, 0, 1, 1, 0, ...] delta(cosine(), 1) # [-1, -1, 0, 1, 1, 0, -1, ...] delta(cosine(), 2) # [0, 1, 1, 0, -1, -1, 0, ...] delta(cosine(), 3) # [1, 0, -1, -1, 0, 1, 1, 0, ...] input = [set([6, 2, 'A']), set([2, 'B', 8]), set(['A', 'B'])] delta(input, 1) # [{8, 'B'}, {'A'}] delta(input, 2) # [{'A'}] ``` ```haskell let count = iterate (+ 1) 0 -- [0, 1, 2, 3, 4, ..] delta count 1 -> [1, 1, 1, 1, ..] delta count 2 -> [0, 0, 0, 0, ..] let cosine = cycle [1, 0, -1, -1, 0, 1] -- [1, 0, -1, -1, 0, 1, 1, 0, ..] delta cosine 1 -> [-1, -1, 0, 1, 1, 0, -1, ..] delta cosine 2 -> [0, 1, 1, 0, -1, -1, 0, ..] delta cosine 3 -> [1, 0, -1, -1, 0, 1, 1, 0, ..] let input = [ Set.fromList [6, 2, 65], Set.fromList [2, 66, 8], Set.fromList [65, 66] ] instance Num (Set Int) where (-) = difference delta input 1 -> [ Set.fromList [8, 66], Set.fromList [65] ] delta input 2 -> [ Set.fromList [65] ] ``` ```csharp IEnumerable<int> Up() { int a=0, b=1; while (true) { yield return a; (a, b) = (a + b, b + 3); } } Delta(Up(), 1).Take(10); // new[] {1,4,7,10,13,16,19,22,25,28} ``` ```rust let iter = std::iter::successors(Some(0), |&x| Some(x + 2)); // [0, 2, 4, 6, ...] delta(iter, 1).take(5).collect::<Vec<_>>(); // Vec<i32> [2, 2, 2, 2, 2] let mut times = vec![]; for i in 0..5 { times.push(std::time::Duration::new(2_u64.pow(i) - 1, 0)) } delta(times, 2).collect::<Vec<_>>(); // Vec<Duration> [1s, 2s, 4s] ``` ```factor GEN: count ( -- gen ) 0 [ dup yield 1 + ] forever ; ! count => 0 1 2 3 4 ... count 1 delta ! 1 1 1 1 ... count 2 delta ! 0 0 0 0 ... GEN: cosine ( -- gen ) { 1 0 -1 -1 0 1 } <circular> 0 [ over nth yield 1 + ] forever ; ! cosine => 1 0 -1 -1 0 1 1 0 ... cosine 1 delta ! -1 -1 0 1 1 0 -1 ... cosine 2 delta ! 0 1 1 0 -1 -1 0 ... cosine 3 delta ! 1 0 -1 -1 0 1 1 0 ... ``` ```javascript function* up() { for (let a = 0n, b = 1n; true; [a, b] = [a + b, b + 3n]) yield a } delta(up(), 1); // 1,4,7,10,13,16,19,22,25,28,... delta(up(), 2); // 3,3,3,3,3,3,3,... delta(up(), 3); // 0,0,0,0,0,0,0,... ```
reference
def delta(iter_, n): iter_ = iter(iter_) if n == 1 else delta(iter_, n - 1) prev = next(iter_) for v in iter_: yield v - prev prev = v
Delta Generators
6040b781e50db7000ab35125
[ "Iterators", "Recursion" ]
https://www.codewars.com/kata/6040b781e50db7000ab35125
6 kyu
## Some but not all ### Description Your task is to create a function that given a sequence and a predicate, returns `True` if only some (but not all) the elements in the sequence are `True` after applying the predicate ### Examples ``` some('abcdefg&%$', str.isalpha) >>> True some('&%$=', str.isalpha) >>> False some('abcdefg', str.isalpha) >>> False some([4, 1], lambda x: x>3) >>> True some([1, 1], lambda x: x>3) >>> False some([4, 4], lambda x: x>3) >>> False ```
reference
def some_but_not_all(seq, pred): return any(map(pred, seq)) and not all(map(pred, seq))
Some (but not all)
60dda5a66c4cf90026256b75
[ "Lists", "Strings", "Fundamentals" ]
https://www.codewars.com/kata/60dda5a66c4cf90026256b75
7 kyu
Given a string, output the encoded version of that string. # Example: # ## Input: ## ```python,js 'When nobody is around, the trees gossip about the people who have walked under them.' ``` First, the input is normalized; Any character other than alphabetic characters should be removed from the text and the message is converted into lowercase. *Only English alphabets (upper and lower case) and valid non-alphabetic characters will be passed i.e.,*: ``` !"#$%&'()*+, -./:;<=>?@[\]^_`{|}~ ``` No digits will be passed as input ## The input is normalized into: ## ```python,js 'whennobodyisaroundthetreesgossipaboutthepeoplewhohavewalkedunderthem' ``` The text is then organized into a rectangle of size `(a * b)` such that `b >= a` and `b - a <= 1`. The last row, if incomplete, should be padded with spaces. Since the length of the normalized text is 68, we use an 8*9 rectangle giving; ```python,js 'whennobod' 'yisaround' 'thetreesg' 'ossipabou' 'tthepeopl' 'ewhohavew' 'alkedunde' 'rthem ' ``` The final message is obtained by reading the rectangle down each column from left to right, and separated into `b` chunks of length `a`, separated by spaces. *No characters other than lowercase English alphabets and spaces are to be used in the output.* ## Output: ## ```python,js 'wytotear hihstwlt eseshhkh natieoee nrrpphdm ooeaeau buebovn onsoped ddgulwe ' ```
reference
import math def cipher_text(plain_text): text = "" . join(c . lower() for c in plain_text if c . isalpha()) s = math . sqrt(len(text)) a = math . floor(s) b = math . ceil(s) if a * b < len(text): a = b return " " . join(text[i:: b]. ljust(a, " ") for i in range(b))
Rectangle letter juggling
60d6f2653cbec40007c92755
[ "Strings", "Fundamentals", "Algorithms" ]
https://www.codewars.com/kata/60d6f2653cbec40007c92755
6 kyu
# Closure Counter - Define the function **counter** that returns a function that returns an increasing value. - The first value should be 1. - You're going to have to use closures. #### Example: > - const newCounter = counter(); > - newCounter() // 1 > - newCounter() // 2 ## Closure: > A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
reference
def counter(): count = 0 def function(): nonlocal count count += 1 return count return function
Closure Counter
60edafd71dad1800563cf933
[ "Fundamentals" ]
https://www.codewars.com/kata/60edafd71dad1800563cf933
7 kyu
Given a balanced string with brackets like: "AA(XX((YY))(U))" find the substrings that are enclosed in the <strong>greatest depth</strong>.<br> <strong>Example:</strong><br> <strong>String</strong>:&ensp; A &ensp; A &ensp; <font color="green">(</font> &ensp; X &ensp; X &ensp; <font color="orange">(</font> &ensp; <font color="red">(</font> &ensp; Y &ensp; Y &ensp; <font color="red">)</font> &ensp; <font color="orange">)</font> &ensp; <font color="orange">(</font> &ensp; U &ensp; <font color="orange">)</font> &ensp; <font color="green">)</font> <br> <strong>Level</strong>:&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;<font color="green">1</font> &ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;<font color="orange">2</font> &ensp;<font color="red">3</font>&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;<font color="red">3</font>&ensp; <font color="orange">2</font> &ensp;<font color="orange">2</font>&ensp;&ensp;&ensp;&ensp;<font color="orange">2</font> &ensp;<font color="green">1</font> <br><br> <strong>Therefore, answer:</strong> { "YY" } since the substring "YY" is locked at the <strong>deepest level</strong>.<br> If several substring are at the deepest level, return them all in a list in order of appearance. <br> <br> The string includes only uppercase letters, parenthesis '(' and ')'.<br> If the input is <strong>empty</strong> or <strong>doesn't contain</strong> brackets, an array containing only the original string must be returned.
algorithms
def strings_in_max_depth(s): start, deepest, lvl, out = 0, 0, 0, [s] for i, c in enumerate(s): if c == ')': if lvl == deepest: out . append(s[start: i]) lvl -= 1 elif c == '(': lvl += 1 start = i + 1 if lvl > deepest: out, deepest = [], lvl return out
Maximum Depth of Nested Brackets
60e4dfc1dc28e70049e2cb9d
[ "Strings", "Performance", "Algorithms" ]
https://www.codewars.com/kata/60e4dfc1dc28e70049e2cb9d
6 kyu
Let's define two functions: ```javascript S(N) — sum of all positive numbers not more than N S(N) = 1 + 2 + 3 + ... + N Z(N) — sum of all S(i), where 1 <= i <= N Z(N) = S(1) + S(2) + S(3) + ... + S(N) ``` You will be given an integer `N` as input; your task is to return the value of `S(Z(N))`. For example, let `N = 3`: ```python Z(3) = 1 + 3 + 6 = 10 S(Z(3)) = S(10) = 55 ``` ```java Z(3) = 1 + 3 + 6 = 10 S(Z(3)) = S(10) = 55 ``` ```javascript Z(3n) = 1n + 3n + 6n = 10n S(Z(3n)) = S(10n) = 55n ``` ```haskell z 3 = 1 + 3 + 6 = 10 s (z 3) = s 10 = 55 ``` ```lambdacalc Z 3 = 1 + 3 + 6 = 10 S (Z 3) = S 10 = 55 ``` The input range is `1 <= N <= 10^9` and there are `80` ( `40` in LC ) test cases, of which most are random. This is my first kata and I hope you'll enjoy it :). Best of luck!
reference
def sum_of_sums(n): def S(n): return (n * (n + 1)) / / 2 def Z(n): return (n * (n + 1) * (n + 2)) / / 6 return S(Z(n))
Sum the nums, sum the sums and sum the nums up to that sum
60d2325592157c0019ee78ed
[ "Mathematics", "Fundamentals" ]
https://www.codewars.com/kata/60d2325592157c0019ee78ed
6 kyu
<h1 align="center"> Maximum Middle </h1> <h2> Task </h2> You will be given a sequence of integers represented by the array or list, `arr`, and the minimum length, `min_length` of a continuous subsequence (or a substring just applied to a list/array/sequence.) Then, return the maximum possible middle term of all possible continuous subsequences with an odd length **greater than or equal to** `min_length`. <h2> Things To Know </h2> A continuous subsequence can be defined as a sequence inbetween a start index and stop index (inclusive) of the sequence. For instance, `[2, 3, 4]` is a continuous subsequence of `[1, 2, 3, 4, 5]` , but `[3, 5]` and `[4, 1]` are not. In this kata, `min_length` will always be odd and less than or equal to the length of `arr` (and positive). <h2> "Performance Requirements" </h2> The length of `arr` can be up to 10,000. Each element of `arr` is in the range of -10,000 to 10,000. <h2> Sample Inputs & Outputs (With Explanations) </h2> ```python arr = [5, 9, 6, 10, 0], min_length = 3 -> 10 # [6, 10, 0] has length 3 with a middle term of 10. arr = [7, 10, 0, 2, 1, 1, 8, 9], min_length = 5 -> 2 # [7, 10, 0, 2, 1, 1, 8] has length 7 with a middle term of 2. arr = [8, 5, 3, -2], min_length = 1 -> 8 # [8] has length of 1 with a middle term of 8 arr = [1, -3, -2], min_length = 3 -> -3 # [1, -3, -2] has length of 3 with a middle term of -3 ``` NOTE: It can be proved that the answers are the **maximized**. Also, `arr` **CAN** contain negative numbers
reference
def maximum_median(arr, s): s / /= 2 return max(arr[s: - s or len(arr)])
Maximum Middle
60e238105b0327001434dfd8
[ "Fundamentals" ]
https://www.codewars.com/kata/60e238105b0327001434dfd8
7 kyu
# Corner Fill You receive a two dimensional array of size `n x n` and you want to fill in the square in one stroke while starting from `0:0` and ending on `n-1:0`. If `n = 3` then: ```rb [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] ``` Starting from left to right and then top to bottom we can grab the first corner! We then return on the inside of this corner to get the next one, and so on (see image below). <img width="155" style="background-color:white;" src="https://files.gitter.im/55db43670fc9f982beae700d/koKc/corners.svg"> Resulting in the sequence `[1, 2, 3, 6, 9, 8, 5, 4, 7]`. Another example: ```rb # 4x4 (Mixed numbers) [ [4, 1, 10, 5], [7, 8, 2, 16], [15, 14, 3, 6], [11, 9, 13, 12] ] #=> [4, 1, 10, 5, 16, 6, 12, 13, 3, 2, 8, 7, 15, 14, 9, 11] ``` ### Inputs The input array can be of size `n=0`, in which case we want to return `[]`
reference
def corner_fill(square): sq = square . copy() result = [] while True: try: result . extend(sq . pop(0)) result . extend(row . pop(- 1) for row in sq) result . extend([row . pop(- 1) for row in sq][:: - 1]) result . extend(sq . pop(0)[:: - 1]) except IndexError: break return result
Corner Fill
60b7d7c82358010006c0cda5
[ "Arrays", "Fundamentals" ]
https://www.codewars.com/kata/60b7d7c82358010006c0cda5
6 kyu
# Pig (dice game) Watch [this Numberphile video](https://www.youtube.com/watch?v=ULhRLGzoXQ0) for an introduction. The goal of Pig is to reach a total score of, say, 100, accumulated over multiple rounds by rolling a six-sided die. The players take turns in playing and, in each round, a player rolls the die as many times they want summing up the results. But, if they roll a 1, the score for that round is zero. The trick to the game is to know when to stop. Example: Say a player rolls a 5 and then a 6. If they stop, 11 points is the score for that round and is added to their total score. If the player continues and rolls a 3 and then a 1, the score for the round is zero and nothing is added to their total score. For more precise instructions on how the game is played, see [the Wikipedia description](https://en.wikipedia.org/wiki/Pig_(dice_game)) The strategy that yields the maximum average score per round is to roll the die until 20 is reached (i.e., the score is 20 or above) and then stop. However, if your opponent is ahead of you, you might want to play more aggressively, and, if your opponent is way behind, you might choose to play more safely. This adds another level of complexity, but we won't pursue that here. Let's just concentrate on the average score when playing "stop at `n`". The expected (or average) score per round when you play "stop at 20" is a little over 8. This means that 20 is reached in approximately 4 out of 10 rounds on average. The goal of this kata is to write a function `stop_at(m, n)` which returns the expected score when rolling an `m`-sided die until `n` is reached. Input constraints: * `2 <= m <= 12` * `1 <= n <= 100` (To those who may object and say that there is no such thing as a 2- or 7-sided die: Here, a 2-sided die is a coin, and a 7-sided die is a 7-sided pencil sharpened at both ends.) Output constraints: * The result has to be within `1e-3` from the correct value Note that a Monte-Carlo simulation as shown in the Numberphile video converges very slowly and is likely to either not provide a result that is sufficiently precise or time out.
reference
from functools import lru_cache @ lru_cache(None) def stop_at(sides, target, curr_score=0): return curr_score if curr_score >= target else \ sum(stop_at(sides, target, curr_score + i) for i in range(2, sides + 1)) / sides
Pig Game
60b05d49639df900237ac463
[ "Fundamentals" ]
https://www.codewars.com/kata/60b05d49639df900237ac463
5 kyu
Your goal is to make a stack based programming language with the following functions/tokens: - `start` - Marks the start of the program. - `end` - Marks the end of the program, and returns the top element in the stack. - `push x` - Pushes the integer `x` into the stack. - `add` - Adds together the top two elements on the stack. - `sub` - Subtracts the top-most element by the second top-most element on the stack. - `mul` - Multiplies the top two elements on the stack. - `div` - Divides (integer division) the top-most element by the second top-most element on the stack. Demo: ```bubbly start push 5 push 3 add end = 8 ``` ```bubbly start push 2 push 5 div push 3 push 8 mul mul end = 48 ``` Easy, right? Such a trivial string interpreter is probably too simple for an amazing code warrior like you. To spice things up, we will add bubbles into the mix. Each token must be engulfed by a bubble (parentheses)! The syntax should be like: ```bubbly (start)(push)(4)(push)(9)(div)(end) ``` which returns `2` in this case. ## Task ~~~if:python Your goal is to create appropriate definitions for `start`, `end`, `push`, `add`, `sub`, `mul` and `div` so that the bubbly language is valid Python syntax, and evaluates to the correct value. ~~~ ~~~if:javascript Your goal is to create appropriate definitions for `start`, `end`, `push`, `add`, `sub`, `mul` and `div` so that the bubbly language is valid JavaScript syntax, and evaluates to the correct value. ~~~ ~~~if:lambdacalc Your goal is to create appropriate definitions for `start`, `end`, `push`, `add`, `sub`, `mul` and `div` so that the bubbly language evaluates to the correct value. ~~~ For instance, typing this in a shell should result in: ```bubbly >>> (start)(push)(5)(push)(8)(push)(1)(add)(add)(end) 14 ``` See the example tests for more examples. ## Notes ~~~if:python - Your definitions should allow multiple bubbly language statements in one script (python session). ~~~ ~~~if:javascript - Your definitions should allow multiple bubbly language statements in one script (node session). ~~~ ~~~if:lambdacalc Purity is `LetRec`. Numbers use `Scott` encoding, so subtracting a larger number from a smaller one should simply result in `0`. ~~~ - Don't worry about division by `0`. There won't be any test cases on that. - All input will be valid. This kata is inspired by [A Simple Postfix Language](https://www.codewars.com/kata/55a4de202949dca9bd000088).
games
def start(fn): return fn([]) def end(a): return a . pop() def push(a): return (lambda n: (lambda fn: fn(a + [n]))) def add(a): return (lambda fn: fn(a + [a . pop() + a . pop()])) def sub(a): return (lambda fn: fn(a + [a . pop() - a . pop()])) def mul(a): return (lambda fn: fn(a + [a . pop() * a . pop()])) def div(a): return (lambda fn: fn(a + [a . pop() / / a . pop()]))
A Bubbly Programming Language
5f7a715f6c1f810017c3eb07
[ "Puzzles" ]
https://www.codewars.com/kata/5f7a715f6c1f810017c3eb07
5 kyu
In Python, `==` tests for equality and `is` tests for identity. Two strings that are equal may also be identical, but this is not guaranteed, but rather an implementation detail. Given a computed expression, ensure that it is identical to the corresponding equal string literal by completing the `make_identical` function. See test case for clarity. (Note, this is easy if you know the concept.)
reference
from sys import intern as make_identical
When we are equal, we are identical
60c47b07f24d000019f722a2
[ "Strings", "Fundamentals" ]
https://www.codewars.com/kata/60c47b07f24d000019f722a2
7 kyu
# Background Your friend has come up with a way to represent any number using binary, but the number of bits can be infinite to represent even the smallest of numbers! He thinks it will be hard to break since just one number can be represented in so many different (and long) ways: `'000000000000000000000000' == 0` `'111111111111' == 0` `'0101101001100110' == 0` He isn't a horrible friend so he's given you lots of examples... see if you can crack his code! # Instructions Your task is to write a function that can decode binary, provided as a string, into the number it represents. You can safely assume that the given string will only contain ones and zeroes, although it may be empty (in which case the expected number is 0). Some representations can be very long so make sure your solution is reasonably efficient. *Good Luck!*
games
def decode_bits(s): return s[1:: 2]. count('1') - s[:: 2]. count('1')
Infinite Length Binary Code
60c8bfa19547e80045184000
[ "Binary", "Puzzles", "Fundamentals" ]
https://www.codewars.com/kata/60c8bfa19547e80045184000
6 kyu