Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  can anyone explain how to write the following algorithm?  (Read 1581 times)
0 Members and 1 Guest are viewing this topic.
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Posted 2005-06-14 19:25:00 »

What is the algorithm for the following?

I have three locations _,_,_
The first can have 0-2,
The second can have 0-4,
The third can have 0-3

I need to be able to generate the following list:

000
001
002
003
010
011
012
013
020
021
022
023
030
031
032
033
100
101
102
103
110
..and so on.

Can anyone explain how this can be done?

Kommi
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2005-06-14 19:46:14 »

Seems remarkably similar to this one:

http://192.18.37.44/forums/index.php?topic=8617.0


In answer:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
int[] location1 = new int[] {0,1,2};
int[] location2 = new int[] {0,1,2,3,4};
int[] location3 = new int[] {0,1,2,3};

for (int a=0;a<location1.length;a++) {
   for (int b=0;b<location2.length;b++) {
      for (int c=0;c<location3.length;c++) {
            System.out.println(location1[a]+""+location2[b]+""+location3[c]);
      }
   }
}


Might work...

Kev

Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Reply #2 - Posted 2005-06-14 19:49:48 »

Oops, thanks for the response kev, but I forgot to mention that it needs to work for n amount of locations.

Kommi
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #3 - Posted 2005-06-14 20:14:11 »

Whats the link between the number of values available for each of the N entries? i.e. at the moment, why does location

1 = 0-2
2 = 0-4
3 = 0-3

If we had a 4th slow, what would the range be?

Kev

Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Reply #4 - Posted 2005-06-14 20:38:39 »

each location can have any range, there is no relation

0-2, 0-5, 0-3

or

0-1, 0-3, 0-8, 0-4

in my app I have an n amount of files. Each file has a certain amount of lines. I am trying to make all possible comparisons between all the lines. So if I have n = 3 files and each file breaks down like this:
file 1 = 2 lines
file 2 = 5 lines
file 3 = 3 lines

then all possible combos of 0-2, 0-5, 0-3 will be a complete check.


Kommi
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Reply #5 - Posted 2005-06-14 21:27:07 »

nevermind, figured it out. Thank you

Kommi
Offline tonberry1

Junior Member





« Reply #6 - Posted 2005-06-16 10:15:32 »

nevermind, figured it out. Thank you

If the answer is pretty simple, that would be nice to know, because atleast in my opinion it is nice to know how differently other people have solved problems.

I have done similar algorithm by adding n-amount of "NumberUnit"-classes (which can have only numbers 0-9 as their values) into an ArrayList. Of course this is far from efficient if the numbers go up to millions.

-= Life is what you decide it to be - Solid Snake =-
Offline Jeff

JGO Coder




Got any cats?


« Reply #7 - Posted 2005-06-18 20:49:45 »

Sounds simply like 3 nested loops.

Also sounds like homework, which I dont do for people


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Reply #8 - Posted 2005-07-11 23:44:57 »

Arise old thread, for I have need of you again.

Ok coming back with a trickier problem:

let say I have 4 elements {1,2,3,4} and I have 7 spaces. Now lets say that I have a certain amount of each element:
1 = 1
2 = 2
3 = 3
4 = 1

How would I get all the possible combinations of these counts into the 7 spaces?
ex:
combo 1 = 1223334
combo 2 = 1223343
combo 3 = 1223433
combo 4 = 1224333
......
Any help would be greatly appreciated

P.S. this is not homework.

Humm, after a fresh look in the morning, I realise that I can treat them as unqiue elements, generate all possible permutations of unqiue elements, and then get rid of the redundencies.



Kommi
Offline Jeff

JGO Coder




Got any cats?


« Reply #9 - Posted 2005-07-13 08:59:19 »


P.S. this is not homework.


Really?  Then whats the application?

~~fascinated~~

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (35 views)
2014-04-15 18:08:23

BurntPizza (31 views)
2014-04-15 03:46:01

UprightPath (46 views)
2014-04-14 17:39:50

UprightPath (29 views)
2014-04-14 17:35:47

Porlus (46 views)
2014-04-14 15:48:38

tom_mai78101 (67 views)
2014-04-10 04:04:31

BurntPizza (127 views)
2014-04-08 23:06:04

tom_mai78101 (227 views)
2014-04-05 13:34:39

trollwarrior1 (192 views)
2014-04-04 12:06:45

CJLetsGame (199 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!