My theory was correct, concerning predecessors and descendants. It's quite simple actually. Count the number of predecessors. -> (8-l) - Math.abs(j - 8)
(Obviously they are mirrored - see if you can optimize my code, if I only need to mirror descendants, then my predecessor calculation is way too complex right?) I'm not going to optimize it, so that's something you can have fun with.
If predecessors is below descendants in amount, print predecessors plus one (remember, it didn't count the current number) Otherwise, print the descendants plus one. Look, I'm just using the numbers of the predecessor and descendants as described above!
Notice that I have used INLINE if-then-else constructs.
Code:
int n = (p > d) ? (d + 1) : (p + 1);
means
Code:
int n; if (p > d) n = (d + 1) else n = (p + 1)
(I'm a sucker for short code.)
Oh, and Math.abs just returns the absolute value. (I cut the triangle in half, so I could consider both sides as one)
Last edited by i pwn on Thu Apr 22, 2010 6:09 pm, edited 4 times in total.
I've tried to do this but I had some stupid problems and I cba to find out what was that all about.
But if you want I can help you in the future. I've been working on a project (Car rental business) so I've got some Java skills.
Also, if you get a little skills in Java, I'd recommend you to use netbeans instead, I've been working in BlueJ and I have almost failed the class due to BlueJ being total asshole to me.
These two questions are algorithmic in nature. The language has no relevance to their solution. It could be written in any language, whereas the mathematical solutions are general.
Also, if you get a little skills in Java, I'd recommend you to use netbeans instead, I've been working in BlueJ and I have almost failed the class due to BlueJ being total asshole to me.
Really, get Eclipse. (Get the one for Java developers - don't worry too much about the others, the eclipse world is composed of THOUSANDS of professionals and companies)
Oh, and PGT, do the square yourself My solution is particular to triangles. But squares got to be easier.
NetBeans is better for GUI stuff. It has a really good editor which is something Eclipse does not have at all. I use both at home, but at work it is almost only Eclipse. It's a bit of a holy war this IDE issue
My advice is to try them both and see what you like best.
Users browsing this forum: No registered users and 2 guests
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum