Search:

Type: Posts; User: CT&SC

Page 1 of 2 1

1. Thread: Program without loops and recursion

by CT&SC
Replies
7
Views
3,189

Re: Program without loops and recursion

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.
2. Thread: How to create a sorted set from the contents of an array

by CT&SC
Replies
1
Views
4,896

Re: How to create a sorted set from the contents of an array

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...
3. Thread: How do you design a complex program

by CT&SC
Replies
5
Views
4,054

Re: How do you design a complex program

Same way you eat an elephant - with a work breakdown structure.

(Sorry, couldn't resist. Please ignore.)

by CT&SC
Replies
4
Views
3,488

Re: Quick Question about Mergesort

^ 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...

by CT&SC
Replies
4
Views
3,488

Re: Quick Question about Mergesort

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. ...
6. Thread: Converting a recursion to iteration

by CT&SC
Replies
7
Views
2,534

Re: Converting a recursion to iteration

^ 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).
7. Thread: Converting a recursion to iteration

by CT&SC
Replies
7
Views
2,534

Re: Converting a recursion to iteration

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
8. Thread: Converting a recursion to iteration

by CT&SC
Replies
7
Views
2,534

Re: Converting a recursion to iteration

"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...
9. Thread: Converting a recursion to iteration

by CT&SC
Replies
7
Views
2,534

Re: Converting a recursion to iteration

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...
10. Thread: Converting a recursion to iteration

by CT&SC
Replies
7
Views
2,534

Re: Converting a recursion to iteration

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...
11. Thread: Converting a recursion to iteration

by CT&SC
Replies
7
Views
2,534

Re: Converting a recursion to iteration

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...
12. Thread: adding items to a binary tree

by CT&SC
Replies
4
Views
2,232

[SOLVED] Re: adding items to a binary tree

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...
13. Thread: adding items to a binary tree

by CT&SC
Replies
4
Views
2,232

[SOLVED] Re: adding items to a binary tree

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...
14. Thread: help with clock class

by CT&SC
Replies
1
Views
3,051

Re: help with clock class

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...
15. Thread: A Few Quick, Easy Questions

by CT&SC
Replies
1
Views
4,666

Re: A Few Quick, Easy Questions

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...
16. Thread: need help on an assignment :(

by CT&SC
Replies
6
Views
1,428

Re: need help on an assignment :(

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
4. ...
17. Thread: Recursive Sentence Finder

by CT&SC
Replies
4
Views
6,753

[SOLVED] Re: Recursive Sentence Finder

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...
18. Thread: Check for palindrome numbers

by CT&SC
Replies
7
Views
5,240

Re: Check for palindrome numbers

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. ...
19. Thread: Setting markers in strings??

by CT&SC
Replies
3
Views
789

Re: Setting markers in strings??

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
...
20. Thread: count how frequently each character occurs

by CT&SC
Replies
1
Views
1,382

Re: count how frequently each character occurs

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?...
21. Thread: Odd Even Zero Counter?

by CT&SC
Replies
1
Views
4,955

Re: Odd Even Zero Counter?

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...
22. Thread: Recursive Sentence Finder

by CT&SC
Replies
4
Views
6,753

[SOLVED] Re: Recursive Sentence Finder

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...
23. Thread: Anyone know what this code is doing?

by CT&SC
Replies
2
Views
539

Re: Anyone know what this code is doing?

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...
24. Thread: Java Help...

by CT&SC
Replies
1
Views
737

Re: Java Help...

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.

1. sum := 0
2. input := 0...
25. Thread: How can I detect the end of a line in a file ?

by CT&SC
Replies
3
Views
19,390

Re: How can I detect the end of a line in a file ?

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...
Results 1 to 25 of 31
Page 1 of 2 1