본문 바로가기

len31

1025. Exclusive "or" (xor) Logical Operator Exclusive "or" (xor) Logical Operator Overview In some scripting languages like PHP, there exists a logical operator (e.g. &&, ||, and, or, etc.) called the "Exclusive Or" (hence the name of this Kata). The exclusive or evaluates two booleans. It then returns true if exactly one of the two expressions are true, false otherwise. For example: false xor false == false // since both are false true x.. 2022. 10. 26.
1019. Is it a palindrome? Write a function that checks if a given string (case insensitive) is a palindrome. Solution: def is_palindrome(s): target = s.lower() for i in range(len(target)//2): if target[i] != target[-i-1]: return False return True def is_palindrome(s): s = s.lower() return s == s[::-1] 2022. 10. 19.
1005. Palindrome Strings Palindrome strings A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. This includes capital letters, punctuation, and word dividers. Implement a function that checks if something is a palindrome. If the input is a number, convert it to string first. Examples(Input ==> Output) "anna" ==> true "walter" ==> false 12321 ==> true 123456 =.. 2022. 10. 5.
0930. Count of positives, sum of negatives Given an array of integers. Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers. 0 is neither positive nor negative. If the input is an empty array or is null, return an empty array. Example For input [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15], you should return [10, -65]. Solution: def sorted_arr(func): def w.. 2022. 9. 30.
0918. Grasshopper - Array Mean Find Mean Find the mean (average) of a list of numbers in an array. Information To find the mean (average) of a set of numbers add all of the numbers together and divide by the number of values in the list. For an example list of 1, 3, 5, 7 Add all of the numbers 1+3+5+7 = 16 Divide by the number of values in the list. In this example there are 4 numbers in the list. 16/4 = 4 The mean (or averag.. 2022. 9. 19.
0826. A wolf in sheep's clothing Wolves have been reintroduced to Great Britain. You are a sheep farmer, and are now plagued by wolves which pretend to be sheep. Fortunately, you are good at spotting them. Warn the sheep in front of the wolf that it is about to be eaten. Remember that you are standing at the front of the queue which is at the end of the array: [sheep, sheep, sheep, sheep, sheep, wolf, sheep, sheep] (YOU ARE HER.. 2022. 8. 26.