How to Take a Ten Minute Walk in C

The challenge You live in the city of Cartesia where all roads are laid out in a perfect grid. You arrived ten minutes too early to an appointment, so you decided to take the opportunity to go for a short walk. The city provides its citizens with a Walk Generating App on their phones — everytime you press the button it sends you an array of one-letter strings representing directions to walk (eg.

How to Count Stats of a String in C

The challenge You will be given a string and your task will be to return a list of ints detailing the count of uppercase letters, lowercase, numbers and special characters, as follows. 1 2 Solve("*'&ABCDabcde12345") = [4,5,5,3]. --the order is: uppercase letters, lowercase, numbers and special characters. The solution in C Option 1: 1 2 3 4 5 6 7 8 9 10 void count_char_types (const char *string, unsigned counts[4]) { char c; counts[0] = counts[1] = counts[2] = counts[3] = 0; while((c = *string++)) if(c >= 'A' && c <= 'Z') counts[0]++; else if(c >= 'a' && c <= 'z') counts[1]++; else if(c >= '0' && c <= '9') counts[2]++; else counts[3]++; } Option 2:

How to Convert a String to the NATO Phonetic Alphabet in C

The challenge You’ll have to translate a string to Pilot’s alphabet (NATO phonetic alphabet). Input: If, you can read? Output: India Foxtrot , Yankee Oscar Uniform Charlie Alfa November Romeo Echo Alfa Delta ? Note: There are preloaded dictionary you can use, named NATO The set of used punctuation is ,.!?. Punctuation should be kept in your return string, but spaces should not. Xray should not have a dash within. Every word and punctuation mark should be seperated by a space ‘ ‘.

How to Add 1 to the Value of each Array in C

The challenge Given an array of integers of any length, return an array that has 1 added to the value represented by the array. the array can’t be empty only non-negative, single digit integers are allowed Return nil (or your language’s equivalent) for invalid inputs. Examples: Valid arrays [4, 3, 2, 5] would return [4, 3, 2, 6] [1, 2, 3, 9] would return [1, 2, 4, 0] [9, 9, 9, 9] would return [1, 0, 0, 0, 0]

How to Calculate the Sum of a Sequence in C

The challenge Your task is to make function, which returns the sum of a sequence of integers. The sequence is defined by 3 non-negative values: begin, end, step (inclusive). If begin value is greater than the end, function should returns **** Examples 1 2 3 4 2,2,2 --> 2 2,6,2 --> 12 (2 + 4 + 6) 1,5,1 --> 15 (1 + 2 + 3 + 4 + 5) 1,5,3 --> 5 (1 + 4) The solution in C Option 1:

How to Solve the Sum of Triangular Numbers in C

The challenge Your task is to return the sum of Triangular Numbers up-to-and-including the nth Triangular Number. Triangular Number: “any of the series of numbers (1, 3, 6, 10, 15, etc.) obtained by continued summation of the natural numbers 1, 2, 3, 4, 5, etc.” 1 2 3 4 5 6 [01] 02 [03] 04 05 [06] 07 08 09 [10] 11 12 13 14 [15] 16 17 18 19 20 [21] e.

How to Determine if a String Only Contains Unique Characters in C

The challenge Write a program to determine if a string contains only unique characters. Return true if it does and false otherwise. The string may contain any of the 128 ASCII characters. Characters are case-sensitive, e.g. ‘a’ and ‘A’ are considered different characters. The solution in C Option 1: 1 2 3 4 5 int has_unique_chars(const char *str) { int mask[128]={0}; while (*str) if (++mask[*str++]>1) return 0; return 1; } Option 2:

How to Find the Maximum Multiple in C

The challenge Given a Divisor and a Bound , Find the largest integer N , Such That , Conditions : N is divisible by divisor N is less than or equal to bound N is greater than 0. Notes The parameters (divisor, bound) passed to the function are only positive values . It’s guaranteed that a divisor is Found .Input » Output Examples 1 maxMultiple (2,7) ==> return (6) Explanation:

How to Assign a Digital Cypher in C

The challenge Digital Cypher assigns to each letter of the alphabet unique number. For example: 1 2 3 4 a b c d e f g h i j k l m 1 2 3 4 5 6 7 8 9 10 11 12 13 n o p q r s t u v w x y z 14 15 16 17 18 19 20 21 22 23 24 25 26 Instead of letters in encrypted word we write the corresponding number, eg.

How to Check for All Inclusive in C

The challenge Input: a string strng an array of strings arr Output of function contain_all_rots(strng, arr) (or containAllRots or contain-all-rots): a boolean true if all rotations of strng are included in arr false otherwise Examples: 1 2 3 4 5 contain_all_rots( "bsjq", ["bsjq", "qbsj", "sjqb", "twZNsslC", "jqbs"]) -> true contain_all_rots( "Ajylvpy", ["Ajylvpy", "ylvpyAj", "jylvpyA", "lvpyAjy", "pyAjylv", "vpyAjyl", "ipywee"]) -> false) Note: Though not correct in a mathematical sense we will consider that there are no rotations of strng == "" and for any array arr: contain_all_rots("", arr) --> true The solution in C Option 1:

How to Solve for Factorial in C

The challenge In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example: 5! = 5 * 4 * 3 * 2 * 1 = 120. By convention the value of 0! is 1. Write a function to calculate factorial for a given input. If input is below 0 or above 12 return -1 (C).

How to Create an Incrementer in C

The challenge Given an input of an array of digits, return the array with each digit incremented by its position in the array: the first digit will be incremented by 1, the second digit by 2, etc. Make sure to start counting your positions from 1 ( and not 0 ). Your result can only contain single digit numbers, so if adding a digit with its position gives you a multiple-digit number, only the last digit of the number should be returned.

How to Return the Closest Number Multiple of 10 in C

The challenge Given a number return the closest number to it that is divisible by 10. Example input: 1 2 3 22 25 37 Expected output: 1 2 3 20 30 40 The solution in C Option 1: 1 2 3 4 5 #include <math.h> int round_to_10 (int n) { return round(n / 10.0) * 10; } Option 2: 1 2 3 int round_to_10(int n) { return (n + 5) / 10 * 10; } Option 3:

How to Reverse Every Other Word in a String in C

The challenge Reverse every other word in a given string, then return the string. Throw away any leading or trailing whitespace, while ensuring there is exactly one space between each word. Punctuation marks should be treated as if they are a part of the word in this challenge. The solution in C Option 1: 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 #include <stddef.

How to Solve Simple Beads Count in C

The challenge Two red beads are placed between every two blue beads. There are N blue beads. After looking at the arrangement below work out the number of red beads. @ @@ @ @@ @ @@ @ @@ @ @@ @ Implement count_red_beads(n) (countRedBeads(n)) so that it returns the number of red beads. If there are less than 2 blue beads return 0. The solution in C Option 1: 1 2 3 4 int countRedBeads(n) { if(n<=1) return 0; return 2*(n-1); } Option 2:

How to Solve the Maze Runner in C

The challenge Introduction Welcome Adventurer. Your aim is to navigate the maze and reach the finish point without touching any walls. Doing so will kill you instantly! Task You will be given a 2D array of the maze and an array of directions. Your task is to follow the directions given. If you reach the end point before all your moves have gone, you should return Finish. If you hit any walls or go outside the maze border, you should return Dead.

How to Take a Number and Sum It’s Digits Raied to the Consecutive Powers in C

The challenge The number 89 is the first integer with more than one digit that fulfills the property partially introduced in the title of this challenge. What’s the use of saying “Eureka”? Because this sum gives the same number. In effect: 89 = 8^1 + 9^2 The next number in having this property is 135. See this property again: 135 = 1^1 + 3^2 + 5^3 We need a function to collect these numbers, that may receive two integers a, b that defines the range [a, b] (inclusive) and outputs a list of the sorted numbers in the range that fulfills the property described above.

How to Find the Middle Element in C

The challenge You need to create a function that when provided with a triplet, returns the index of the numerical element that lies between the other two elements. The input to the function will be an array of three distinct numbers (Haskell: a tuple). For example: 1 gimme([2, 3, 1]) => 0 2 is the number that fits between 1 and 3 and the index of 2 in the input array is __.

How to Invite More Women in C

The challenge Task King Arthur and his knights are having a New Years party. Last year Lancelot was jealous of Arthur, because Arthur had a date and Lancelot did not, and they started a duel. To prevent this from happening again, Arthur wants to make sure that there are at least as many women as men at this year’s party. He gave you a list of integers of all the party goers.

How to Build a Tower in C

The challenge Build a pyramid-shaped tower, as an array/list of strings, given a positive integer number of floors. A tower block is represented with "*" character. For example, a tower with 3 floors looks like this: 1 2 3 4 5 [ " * ", " *** ", "*****" ] And a tower with 6 floors looks like this: 1 2 3 4 5 6 7 8 [ " * ", " *** ", " ***** ", " ******* ", " ********* ", "***********" ] The solution in C Option 1: