# Alatar

Member

228

303 Neutral

• Rank
Member
1. ## Recursive Algorithm Help

Thank you for the replies. Here is my updated program: [source lang=java] public static boolean groupExists(final List<Integer> numbers, final int target) { if (numbers == null) { return false; } else if (target == 0) { return true; } else if (numbers.size() == 0) { if (target == 0) { return true; } else { return false; } } else if (target == numbers.get(numbers.size()-1)) { return true; } else { if (target > numbers.get(numbers.size()-1)) { return groupExists(numbers.subList(0, numbers.size()-1), target - numbers.get(numbers.size()-1)); } else { if (numbers.size() > 3) { return groupExists(numbers.subList(0, numbers.size()-2), target); } else { return groupExists(numbers.subList(0, numbers.size()-1), target); } } } } [/source] It passes every single test I have written for it (about 20) except for one: assertTrue(Exercises.groupExists(list, 31)); The variable list is defined: list = java.util.Arrays.asList(2, 7, 13, 9, 11); Does anyone have any advice on how to change this so that the test does not fail? Thank you
2. ## Recursive Algorithm Help

Hi everyone, I am trying to write a recurisve algoritm that, when given a list of numbers, checks to see if there is any combination of the numbers that will add up to a target value. I'm attempting to write it using tail recursion. The method works occasionally, but does not work every time. My problem is if I have a list {9, 7, 2, 5, 1} and the target is 11, obviously 2 and 9 will add together to become 11. BUT the way I have it written, it will add 1 + 5 (making 6). The next iteration will add the 2, making 8. After that, it will see the 7 and 9 and decide that the group does not exist. I do not see how to code it so that it can detect the 2 and 9 combination. Did that make sense? [source lang=java] public static boolean groupExists(final List<Integer> numbers, final int target) { if (numbers == null || numbers.isEmpty()) { return false; } else if (target == 0) { return true; } else if (numbers.size() == 1) { return (numbers.get(0) == target); } else if (target == numbers.get(numbers.size()-1)) { return true; } else { if (target > numbers.get(numbers.size()-1)) { return groupExists(numbers.subList(0, numbers.size()-1), target - (numbers.size()-1)); } else { return groupExists(numbers.subList(0, numbers.size()-1), target); } } } [/source] I do not see how to get the method to check ALL possible combinations. Can anyone give me some advice? Any help will be appreciated. Thank you.
3. ## Binary Tree that Grows as the Program Runs

Thank you very much for your help. I was able to finally get it working with your pushes in the right direction.
4. ## Binary Tree that Grows as the Program Runs

Thank you for the help you have given me so far. I really do appreciate it. I almost have it figured out, I am just running into an issue with the output. It runs through properly when there are two animals in the tree (say, lion and tiger). The problem is that once I try to add a third, it seems to forget about the others, and basically starts over. Here is what I have now: [source lang=java] public class Tree { public static void main(String[] args) { USERINTERFACE userInterface = new USERINTERFACE(); DTNode root = new TNode("Daisy"); do { root = traverse(root); } while (userInterface.confirmation("Would you like to play again?")); userInterface.outputInfo("Thank you for playing and helping me learn!"); } public static DTNode traverse(DTNode current) { if (current instanceof TNode) { if (userInterface.confirmation("Is it a " + current.getString() + "?")) { userInterface.outputInfo("I guessed it!"); return current; } else { String thing = userInterface.promptUser("I give up!\nWhat kind of flower were you thinking of?"); TNode tNode = new TNode(thing); String ques = userInterface.promptUser("Please enter a yes/no question that queses between a " + current.getString() + " and a " + tNode.getThing()); QNode qNode = null; if (userInterface.confirmation("What is the answer for a " + tNode.getThing() + "?")) { qNode = new QNode(ques, current, tNode); } else { qNode = new QNode(ques, tNode, current); } current = qNode; return traverse(current); } } else { if (userInterface.confirmation(current.getString())) { current = current.rLink(); } else { current = current.lLink(); } return traverse(current); } } } [/source] Can you help me narrow down where my new bug is? Again, thank you very much for all the help you have given me so far.
5. ## Binary Tree that Grows as the Program Runs

Thank you for your reply. Parent Node -> Old Thing Node (which isn't what the user is thinking of) ...into this... New Question Node -> no -> Old Thing Node New Question Node -> yes -> New Thing Node [/quote] I thought that's what I was doing when I said QuestionNode qNode = new QuestionNode(distinguish, current, tNode) because the QuestionNode's constructor is (String question, DecisionTreeNode no, DecisionTreeNode yes). I take it that's not really what my code is doing?

8. ## More Boolean Algebra

Thanks. That helped a lot.
9. ## More Boolean Algebra

I'm still trying to understand how to simplify Boolean algebra expressions. Can someone help me understand how to simplify these pelase? 1. A.B + B.!C + !A.!C 2. D + !B.!C + C.!D + !A.!B.C Thanks. I would appreciate any help.
10. ## Boolean Algebra and Proofs

Hi everyone, Does anyone have a link to a good intro to boolean algebra? I'm trying to do my homework, and my notes and the professor's powerpoints don't work. Our textbook is no help either. I'm trying to solve problems like: (A+B).(A+ !B) = A A.(A + B) = A A.(A +!A.B) = A A + A . B = A+B We are expected to prove them analytically using Boolean algebra laws. The ones with ! are supposed to have a bar above them according to my professor, but the ! (not) means the same thing. If someone has a good link, or could help me with this, I would really appreciate it. Thanks
11. ## IEEE754

Ok. Thanks for your help with this.
12. ## IEEE754

Thanks. So... it would be -1.001010000011011*2^1110... 1 10001101 0010100000110110...0? Is that closer?
13. ## IEEE754

Hi everyone, It's been forever since I've logged in, how is everyone? Anyway, I'm taking a computer architecture class and our professor does not speak English very well at all, and he does not know how to teach the material. I'm having trouble with presenting numbers as single-precision floating point numbers. I can do it ok when it's a positive number, but when it's a negative I have trouble. I'm trying to represent -4A0D.8 in this format. This is what I have: 4A0D.8 = 0100101000001101.1000 -4A0D.8 = 1011010111110010.0111 + 1 (using two's complement) = 1011010111110011.0111 So: the sign is 1 because it is a negative the exponent is 15, or 1111, which gets converted to Excess 127 (0111111 + 00001111 = 10001110) so it becomes 1.0110101111100110111, with 1 as the sign and 10001110 as the exponent. 1 10001110 01101011111001101110...0 (last section has 23 digits) Is this correct? Can anyone help me please?
14. ## What do you listen to while programming?

I generally listen to a mix of Breaking Benjamin, Evanescence, Linkin Park and 3 Doors Down. Sometimes I'll branch out and listen to game or movie soundtracks.
15. ## Rotating a Rectangle

In your create functions, you're rotating the rectangle, then setting the corner positions. Move the rotate call below where you set the corner positions.