Jump to content

Algorithmic solution


bwoodhouse729

Recommended Posts

Since there's some interest, I updated with a simple example commented at the top of the program.  

 

WallaceErick2, it looks like you didn't make the CombinationGenerator class available to the system when you ran the program.  Make sure you downloaded that to the same directory as Energy_Balance.

  • Like 1
Link to comment
Share on other sites

thanks for the answer. :D

 

For this example:

Sem-_T_tulo-1.png

 

my vars:

//  original_values  = {4, 5, -2, -3, -4, -5, -1, 3, 4, 4, 0, 1, 8}
//  addends            = {{0, 1, 2, 3}, {0, 4, 7, 9}, {3, 6, 8, 12}, {9, 10, 11, 12}}
//  sums                 = {-3, 3, 7, 9}

 

returns:

Position 0: 4 
Position 1: -2 
Position 2: -4 
Position 3: -1 
Position 4: -5 
Position 5: 1000 
Position 6: 4 
Position 7: 1 
Position 8: 0 
Position 9: 3 
Position 10: 5 
Position 11: -3 
Position 12: 4 

 

why position 5 is 1000?

 

Edited by WallaceErick2
Link to comment
Share on other sites

I'm in the 6th puzzle, this one: 

 

YWkHiMG.png

 

The values I put:

 

- {2, -4, 0, -3, 1, -8, 0, -6, -5, -8, -3, 4, -2, -6, -1, -2, -2, 8, -1, 8, 0, 4, -2, 5, 2, 7, 1};

- {{0, 1, 2, 3, 4}, {5, 6, 7}, {8, 9, 10}, {0,7}, {14, 15, 16, 17, 18}, {6, 11, 13, 19, 22}, {21, 22, 23}, {4, 9, 12, 17, 20, 25}, {24, 25, 26}}; 

- {2, 3, -3, 8, 14, -3, -8, -5, -12};

 

> Runs program

> No solution found ?

 

Edited by LucasDiasC
Link to comment
Share on other sites

WallaceErick2, my default value for solutions was 1000 to indicate the algorithm didn't find a value for it.  Here it's because there's no constraint involving position 5.  Of course, position 5 just takes the remaining number that doesn't show up in any other position.

 

LucasDiasC, there must be a bug somewhere preventing it from considering all cases.  If it continues to be a problem I can debug further.  However, when I rearranged the constraints from smallest to largest ({0, 7} first for example, and of course move its sum to the front of the sums, then some 3-length constraints, etc.), it quickly finds a solution.

 

Position 0: 0 
Position 1: 1 
Position 2: -8 
Position 3: 4 
Position 4: 5 
Position 5: -4 
Position 6: -1 
Position 7: 8 
Position 8: 2 
Position 9: -3 
Position 10: -2 
Position 11: -2 
Position 12: -3 
Position 13: -1 
Position 14: 0 
Position 15: -5 
Position 16: 8 
Position 17: 4 
Position 18: 7 
Position 19: 1 
Position 20: -2 
Position 21: -6 
Position 22: 0 
Position 23: -2 
Position 24: -8 
Position 25: -6 
Position 26: 2 

Edited by bwoodhouse729
  • Like 1
Link to comment
Share on other sites

37 minutes ago, bwoodhouse729 said:

WallaceErick2, my default value for solutions was 1000 to indicate the algorithm didn't find a value for it.  Here it's because there's no constraint involving position 5.  Of course, position 5 just takes the remaining number that doesn't show up in any other position.

 

LucasDiasC, there must be a bug somewhere preventing it from considering all cases.  If it continues to be a problem I can debug further.  However, when I rearranged the constraints from smallest to largest ({0, 7} first for example, and of course move its sum to the front of the sums, then some 3-length constraints, etc.), it quickly finds a solution.

 

Position 0: 0 
Position 1: 1 
Position 2: -8 
Position 3: 4 
Position 4: 5 
Position 5: -4 
Position 6: -1 
Position 7: 8 
Position 8: 2 
Position 9: -3 
Position 10: -2 
Position 11: -2 
Position 12: -3 
Position 13: -1 
Position 14: 0 
Position 15: -5 
Position 16: 8 
Position 17: 4 
Position 18: 7 
Position 19: 1 
Position 20: -2 
Position 21: -6 
Position 22: 0 
Position 23: -2 
Position 24: -8 
Position 25: -6 
Position 26: 2 

Yeah, I was going to try doing that, thanks man, tomorrow I'll probably use it for the remaining levels

Link to comment
Share on other sites

9 hours ago, bwoodhouse729 said:

WallaceErick2, my default value for solutions was 1000 to indicate the algorithm didn't find a value for it.  Here it's because there's no constraint involving position 5.  Of course, position 5 just takes the remaining number that doesn't show up in any other position.

 

 

Thanks for the solution, bro.

I will be create an web interface for this... its ok to use your code?

 

 

 

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

Yes you need to 'set path' to java JDK in command prompt. Only then you can run the 'javac' command. 

 

@bwoodhouse729, thank you very much for the work you have put in to the program. It helped me out on a few of the puzzle which I could not figure out on my own!

  • Like 1
Link to comment
Share on other sites

Took me a while to figure out how to get this to work. A slightly more detailed explanation would have saved me quite a bit of time, but I did my research and got it sorted.

 

Doesn't seem to work for some of the later puzzles. I couldn't get a solution for Hard 3, so I solved it manually. Now I'm stuck on Hard 4. I've tried several resets, and re-entered the data to make sure it wasn't user error, but I never get a solution. Has anyone successfully used it for the more complex levels?

Link to comment
Share on other sites

14 minutes ago, diskdocx said:

Took me a while to figure out how to get this to work. A slightly more detailed explanation would have saved me quite a bit of time, but I did my research and got it sorted.

 

Doesn't seem to work for some of the later puzzles. I couldn't get a solution for Hard 3, so I solved it manually. Now I'm stuck on Hard 4. I've tried several resets, and re-entered the data to make sure it wasn't user error, but I never get a solution. Has anyone successfully used it for the more complex levels?

 

I used it for every single one except the last square one. Hard 4 was one of the ones that took me the longest, just took a lot of resetting and rearranging the order of the solutions to get it to work. Pretty sure it was one of the ones I let get to a couple million flag calls before it actually worked. 

  • Like 2
Link to comment
Share on other sites

There can be a very large number of possibilities for Hard 4 and Square 4, especially if you were unlucky in puzzle generation, so the program probably keeps computing without finding a solution.  All I can offer without overhauling the program is to make sure you list the row and column constraints in decreasing order, then if it's still not fast enough, try initially arranging the values based roughly on the row sums and column sums (larger sums use larger values, etc.)

  • Like 1
Link to comment
Share on other sites

3 hours ago, Gage said:

 

I used it for every single one except the last square one. Hard 4 was one of the ones that took me the longest, just took a lot of resetting and rearranging the order of the solutions to get it to work. Pretty sure it was one of the ones I let get to a couple million flag calls before it actually worked. 

 

3 hours ago, bwoodhouse729 said:

There can be a very large number of possibilities for Hard 4 and Square 4, especially if you were unlucky in puzzle generation, so the program probably keeps computing without finding a solution.  All I can offer without overhauling the program is to make sure you list the row and column constraints in decreasing order, then if it's still not fast enough, try initially arranging the values based roughly on the row sums and column sums (larger sums use larger values, etc.)

Thanks both, I finally got it.  I left it runners get and it finally solved it, but I had reset the puzzle. Tried a couple more, then one popped almost immediately.

 

Just square 4 left, and I'm holding that for the weekend plat party ?

  • Like 1
Link to comment
Share on other sites

1 hour ago, Leo_the_Lion25 said:

I've been trying to get the code to work with Notepad but fail. I haven't used Java in years. I forgot how to use Netbeans as well. 

 

use eclipse, its easy.

 

---------

 

i've finished the interface... integration with backend is coming son...

http://www.platinas.com.br/energy-balance/

 

anyone have a vps server to host?

its very expensive.

 

  • Like 1
Link to comment
Share on other sites

2 hours ago, WallaceErick2 said:

 

use eclipse, its easy.

 

---------

 

i've finished the interface... integration with backend is coming son...

http://www.platinas.com.br/energy-balance/

 

anyone have a vps server to host?

its very expensive.

 

I've tried using your link, but I keep getting an error and doesn't work can you help out with a sample/explanation.  

Link to comment
Share on other sites

i made a example picture for our trophy community at facebook.

 

 

i have to say, that the java program took realtive long sometimes. sometimes so long, that i solved the puzzle in the meantime. if you use lesser rows, you can get an idea how to solve the puzzle and do the rest on your own. you have to adjust the parameter in the .java file and than compile it with javac. you can run the compiled code with java. it helps alot but it didnt solve everything for you.

Link to comment
Share on other sites

I'm trying to run the program on this site: http://www.browxy.com/

 

If we can get it running on their all we have to do is simply click on the get URL option and we can all use the same program. The issue I have is that I cannot get both programs to find each other's locations. 

 

 

My errors reading this

 

Quote

Compilation Errors Detected

Line: 182
cannot find symbol
  symbol:   class CombinationGenerator
  location: class Energy_Balance

Line: 182
cannot find symbol
  symbol:   class CombinationGenerator
  location: class Energy_Balance
 

 

Edited by Leo_the_Lion25
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...