Sort of a silly contest problem... hard coding is the obvious method, and you could write a trivial ~20 line program to generate the >1000 line program in literally no time.
Type: Posts; User: CT&SC
Sort of a silly contest problem... hard coding is the obvious method, and you could write a trivial ~20 line program to generate the >1000 line program in literally no time.
Well, this works, although there may be a more elegant solution.
Array is not a Collection, so you cannot use TreeSet's "addAll" or constructor to include elements. Sorry... you'll have to loop...
Same way you eat an elephant - with a work breakdown structure.
(Sorry, couldn't resist. Please ignore.)
^ True, and a better treatment of the practicalities than in my post. I think that the two together pretty much exhaustively answer the OP's question... OP, what's your take on these comments?
You...
That's a good question.
Let's see... On a single processor, you would implement it like this...
MergeSort(array[i...j])
1. if i = j then return
2. else
3. m := (i + j) / 2
4. ...
^ Just a clarification, my algorithm is already posted above and works (I'll leave as an exercise to the reader what needs to be changed about the java implementation to make it work).
Huh. Just implemented my version using javascript. I let n = 3 and made isPartialSolution the "true" function. Here's the output:
000
001
010
011
100
101
110
111
"The code that I posted above is correct and there is no need to include n in the loop. You are welcome to run it and see for yourself that it stops."
- I think I now understand that you avoided...
Just out of curiosity, does my algorithm do what you want? I'm still not sure I've even understood what you're trying to do.
And correct me if I'm wrong, but how does your start() function know...
I'm really not sure I understand what you're asking for... why do these iterative solutions not work?
After looking at your code a little more carefully, I think I might have deciphered what you...
Is what you want an iterative tree traversal algorithm? That isn't too hard to make iterative.
All you need to do is to design a state machine with the following transitions:
START:
- if there...
Here's some pseudocode. The implementation details I'll leave to you, as they're pretty easy.
!!! assuming the existence of an array with arbitrary capacity, adds a new object to the end of...
There's actually a very simple way to do this.
Consider a simple array. We'll assume a variable sized array, which you can do in Java without too much trouble.
Say you want to make a tree with...
Well the incrementing shouldn't be too bad.
If you incremented by n seconds, then as long as n >= 60, increment by minutes instead and subtract 60 from n. When 0 <= n < 60, add that to the current...
All of those look right to me. Why do you think they're wrong?
1. The only things that could be wrong here are your use of "bool" and "string" (in Java, these might be "Boolean" and "String", so...
Here's some pseudocode for what you want, I believe. I'll leave the details and the translation to you...
DataStore()
1. continue := true
2. while continue
3. do PrintMenu()
4. ...
Sure. Of course, beauty is in the eye of the beholder, and maybe some other members can chime in, but...
First, not that it matters, but I don't think this stipulation in the third elseif clause...
I can't really follow your code. Take a look at the following and see if it's similar or different from the way I would do it:
ListPalindroms(numbers[1...n] : integer)
1. for i := 1 to n
2. ...
First of all, if it's supposed to get the text between the first occurrence of the first marker and the first occurrence of the second marker, inclusive, then in your example,
hello to everyone
...
I really don't quite know what you're asking. Do you have a problem with the code you have provided, or do you want to write new code to count the frequency with which each ASCII character appears?...
Well, what the code is doing at present is reading in a number, and telling you if the number is zero, odd, or even. It does nothing about the individual digits of the number.
You need a way to...
Change this line:
shorterSentence.find(find);
to this line:
result = shorterSentence.find(find);
There is also some tidying up you could do, but I think that the only problem with the code is...
You're right, of course. The people and products are indexed from 1 to 4, and the products 1 to 5, so subtracting by 1 allows these indices to be used for the arrays which are indexed from 0 to 3 and...
You're really almost there, aren't you? I don't understand what the problem is. You have all the code written... now you just have to put it together.
ReadAndSum()
1. sum := 0
2. input := 0...
How are you reading the file? If you're reading it one line at a time, I'd imagine there's a chance that these characters are being stripped automatically. Ditto if you're using the Scanner to get...