diff --git a/data-processing-io.md b/data-processing-io.md new file mode 100644 index 0000000..798b416 --- /dev/null +++ b/data-processing-io.md @@ -0,0 +1,80 @@ +--- +title: Product of Prime Numbers from User Input +tags: [primes, I/O, filtering] +--- + +# Problem Statement + +Given five numbers input by the user, determine which of them are prime numbers. Find the product of the prime numbers and print it. + +Assume the numbers are non-negative integers. If no prime numbers are found, print 0. + +# Solution +```python test.py -r 'python test.py' + +``` +# Public Test Cases + +## Input 1 +``` +1 2 3 4 5 +``` + +## Output 1 +``` +30 +``` + +## Input 2 +``` +10 15 18 7 4 +``` + +## Output 2 +``` +7 +``` + +# Private Test Cases + + +## Input 1 +``` +6 9 11 13 17 +``` + +## Output 1 +``` +2002 +``` + +## Input 2 +``` +29 34 37 40 42 +``` + +## Output 2 +``` +1073 +``` \ No newline at end of file diff --git a/data-processing.md b/data-processing.md new file mode 100644 index 0000000..3063ee6 --- /dev/null +++ b/data-processing.md @@ -0,0 +1,152 @@ +--- +title: Data Processing Operations +tags: ['list', 'filter', 'map'] +--- + +# Problem Statement + +Write a function `process_numbers(input_list: list[int]) -> int` that takes a list of integers as input. The function should: + +1. **Filter out the negative numbers** from the list. +2. **Double the remaining values** in the list. +3. **Find the unique values** after doubling. +4. **Calculate and return the sum** of the unique doubled values. + +### Constraints: +- The input list will be non-empty. +- The list will contain only integers (both positive and negative). + +### Examples: + +`process_numbers([1, -3, 4, 2, -5, 2])` should return `14` (after filtering, doubling, finding unique values, and summing). + +`process_numbers([1, 2, 3, -4, -5, 3])` should return `18` (after filtering, doubling, finding unique values, and summing). + +`process_numbers([10, 10, -5, -5, 7])` should return `34` (after filtering, doubling, finding unique values, and summing). + +`process_numbers([-1, -2, -3])` should return `0` (no positive numbers to double and sum). + + +# Solution +```python test.py -r 'python test.py' + + +def process_numbers(input_list): + # Your code here + pass + + + + +if __name__ == "__main__": + input_list = list(map(int, input("Enter a list of integers separated by spaces: ").split())) + result = process_numbers(input_list) + print(result) + + + + + + + + + + + + + + + +``` + +# Public Test Cases +## Input 1 + +``` +1, -3, 4, 2, -5, 2 +``` + +## Output 1 + +``` +14 +``` + + +## Input 2 + +``` +1, 2, 3, -4, -5, 3 +``` + +## Output 2 + +``` +18 +``` + + +## Input 3 + +``` +10, 10, -5, -5, 7 +``` + +## Output 3 + +``` +34 +``` + + +## Input 4 + +``` +-1, -2, -3 +``` + +## Output 4 + +``` +0 +``` + + +# Private Test Cases + +## Input 1 + +``` +100, 50, -50, 100 +``` + +## Output 1 + +``` +300 +``` + +## Input 2 + +``` +5, -5, -5, 5 +``` + +## Output 2 + +``` +10 +``` diff --git a/data-types.md b/data-types.md new file mode 100644 index 0000000..77c2e3a --- /dev/null +++ b/data-types.md @@ -0,0 +1,131 @@ +--- +title: Data Types Operations +tags: ['string', 'int','conversion','sum'] +--- + +# Problem Statement +Write a function sum_first_last(input_str: str) -> int | str that takes a single string as input. The function should: + +Check if the input string contains only numeric characters (0-9). +If the string contains only numbers, calculate the sum of the first and last digits and return the result. +If the string cannot be converted to an integer (contains any non-numeric characters), return the string "N/A". +Constraints: + +The input string will be a non-empty string. +Length of string is more than or equal to 2. +Assume the string does not contain leading or trailing whitespace. +Do not use exception handling (try-except) for solving the problem. +Examples: + +sum_first_last("12345") should return 6 (1 + 5). +sum_first_last("987654321") should return 10 (9 + 1). +sum_first_last("007") should return 7 (0 + 7). +sum_first_last("12a45") should return "N/A". +sum_first_last("abcd") should return "N/A". + +# Solution +```python test.py -r 'python test.py' + +def convert_and_sum(input_str: str) -> int | str: + # Your code here + pass + + + + +if __name__ == "__main__": + input_str = input("Enter a string: ") + result = convert_and_sum(input_str) + print(result) + + + + +``` +# Public Test Cases + +## Input 1 + +``` +12345 +``` + +## Output 1 + +``` +6 +``` + + +## Input 2 + +``` +2098 +``` + +## Output 2 + +``` +10 +``` + + +## Input 3 + +``` +1234a +``` + +## Output 3 + +``` +N/A +``` + + +## Input 4 + +``` +a1234 +``` + +## Output 4 + +``` +N/A +``` + + +# Private Test Cases + +## Input 1 + +``` +19 +``` + +## Output 1 + +``` +10 +``` + +## Input 2 + +``` +1a +``` + +## Output 2 + +``` +N/A +``` diff --git a/problem-solving.md b/problem-solving.md new file mode 100644 index 0000000..7d61113 --- /dev/null +++ b/problem-solving.md @@ -0,0 +1,73 @@ +--- +title: Problem Solving Game +tags: ['problem-solving', 'filtering','loops'] +--- + +# Problem Statement +You are tasked with writing a function that simulates a "number elimination game". Given a list of integers, the game proceeds as follows: + +Sum up all the odd numbers in the list. +Multiply all the even numbers by 2. +After completing the above transformations, eliminate all numbers that are divisible by 5 from the list. +Finally, return the list after the transformations. If no numbers remain after the eliminations, return "No numbers left". +Input +A space-separated string of integers. The list will contain between 1 and 1000 integers. +Each integer can range from -10^9 to 10^9. +Output +Return the modified list after performing all transformations. If no numbers remain, print "No numbers left". + +# Solution +```python test.py -r 'python test.py' + + +``` + +# Public Test Cases + +## Input 1: +1 2 3 4 5 6 10 7 +## Output 1: +[2, 4, 12, 14] + +## Input 2: +5 10 15 20 +## Output 2: +No numbers left + +## Input 3: +-1 -2 -3 -4 0 +## Output 3: +[-4, 0] + +--- + +# Private Test Cases + +## Input 1: +11 22 33 44 55 +## Output 1: +[44, 88] + +## Input 2: +6 7 8 9 10 +## Output 2: +[12, 14] + +## Input 3: +-5 0 -7 8 10 +## Output 3: +[0, 16] \ No newline at end of file