Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (762) Games in Android Showcase (229) games submitted by our members Games in WIP (847) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 can anyone explain how to write the following algorithm?  (Read 2828 times) 0 Members and 1 Guest are viewing this topic.
Kommi

Junior Devvie

All opinions will be lined up and shot!

 « Posted 2005-06-14 17: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
kevglass

« JGO Spiffy Duke »

Medals: 319
Projects: 25
Exp: 22 years

Coder, Trainee Pixel Artist, Game Reviewer

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

Seems remarkably similar to this one:

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

 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

Might work...

Kev

Kommi

Junior Devvie

All opinions will be lined up and shot!

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

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

Kommi
kevglass

« JGO Spiffy Duke »

Medals: 319
Projects: 25
Exp: 22 years

Coder, Trainee Pixel Artist, Game Reviewer

 « Reply #3 - Posted 2005-06-14 18: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

Kommi

Junior Devvie

All opinions will be lined up and shot!

 « Reply #4 - Posted 2005-06-14 18: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
Kommi

Junior Devvie

All opinions will be lined up and shot!

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

nevermind, figured it out. Thank you

Kommi
tonberry1

Junior Devvie

 « Reply #6 - Posted 2005-06-16 08: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 =-
Jeff

JGO Coder

Got any cats?

 « Reply #7 - Posted 2005-06-18 18: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
Kommi

Junior Devvie

All opinions will be lined up and shot!

 « Reply #8 - Posted 2005-07-11 21: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
Jeff

JGO Coder

Got any cats?

 « Reply #9 - Posted 2005-07-13 06: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

 EgonOlsen (361 views) 2018-06-10 19:43:48 EgonOlsen (363 views) 2018-06-10 19:43:44 EgonOlsen (302 views) 2018-06-10 19:43:20 DesertCoockie (539 views) 2018-05-13 18:23:11 nelsongames (867 views) 2018-04-24 18:15:36 nelsongames (850 views) 2018-04-24 18:14:32 ivj94 (1302 views) 2018-03-24 14:47:39 ivj94 (423 views) 2018-03-24 14:46:31 ivj94 (1085 views) 2018-03-24 14:43:53 Solater (441 views) 2018-03-17 05:04:08
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 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