+ 10

Mathematic logic question!

I wont to fix my programm. I have a random array with 1 to 8 no repeat numbers. Not all arrays a good for my programm. Can you find anything can help? Remember that is an array.... ***SLIDER PUZZLE *** https://code.sololearn.com/Wiv9Z9z3L6Az/?ref=app 18732456 ok 32574861 ok 72643158 ok 68351472 ok 24185673 ok 51748632 ok 47623158 ok 18264537 wrong 75281346 wrong 12753486 wrong 13578462 wrong 61735284 wrong 38756241 wrong 76312845 wrong

7th Mar 2017, 4:14 PM
Didi Georgel Danaila
Didi Georgel Danaila - avatar
12 ответов
+ 13
I know this is a stupid idea but could you have an array of all the valid arrays. Then use a random number to select one of these arrays for the game? It'll take a lot of time and not as clever but still works 😅
7th Mar 2017, 10:34 PM
Jafca
Jafca - avatar
+ 9
It's okay I have the solution (thanks Burey for link) I will explain: let's say that we have 8 brothers ... brother age 1......age 5 .....age 8 IF THE SUM ( BROTHERS AFTER ) IS EVEN THE PUZZLE IS SOLVABLE example: 47623158 is ok 4 has 3brothers after (231) 7 = 5.....................(62315) brother8 is bigger 6 = 4 (2315) 2 = 1 (1) 3 = 1 (1) 1 = 0 5 = 0 8 = 0 SUM = 3+5+4+1+1+0+0+0 SUM = 14 14 IS EVEN PUZZLE IS SOLVABLE so random 47623158 is ok now I should write the code
8th Mar 2017, 7:40 AM
Didi Georgel Danaila
Didi Georgel Danaila - avatar
+ 8
@Alvaro it is an Array = [0,1,2,3,4,5,6,7] there are 7 arrays ok and 7 wrong
7th Mar 2017, 4:07 PM
Didi Georgel Danaila
Didi Georgel Danaila - avatar
+ 8
@Burey if you try the program you'll understand
7th Mar 2017, 6:28 PM
Didi Georgel Danaila
Didi Georgel Danaila - avatar
+ 8
Thanks Burey
7th Mar 2017, 6:55 PM
Didi Georgel Danaila
Didi Georgel Danaila - avatar
+ 7
it is very important the position of any number in the array and all the 8 positions of numbers as a group
7th Mar 2017, 4:12 PM
Didi Georgel Danaila
Didi Georgel Danaila - avatar
+ 7
ok did some research and found you some reading material :) this refer to the game 15-puzzle where you have 15 tiles instead of 8 but the solution should be similar ;) https://www.cs.bham.ac.uk/~mdr/teaching/modules04/java2/TilesSolvability.html edit also found this link (contains a function to check): http://math.stackexchange.com/questions/293527/how-to-check-if-a-8-puzzle-is-solvable
7th Mar 2017, 6:53 PM
Burey
Burey - avatar
+ 6
no problem :) i edited my last post, with another link
7th Mar 2017, 6:58 PM
Burey
Burey - avatar
+ 5
what are the rules for a bad positioning? identify those and you can progress to tackle the problem
7th Mar 2017, 5:43 PM
Burey
Burey - avatar
+ 5
i tried it already, i just suck at it :p anyway i understand that the problem is that some arrangments are unsolvable is there a notable pattern for that?
7th Mar 2017, 6:43 PM
Burey
Burey - avatar
+ 4
Are the numbers in the second part individually wrong, or all of them as a whole?
7th Mar 2017, 3:58 PM
Álvaro
0
Turn the number into a string. Otherwise you can't look at digits. Separate characters into a list. For every character, for every character after it, check if they are different. I you find doubles, abort. Otherwise return your number.
8th Mar 2017, 5:54 AM
1of3
1of3 - avatar