0

I have a list consist of different integers, and i will give a number, then I need to add the integers in that list

I have a list consist of different integers, and i will give a number, then I need to add the integers in that list, and i wanna know how many elements are used in our list to get our specified number, how can I do it ?. Hellp me out guys

2nd Jun 2022, 9:57 AM
S GOUSE BASHA
S GOUSE BASHA - avatar
18 RĂŠponses
+ 6
Don't DM me the task instruction, post it 👉HERE.
2nd Jun 2022, 12:49 PM
Lisa
Lisa - avatar
+ 3
# not sure but I think you wanna do something like this https://code.sololearn.com/cFjQ4JcmFfOH/?ref=app This is just a basic version, you need to find all the possible sum of numbers inside list, and compare it with your number
2nd Jun 2022, 12:42 PM
Sandeep
Sandeep - avatar
+ 3
Some clues to get you started: • Since your goal is to minimize the coin counts, I’d think about how I want to arrange my coin value list; should it be ascending or descending? • Floor division (x // y) and modulo/remainder (x % y) can be helpful in finding out how many of x fit in y and how many are left over. • What does it mean when the remainder becomes zero? • How many times does the loop need to run?
2nd Jun 2022, 2:05 PM
Jeremy Miller
+ 2
That's up to you to decide... I'm not really clear on what you're trying to do. Can you maybe rephrase?
2nd Jun 2022, 10:26 AM
Justice
Justice - avatar
+ 2
[new info made this answer irrelevant and possibly confusing; see the more recent one]
2nd Jun 2022, 10:31 AM
Jeremy Miller
+ 2
It would be helpful if you gave examples for input, output and given list. Which integers do we "add"? Integers that already are in the list? The input integer? Do we add them to each list item? Or do we append them to the list? How do we get the "specified number"? Sum of list items? Product if list items? List length?
2nd Jun 2022, 10:34 AM
Lisa
Lisa - avatar
+ 2
Here is the problem statement guys, I have function Mathchallenge(num) take the input, which will be an integer from 1 to 250, and return an integer output that will specify the least number number of conis, that when added, equal the input integer, Coins are based on a system as fallows: there are coins representing the integers 1,5,7,9, and 11. So for example: if num is 16, then the output should be 2 because you can achieve the number 16 with the coins 7 and 9. If num is 25, then the output should be 3 because you can achieve 25 with either 11,9 and coins or with 9, 9, and 7 coins Example 1 :- Input: 6 Output 2 Example 2:- Input: 16 Output: 2
2nd Jun 2022, 12:57 PM
S GOUSE BASHA
S GOUSE BASHA - avatar
+ 2
Jeremy Miller I also thought the same, but there is one problem with this: https://code.sololearn.com/cxx0oGrFgF0v/?ref=app for 26, output should be 4 but mine shows 6. am i missing something in this code?
2nd Jun 2022, 5:43 PM
Sandeep
Sandeep - avatar
+ 2
Sandeep The issue with your script is that you are assuming the largest number must always be the optimal choice regardless of the other % results. You should evaluate the list in that order (because generally the larger coins will lead to fewer in the final count), but you should check the other values as well. That is, in the second iteration, your script ignores the higher optimality of five: • 15 % 5 => 0 • 15 // 5 => 3 (+ 1) => 4 in favor of eleven: • 15 % 11 => 4 • 15 // 11 => 1 (+ 1) => 2 Because the “1” coin is the only one having a value equal to or less than four (15 % 11) you’re stuck with four coins in the last step: • 4 % 1 => 0 • 4 // 1 => 4 (+ 2) => 6 You’re right to check the list in descending order because this will, generally, find the smallest coin set faster, but your algorithm should optimize the “remainder” value, not the “coin” value itself, since it is the remainder value that leads to more lower-value coins being added.
3rd Jun 2022, 11:38 AM
Jeremy Miller
+ 2
There are several solutions here. https://www.google.com/amp/s/www.geeksforgeeks.org/coin-change-dp-7/amp/ https://www.google.com/amp/s/www.geeksforgeeks.org/find-minimum-number-of-coins-that-make-a-change/amp/ Honestly, people should take googling for solutions as one of the essential modern programming skills. It's as important as auto-complete.😁
4th Jun 2022, 2:27 AM
Bob_Li
Bob_Li - avatar
+ 2
Thanks for the help Bob_Li I was using loops, nested loop to find the solution but it's always recursion in the end xD How did you find the solution? maybe you can tell me some advance google search techniques ;)
4th Jun 2022, 4:00 AM
Sandeep
Sandeep - avatar
+ 2
Sandeep It’s a famous problem; the wikipedia page discusses the brute-force recursion approach you tried and the mathematic particulars of further optimization. https://en.m.wikipedia.org/wiki/Change-making_problem
4th Jun 2022, 4:05 AM
Jeremy Miller
+ 2
Sandeep yes, most problems posted here are homeworks which are often variations of math puzzles with certain names. The trick is to use the right keyword when googling. Doing them without references often lead to brute force methods. But knowing that smarter people have tackled them before, that is like... cheating in an exam😅 Googling is a secret programming language.
4th Jun 2022, 4:12 AM
Bob_Li
Bob_Li - avatar
+ 2
Thanks Bob_Li and Jeremy Miller , I will be looking more into these kind of problems :] Also Bob_Li I will be looking for some ways to cheat because a wise man once said, "you have to be smart to cheat" XD
4th Jun 2022, 6:25 AM
Sandeep
Sandeep - avatar
+ 1
S GOUSE BASHA This challenge sounds incredibly familiar. Are you taking the Harvard CS50 course by chance? And even if not, what is your code? We cannot do the work for you.
2nd Jun 2022, 1:01 PM
Justice
Justice - avatar
+ 1
S GOUSE BASHA maybe using a for loop and performing floor division with number can help.
2nd Jun 2022, 1:53 PM
Sandeep
Sandeep - avatar
+ 1
#input the integers, or if there's more, you can expand a = int(input()) b = int(input()) c = int(input()) yourlist = [a, b, c] x = 0 print("sum =", a+b+c) for i in yourlist: x += 1 print ("variable quantity =", x)
3rd Jun 2022, 11:23 AM
bjakmz
bjakmz - avatar
- 1
Ucvuckhc 6is of is is a to 66h 5hh5hth6by 5hh5hth6b h44h4 is 4g and g of yv vy and we,,,,,,,,,,,,,use it,s
4th Jun 2022, 9:28 AM
Rahul Landge
Rahul Landge - avatar