phpBB Forum
 
It is currently Wed Mar 25, 2020 4:01 pm




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2, 3  Next
Some Java Advice 
Author Message
HH Donor
HH Donor
User avatar

Joined: Sat Dec 15, 2007 3:03 am
Posts: 303
Location: Roskilde, Denmark
STEAM_0:0:1066641
MCID: ipwndk
Post Re: Some Java Advice
I'm soon there :)

Got this so far:
Code:
-8-7-6-5-4-3-2-1 0-1-2-3-4-5-6-7-8
-7-6-5-4-3-2-1 0 1 0-1-2-3-4-5-6-7
-6-5-4-3-2-1 0 1 2 1 0-1-2-3-4-5-6
-5-4-3-2-1 0 1 2 3 2 1 0-1-2-3-4-5
-4-3-2-1 0 1 2 3 4 3 2 1 0-1-2-3-4
-3-2-1 0 1 2 3 4 5 4 3 2 1 0-1-2-3
-2-1 0 1 2 3 4 5 6 5 4 3 2 1 0-1-2
-1 0 1 2 3 4 5 6 7 6 5 4 3 2 1 0-1
0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0


It's the number of predecessors (numbers above, vertically). Disregard the negatives, they have no meaning.

_________________
I R FERNIUS MAXIMUS


Thu Apr 22, 2010 5:46 pm
Profile E-mail WWW
HH Donor
HH Donor
User avatar

Joined: Sun Feb 15, 2009 9:23 pm
Posts: 4908
Location: Aruba
STEAM_0:1:11237970
MCID: pgt
Post Re: Some Java Advice
nearly done m8! :-D

looks nice so far.

_________________


Thu Apr 22, 2010 5:48 pm
Profile E-mail
HH Donor
HH Donor
User avatar

Joined: Sat Dec 15, 2007 3:03 am
Posts: 303
Location: Roskilde, Denmark
STEAM_0:0:1066641
MCID: ipwndk
Post Re: Some Java Advice
Eureka!

The system has been solved.
Code:
      for (int i = 0, l = 8; i < 9; i++, l--) {
         for (int j = 0; j < 17; j++) {
            int p = (8-l) - Math.abs(j - 8);    // Predecessors
            int d = (8-i);                  // Descendants
            int n = (p > d) ? (d + 1) : (p + 1);
            System.out.print(" " + ((j < l || j > l + (16 - (l+l))) ? " " : n));
         }
         System.out.println();
      }


It generates this:
Code:
                 1               
               1 2 1             
             1 2 3 2 1           
           1 2 3 4 3 2 1         
         1 2 3 4 5 4 3 2 1       
       1 2 3 4 4 4 4 4 3 2 1     
     1 2 3 3 3 3 3 3 3 3 3 2 1   
   1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1


My theory was correct, concerning predecessors and descendants. It's quite simple actually. Count the number of predecessors. -> (8-l) - Math.abs(j - 8)
Code:
                 0               
               0 1 0             
             0 1 2 1 0           
           0 1 2 3 2 1 0         
         0 1 2 3 4 3 2 1 0       
       0 1 2 3 4 5 4 3 2 1 0     
     0 1 2 3 4 5 6 5 4 3 2 1 0   
   0 1 2 3 4 5 6 7 6 5 4 3 2 1 0 
0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0


Then count the number of descendants.
Code:
                 8               
               7 7 7             
             6 6 6 6 6           
           5 5 5 5 5 5 5         
         4 4 4 4 4 4 4 4 4       
       3 3 3 3 3 3 3 3 3 3 3     
     2 2 2 2 2 2 2 2 2 2 2 2 2   
   1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


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



Thu Apr 22, 2010 5:57 pm
Profile E-mail WWW
@H|H Reg
@H|H Reg
User avatar

Joined: Tue Jan 26, 2010 6:31 pm
Posts: 1178
Location: Slovakia/Czech Republic
STEAM_0:1:6032953
BattleTag: Nemko#1878
Post Re: Some Java Advice
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. :D

_________________


My Diablo 3 profile


Thu Apr 22, 2010 5:59 pm
Profile E-mail
HH Donor
HH Donor
User avatar

Joined: Sat Dec 15, 2007 3:03 am
Posts: 303
Location: Roskilde, Denmark
STEAM_0:0:1066641
MCID: ipwndk
Post Re: Some Java Advice
May I ask what class this is for?

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.


Thu Apr 22, 2010 6:11 pm
Profile E-mail WWW
HH Donor
HH Donor
User avatar

Joined: Sun Feb 15, 2009 9:23 pm
Posts: 4908
Location: Aruba
STEAM_0:1:11237970
MCID: pgt
Post Re: Some Java Advice
iPwn u da man ! :D

now go workin on dem apps 8-)


Thu Apr 22, 2010 6:13 pm
Profile E-mail
HH Donor
HH Donor
User avatar

Joined: Sat Dec 15, 2007 3:03 am
Posts: 303
Location: Roskilde, Denmark
STEAM_0:0:1066641
MCID: ipwndk
Post Re: Some Java Advice
Nemko wrote:
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. :D


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.


Thu Apr 22, 2010 6:15 pm
Profile E-mail WWW
HH Donor
HH Donor
User avatar

Joined: Sun Feb 15, 2009 9:23 pm
Posts: 4908
Location: Aruba
STEAM_0:1:11237970
MCID: pgt
Post Re: Some Java Advice
yea will at least try to do it. if i fail i just wait till someone else in my course has it :P


Thu Apr 22, 2010 6:28 pm
Profile E-mail
HH Donor
HH Donor

Joined: Sun Dec 02, 2007 8:47 pm
Posts: 688
STEAM_0:1:15560700
Post Re: Some Java Advice
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.


Fri Apr 23, 2010 10:22 am
Profile E-mail
HH Donor
HH Donor
User avatar

Joined: Sun Feb 15, 2009 9:23 pm
Posts: 4908
Location: Aruba
STEAM_0:1:11237970
MCID: pgt
Post Re: Some Java Advice
Rofl in the mail my teacher sent me :

1) Very special solution
2) You have no clue what that is :-)


Fri Apr 23, 2010 11:56 am
Profile E-mail
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2, 3  Next


Who is online

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

Search for:
Jump to:  
cron
Powered by phpBB © phpBB Group.
Designed by Vjacheslav Trushkin for Free Forum/DivisionCore.