From 4a361feddf1ae3d1f57879b4815778cb61066298 Mon Sep 17 00:00:00 2001 From: Vihaan Date: Wed, 8 Jan 2025 23:58:03 +0530 Subject: [PATCH 1/2] Questions setup done --- data-processing-io.md | 80 ++++++++++++++++++++++ data-processing.md | 156 ++++++++++++++++++++++++++++++++++++++++++ data-types.md | 131 +++++++++++++++++++++++++++++++++++ problem-solving.md | 102 +++++++++++++++++++++++++++ 4 files changed, 469 insertions(+) create mode 100644 data-processing-io.md create mode 100644 data-processing.md create mode 100644 data-types.md create mode 100644 problem-solving.md diff --git a/data-processing-io.md b/data-processing-io.md new file mode 100644 index 0000000..56f557a --- /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..89b1270 --- /dev/null +++ b/data-processing.md @@ -0,0 +1,156 @@ +--- +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..5f56033 --- /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..81083f6 --- /dev/null +++ b/problem-solving.md @@ -0,0 +1,102 @@ +--- +title: Sample Title +tags: ['sample tag1', 'sample tag2'] +--- + +# Problem Statement + +# Solution +```python test.py -r 'python test.py' + + + + + + + + + + +``` + +# Public Test Cases + +## Input 1 + +``` + +``` + +## Output 1 + +``` + +``` + + +## Input 2 + +``` + +``` + +## Output 2 + +``` + +``` + + +## Input 3 + +``` + +``` + +## Output 3 + +``` + +``` + + +## Input 4 + +``` + +``` + +## Output 4 + +``` + +``` + + +# Private Test Cases + +## Input 1 + +``` + +``` + +## Output 1 + +``` + +``` + +## Input 2 + +``` + +``` + +## Output 2 + +``` + +``` From 58eb0368eaa3f064dc06e2358e009b5e391864b5 Mon Sep 17 00:00:00 2001 From: Vihaan Date: Thu, 9 Jan 2025 00:13:30 +0530 Subject: [PATCH 2/2] completed questions --- data-processing-io.md | 2 +- data-processing.md | 4 -- data-types.md | 2 +- problem-solving.md | 129 ++++++++++++++++-------------------------- 4 files changed, 52 insertions(+), 85 deletions(-) diff --git a/data-processing-io.md b/data-processing-io.md index 56f557a..798b416 100644 --- a/data-processing-io.md +++ b/data-processing-io.md @@ -33,7 +33,7 @@ else: print(0) - +``` # Public Test Cases ## Input 1 diff --git a/data-processing.md b/data-processing.md index 89b1270..3063ee6 100644 --- a/data-processing.md +++ b/data-processing.md @@ -39,16 +39,12 @@ def process_numbers(input_list): diff --git a/data-types.md b/data-types.md index 5f56033..77c2e3a 100644 --- a/data-types.md +++ b/data-types.md @@ -49,7 +49,7 @@ if __name__ == "__main__": - +``` # Public Test Cases ## Input 1 diff --git a/problem-solving.md b/problem-solving.md index 81083f6..7d61113 100644 --- a/problem-solving.md +++ b/problem-solving.md @@ -1,102 +1,73 @@ --- -title: Sample Title -tags: ['sample tag1', 'sample tag2'] +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 + +nums = list(map(int, input().split())) +odd_sum = sum(num for num in nums if num % 2 != 0) -``` - -``` - -## Output 1 - -``` - -``` +nums = [num * 2 if num % 2 == 0 else num for num in nums] +nums = [num for num in nums if num % 5 != 0] -## Input 2 - -``` - -``` - -## Output 2 - -``` - -``` - - -## Input 3 - -``` - -``` - -## Output 3 - -``` - -``` - - -## Input 4 +if nums: + print(nums) +else: + print("No numbers left") + + ``` -``` +# Public Test Cases -## Output 4 +## 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 - -``` - -``` - -## Output 1 - -``` - -``` +## Input 1: +11 22 33 44 55 +## Output 1: +[44, 88] -## Input 2 +## Input 2: +6 7 8 9 10 +## Output 2: +[12, 14] -``` - -``` - -## Output 2 - -``` - -``` +## Input 3: +-5 0 -7 8 10 +## Output 3: +[0, 16] \ No newline at end of file