본문 바로가기

bool6

1223. validate code with simple regex Basic regex tasks. Write a function that takes in a numeric code of any length. The function should check if the code begins with 1, 2, or 3 and return true if so. Return false otherwise. You can assume the input will always be a number. Solution: def validate_code(code: int) -> bool: return int(str(code)[0]) 2022. 12. 23.
1208. A Strange Trip to the Market You're on your way to the market when you hear beautiful music coming from a nearby street performer. The notes come together like you wouln't believe as the musician puts together patterns of tunes. As you wonder what kind of algorithm you could use to shift octaves by 8 pitches or something silly like that, it dawns on you that you have been watching the musician for some 10 odd minutes. You a.. 2022. 12. 8.
1023. No Loops 2 - You only need one No Loops Allowed You will be given an array a and a value x. All you need to do is check whether the provided array contains the value, without using a loop. Array can contain numbers or strings. x can be either. Return true if the array contains the value, false if not. With strings you will need to account for case. Looking for more, loop-restrained fun? Check out the other kata in the series:.. 2022. 10. 23.
1017. Enumerable Magic - Does My List Include This? Create a method that accepts a list and an item, and returns true if the item belongs to the list, otherwise false. Solution: from typing import List def include(arr: List[int], item: int) -> bool: return bool(arr.count(item)) 2022. 10. 17.
Is n divisible by x and y? Description: Create a function that checks if a number n is divisible by two numbers x AND y. All inputs are positive, non-zero digits. Examples: 1) n = 3, x = 1, y = 3 => true because 3 is divisible by 1 and 3 2) n = 12, x = 2, y = 6 => true because 12 is divisible by 2 and 6 3) n = 100, x = 5, y = 3 => false because 100 is not divisible by 3 4) n = 12, x = 7, y = 5 => false because 12 is neith.. 2022. 3. 25.
하샤드 수 문제 설명 양의 정수 x가 하샤드 수이려면 x의 자릿수의 합으로 x가 나누어져야 합니다. 예를 들어 18의 자릿수 합은 1+8=9이고, 18은 9로 나누어 떨어지므로 18은 하샤드 수입니다. 자연수 x를 입력받아 x가 하샤드 수인지 아닌지 검사하는 함수, solution을 완성해주세요. 제한 조건 x는 1 이상, 10000 이하인 정수입니다. 입출력 예 설명 입출력 예 #1 10의 모든 자릿수의 합은 1입니다. 10은 1로 나누어 떨어지므로 10은 하샤드 수입니다. 입출력 예 #2 12의 모든 자릿수의 합은 3입니다. 12는 3으로 나누어 떨어지므로 12는 하샤드 수입니다. 입출력 예 #3 11의 모든 자릿수의 합은 2입니다. 11은 2로 나누어 떨어지지 않으므로 11는 하샤드 수가 아닙니다. 입출력 예.. 2022. 1. 16.