본문 바로가기

range34

Factorial 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 throw an exception of type ArgumentOutOfRangeException (C#) or IllegalArgumentException (.. 2022. 8. 7.
Count the Digit Take an integer n (n >= 0) and a digit d (0 2022. 8. 5.
Build Tower Build Tower Build a pyramid-shaped tower given a positive integer number of floors. A tower block is represented with "*" character. For example, a tower with 3 floors looks like this: [ " * ", " *** ", "*****" ] And a tower with 6 floors looks like this: [ " * ", " *** ", " ***** ", " ******* ", " ********* ", "***********" ] Solution: def tower_builder(n_floors): nums = [i>0 and i*2+1 or 1 for.. 2022. 7. 29.
What is between? Complete the function that takes two integers (a, b, where a [1, 2, 3, 4] Solution: def between(a,b): number = get_number_generater(range(a,b+1)) return [next(number) for i in range(b+1-a)] def get_number_generater(range): for i in range: yield i Solve it using a generator. It can .. 2022. 7. 24.
Sum of odd numbers Description: Given the triangle of consecutive odd numbers: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 ... Calculate the sum of the numbers in the nth row of this triangle (starting at index 1) e.g.: (Input --> Output) 1 --> 1 2 --> 3 + 5 = 8 Solution: 1. Add up all 'n' numbers. 2. Find the odd number by the added number. 3. It returns after adding 'n' odd numbers from the last. def row_sum_odd_num.. 2022. 4. 28.
Find the divisors! Description: Create a function named divisors/Divisors that takes an integer n > 1 and returns an array with all of the integer's divisors(except for 1 and the number itself), from smallest to largest. If the number is prime return the string '(integer) is prime' (null in C#) (use Either String a in Haskell and Result in Rust). Example: divisors(12); #should return [2,3,4,6] divisors(25); #shoul.. 2022. 3. 24.