CodeKata/Codewars22 [CK] Create Phone Number Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number. Example createPhoneNumber(int[10]{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}) // => returns "(123) 456-7890" The returned format must be correct in order to complete this challenge. Don't forget the space after the closing parentheses! Solution #include std::string ge.. CodeKata/Codewars 2022. 2. 15. [CK] Row of the odd triangle Given a triangle of consecutive odd numbers: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 ... find the triangle's row knowing its index (the rows are 1-indexed), e.g.: odd_row(1) == [1] odd_row(2) == [3, 5] odd_row(3) == [7, 9, 11] Note: your code should be optimized to handle big inputs. Solution #include std::vector odd_row(unsigned long long n) { std::vector vResult; unsigned long long c = n * (n-.. CodeKata/Codewars 2022. 2. 14. [CK] Sequences and Series Have a look at the following numbers. n | score ---+------- 1 | 50 2 | 150 3 | 300 4 | 500 5 | 750 Can you find a pattern in it? If so, then write a function getScore(n)/get_score(n)/GetScore(n) which returns the score for any positive number n: int getScore(1) = return 50; int getScore(2) = return 150; int getScore(3) = return 300; int getScore(4) = return 500; int getScore(5) = return 750; Sol.. CodeKata/Codewars 2021. 11. 4. [CK] My smallest code interpreter (aka Brainf**k) Inspired from real-world Brainf**k, we want to create an interpreter of that language which will support the following instructions: > increment the data pointer (to point to the next cell to the right). second; break; case ']': if( data[data_ptr] != (char)0 ) code_ptr = open_brace.find( code_ptr )->second;; break; default: break; } } if( output.size() > 0 ) return output; else return input; } 후.. CodeKata/Codewars 2021. 11. 4. [CK] Can you get the loop? You are given a node that is the beginning of a linked list. This list always contains a tail and a loop. Your objective is to determine the length of the loop. For example in the following picture the tail's size is 3 and the loop size is 12: // Use the `getNext()` method to get the following node. nodePtr->getNext() Solution #include int getLoopSize(Node* startNode) { Node *next, start; int re.. CodeKata/Codewars 2021. 10. 28. [CK] Human Readable Time Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (HH:MM:SS) HH = hours, padded to 2 digits, range: 00 - 99 MM = minutes, padded to 2 digits, range: 00 - 59 SS = seconds, padded to 2 digits, range: 00 - 59 The maximum time never exceeds 359999 (99:59:59) You can find some examples in the test fixtures. Solution function addZer.. CodeKata/Codewars 2021. 10. 28. [CK] Product of consecutive Fib numbers The Fibonacci numbers are the numbers in the following integer sequence (Fn): 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, ... such as F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1. Given a number, say prod (for product), we search two Fibonacci numbers F(n) and F(n+1) verifying F(n) * F(n+1) = prod. Your function productFib takes an integer (prod) and returns an array: [F(n), F(n+1), .. CodeKata/Codewars 2021. 10. 28. [CK] Greed is Good Greed is a dice game played with five six-sided dice. Your mission, should you choose to accept it, is to score a throw according to these rules. You will always be given an array with five six-sided dice values. Three 1's => 1000 points Three 6's => 600 points Three 5's => 500 points Three 4's => 400 points Three 3's => 300 points Three 2's => 200 points One 1 => 100 points One 5 => 50 point A .. CodeKata/Codewars 2021. 10. 27. [CK] Decode the Morse code In this kata you have to write a simple Morse code decoder. While the Morse code is now mostly superseded by voice and digital data communication channels, it still has its use in some applications around the world. The Morse code encodes every character as a sequence of "dots" and "dashes". For example, the letter A is coded as ·−, letter Q is coded as −−·−, and digit 1 is coded as ·−−−−. The M.. CodeKata/Codewars 2021. 10. 27. [CK] Mexican Wave Introduction The wave (known as the Mexican wave in the English-speaking world outside North America) is an example of metachronal rhythm achieved in a packed stadium when successive groups of spectators briefly stand, yell, and raise their arms. Immediately upon stretching to full height, the spectator returns to the usual seated position. The result is a wave of standing spectators that travel.. CodeKata/Codewars 2021. 10. 25. [CK] Rectangle into Squares The drawing below gives an idea of how to cut a given "true" rectangle into squares ("true" rectangle meaning that the two dimensions are different). Can you translate this drawing into an algorithm? You will be given two dimensions a positive integer length a positive integer width You will return a collection or a string (depending on the language; Shell bash, PowerShell, Pascal and Fortran re.. CodeKata/Codewars 2021. 10. 25. [CK] Playing with digits Some numbers have funny properties. For example Given a positive integer n written as abcd... (a, b, c, d... being digits) and a positive integer p we want to find a positive integer k, if it exists, such as the sum of the digits of n taken to the successive powers of p is equal to k * n. In other words: Is there an integer k such as : (a ^ p + b ^ (p+1) + c ^(p+2) + d ^ (p+3) + ...) = n * k If .. CodeKata/Codewars 2021. 10. 21. [CK] Bit Counting Write a function that takes an integer as input, and returns the number of bits that are equal to one in the binary representation of that number. You can guarantee that input is non-negative. Example: The binary representation of 1234 is 10011010010, so the function should return 5 in this case Solution unsigned int countBits(unsigned long long n){ unsigned int result = 0; while(0 < n) { if(n %.. CodeKata/Codewars 2021. 10. 19. [CK] Convert string to camel case Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized only if the original word was capitalized (known as Upper Camel Case, also often referred to as Pascal case). Examples "the-stealth-warrior" gets converted to "theStealthWarrior" "The_Stealth_Warrior" gets converted to "TheStealthWarrior" Solu.. CodeKata/Codewars 2021. 10. 19. [CK] Sum of Digits / Digital Root Digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. The input will be a non-negative integer. Examples 16 --> 1 + 6 = 7 942 --> 9 + 4 + 2 = 15 --> 1 + 5 = 6 132189 --> 1 + 3 + 2 + 1 + 8 + 9 = 24 --> 2 + 4 = 6 493193 --> 4 + 9 + 3 + 1.. CodeKata/Codewars 2021. 10. 19. [CK] Find the odd int Given an array of integers, find the one that appears an odd number of times. There will always be only one integer that appears an odd number of times. Examples [7] should return 7, because it occurs 1 time (which is odd). [0] should return 0, because it occurs 1 time (which is odd). [1,1,2] should return 2, because it occurs 1 time (which is odd). [0,1,0,1,0] should return 0, because it occurs.. CodeKata/Codewars 2021. 10. 19. [CK] Split Strings Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_'). Examples: solution("abc") // should return {"ab", "c_"} solution("abcdef") // should return {"ab", "cd", "ef"} Solution #include #include std::vector solution(const std::.. CodeKata/Codewars 2021. 10. 19. [CK] Perimeter of squares in a rectangle The drawing shows 6 squares the sides of which have a length of 1, 1, 2, 3, 5, 8. It's easy to see that the sum of the perimeters of these squares is : 4 * (1 + 1 + 2 + 3 + 5 + 8) = 4 * 20 = 80 Could you give the sum of the perimeters of all the squares in a rectangle when there are n + 1 squares disposed in the same manner as in the drawing: Hint: See Fibonacci sequence Ref: http://oeis.org/A00.. CodeKata/Codewars 2021. 10. 19. [CK] Which are in? Given two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2. Example 1: a1 = ["arp", "live", "strong"] a2 = ["lively", "alive", "harp", "sharp", "armstrong"] returns ["arp", "live", "strong"] Example 2: a1 = ["tarp", "mice", "bull"] a2 = ["lively", "alive", "harp", "sharp", "armstrong"] returns [] Notes: Arrays.. CodeKata/Codewars 2021. 10. 13. [CK] Row Weights Scenario Several people are standing in a row divided into two teams. The first person goes into team 1, the second goes into team 2, the third goes into team 1, and so on. Task Given an array of positive integers (the weights of the people), return a new array/tuple of two integers, where the first one is the total weight of team 1, and the second one is the total weight of team 2. Notes Array .. CodeKata/Codewars 2021. 10. 13. 이전 1 2 다음