Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 34 of 34

Thread: Modifying "Coin change" program

  1. #26
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Modifying "Coin change" program

    If you didn't notice I deleted it.. I read the entire thread

  2. #27
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,300
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: Modifying "Coin change" program

    Quote Originally Posted by Tjstretch View Post
    If you didn't notice I deleted it.. I read the entire thread
    Fair enough. But that's why people complain about spoonfeeding. Lesson learned, I suppose.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #28
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Modifying "Coin change" program

    Yeah, hadn't thought about giving runnable code in quite that way, mostly because I wasn't agreeing on the premise that you don't learn from getting code to 'toy' with. Suppose I should thank you. However, you should add a tutorial on how to make pseudo-code or how to show code without "Spoon-Feeding."

  4. #29
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,300
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: Modifying "Coin change" program

    Quote Originally Posted by Tjstretch View Post
    Yeah, hadn't thought about giving runnable code in quite that way, mostly because I wasn't agreeing on the premise that you don't learn from getting code to 'toy' with. Suppose I should thank you. However, you should add a tutorial on how to make pseudo-code or how to show code without "Spoon-Feeding."
    That's a good idea.

    But for the record, I do think that people learn from getting code to play around with- in fact, in my spare time I work on little open source programs that novice programmers can use as a start to their own cool, fun stuff (I'm not advertising myself, but for the curious, they are here). But I think there's a difference between providing a novice programmer with some code to jump start their ability to futz around, and doing a novice programmer's homework for him/her. That's spoon-feeding.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #30
    Junior Member
    Join Date
    Aug 2011
    Location
    Perth, Australia
    Posts
    14
    My Mood
    Tired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Modifying "Coin change" program

    Man that's cool lol, not only do you not help, but any answer which contains the code I'm looking for you'll actually delete and vote to ban the user? Wow...
    You seem to think this is homework. On the other forums I'm on (I'm not advertising myself, but for the curious, they are here and here, mainly first link. Do a search in the "programming" area for posts by S0ULphIRE) we have the same policies, i.e no posting solutions to homework problems. But I tell ya, this ain't homework! I program in a lot of other languages, learn java for funzies. But I'm all funned out on this one.
    Check the programming areas, check my user profile (same name), check whatever. Should give you enough info/assurance that I'm not trolling
    FYI ended up just using a greedy algorithm in c++, little GUI etc. Works fine, turns out I didn't need as much control as I thought would be necessary.
    STILL though, I'd like to know how one would achieve this in Java
    Last edited by S0ULphIRE; September 14th, 2011 at 10:32 PM.

  6. #31
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,300
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: Modifying "Coin change" program

    I didn't delete that post, and I actually said that I didn't count that post as spoonfeeding, since it simply showed you how to use an Object- which is an option I presented, but simply using Integers makes just as much sense.

    But, I predict that you'd do it in Java exactly how you did it in c++.

    Or, like I said back in August: Hint: find all the different combinations that add up to your goal. Choose the shortest one.

    I would just use a dumb recursive tree-path-traverser. Take a List of Integers (those are your coin values). Choose one, add it to your total, add it to a List of "used coins" for that path, and recurse. When you reach the total, return the List. If you go over the total, return null (or whatever you want to return in case of failure). For any node in the tree, you'll return a List of Lists of Integers (one List for each coin choice you could make)- the shortest List is your solution.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #32
    Junior Member
    Join Date
    Aug 2011
    Location
    Perth, Australia
    Posts
    14
    My Mood
    Tired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Modifying "Coin change" program

    Oh yeah I can write what I wrote in c++ for java in a few minutes, but as I said that's just a bog standard GA.

    I'll have a go at writing it in Java again, got more free time now that I'm not the only IT guy in the department (only other guy was away for 5 weeks).

  8. #33
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,300
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: Modifying "Coin change" program

    Maybe I don't understand the problem correctly, but wouldn't a standard greedy algorithm (take the best available option, discard the rest) not always find the answer? For example, say you want to add up to 14 and you have 5, 5, 3, 2, and 2. A greedy algorithm would take the 5, then the other 5, then the 3 (because it gets closer to the goal of 14) but then it would be stuck. The way I described it, the algorithm would back up and try the 2 instead of the 3, eventually arriving at the correct answer.

    Also, I'd like to point out that I hinted at my algorithm way back in August. Had you taken that hint and tried something, or even just pointed out what exactly you didn't understand about it, I would have been more than happy to explain it further, because I love stuff like this. Instead, you argued, asked for code, and criticized me every step of the way. That's fine, but it really doesn't make people want to help you. Maybe something to consider in the future.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #34
    Junior Member
    Join Date
    Aug 2011
    Location
    Perth, Australia
    Posts
    14
    My Mood
    Tired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Modifying "Coin change" program

    Quote Originally Posted by KevinWorkman View Post
    Maybe I don't understand the problem correctly, but wouldn't a standard greedy algorithm (take the best available option, discard the rest) not always find the answer? For example, say you want to add up to 14 and you have 5, 5, 3, 2, and 2. A greedy algorithm would take the 5, then the other 5, then the 3 (because it gets closer to the goal of 14) but then it would be stuck. The way I described it, the algorithm would back up and try the 2 instead of the 3, eventually arriving at the correct answer.
    There's always a 1, so it's always solvable. So your example would grab 5,5,3,1.

    Quote Originally Posted by KevinWorkman View Post
    Also, I'd like to point out that I hinted at my algorithm way back in August. Had you taken that hint and tried something, or even just pointed out what exactly you didn't understand about it, I would have been more than happy to explain it further, because I love stuff like this. Instead, you argued, asked for code, and criticized me every step of the way. That's fine, but it really doesn't make people want to help you. Maybe something to consider in the future.
    I just re-read the thread, especially page 1. I pointed out what I didn't understand at every point that you suggested something (I can provide specific quotes if you'd like).
    As for "criticized you every step of the way", all I can say is again take the time to read back. I asked questions about what you were suggesting, then when you started to repeat "you shouldn't be doing this" and "write it yourself" and "you're a troll", I guess I did start criticizing. Don't think I don't see the irony in this paragraph btw :p

    Get a list of values, calculate every and all possible combinations of values that sum to required value, saving values used in each calculation, saving shortest combo each time. Yes, I understand the theory. But implementing that theory in this particular language right now isn't something I can manage.
    I'm not stupid, I just posted up hoping that the people who do this all the time could go "well easiest way is if you just put printf thesevalues right under this line."
    Then I'd have been like "oh sweet man, thanks that was exactly what I've been trying to do! Ohhh, so that table is being updated THERE and THAT'S where I need to put in a catch to grab the values!"

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  2. Replies: 1
    Last Post: August 2nd, 2011, 05:13 PM
  3. Replies: 21
    Last Post: May 29th, 2011, 12:48 PM
  4. Replies: 2
    Last Post: October 29th, 2010, 03:14 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 07:35 AM