Final Fantasy 13-2 Clock Puzzle (Java)

Needed some code to finish this one… if you made it to the clock size puzzle with 12 sphere’s here’s some java code for you to solve it quickly if you like!
You can use pen and paper if you like. To get all values start by creeping up really slowly until you can’t see the 12:00 number but can see the color if it and thereby tell what the value is going to be. Enter values in the hourMoveValues array and increment the startHourMinusOne value if you need a new starting point.

import java.util.ArrayList;

/**
*
* This class will print out a string of numbers that are similar to a clock
* where one is the first sphere just past noon at the center top. You will have
* to account for the hours you have on the screen. This is the spheres you see
* in the circle. The Array values represent the numbers in the spheres. You may
* have to adjust the Array based on hours. A print out of the possible path
* will show itself if possible. If this is not possible you will have to change
* the start hour minus one variable.
*
* @author Rick
*
*/

public class Main {

static ArrayList<Integer> order = new ArrayList<>();
static Integer[] hourMoveValues;
// you may have to increment this, but 0 is the 1:00 value
static int startHourMinusOne = 4;
// total number of spheres on screen.
static int hours = 12;

public static void main(String[] args) {
reset();
}

private static void reset() {
hourMoveValues = new Integer[hours];
initArray();
order.add(startHourMinusOne);
nextSpacesToMoveCount(startHourMinusOne, order, hourMoveValues);
}

private static void initArray() {
// the position is 1 - 12 on the clock so 0 is really 1:00 value
hourMoveValues[0] = 3;
hourMoveValues[1] = 5;
hourMoveValues[2] = 3;
hourMoveValues[3] = 3;
hourMoveValues[4] = 2;
hourMoveValues[5] = 5;
hourMoveValues[6] = 1;
hourMoveValues[7] = 5;
hourMoveValues[8] = 2;
hourMoveValues[9] = 4;
hourMoveValues[10] = 1;
hourMoveValues[11] = 4;

}

private static void nextSpacesToMoveCount(int index, ArrayList<Integer> order2, Integer[] ints2) {
// check for full order
Integer[] tempInts = new Integer[hours];
copyArrayToTemp(tempInts, ints2);

int moves = tempInts[index];

// block from accepting this as valid next move space
tempInts[index] = -1;

// get pair of next traverse indexes
int moveUp = addToStartOrder(index, moves);
int moveDown = subFromStartOrder(index, moves);

checkForCompleteOrder(order2);

if (tempInts[moveUp] != -1) {
// keep current instance of order separate from the one sent
ArrayList<Integer> currOrder = new ArrayList<Integer>(order2);
currOrder.add(moveUp);
checkForCompleteOrder(currOrder);
nextSpacesToMoveCount(moveUp, currOrder, tempInts);
}
if (moveUp != moveDown) {
if (tempInts[moveDown] != -1) {
// keep current instance of order separate from the one sent
ArrayList<Integer> currOrder = new ArrayList<Integer>(order2);
currOrder.add(moveDown);
checkForCompleteOrder(currOrder);
nextSpacesToMoveCount(moveDown, currOrder, tempInts);
}
}
}

private static void copyArrayToTemp(Integer[] tempInts, Integer[] ints2) {
for (int i = 0; i < hours; i++) {
tempInts[i] = ints2[i];
}
}

private static void checkForCompleteOrder(ArrayList<Integer> currOrder) {
// if the order is full you have a solution
if (currOrder.size() >= hours) {
// get value for index
System.out.println("Complete: numbers are reference from 1 as 1:00");
printOrder(currOrder);
System.exit(0);
}
}

private static void printOrder(ArrayList<Integer> currOrder) {
for (Integer i : currOrder) {
System.out.println(i + 1);
}
}

private static int subFromStartOrder(int startOrder, int spacesToMove) {
// get the new hour based on moves
int tempOrder = startOrder -= spacesToMove;
if (tempOrder < 0) {
tempOrder = hours + tempOrder;
return tempOrder;
}
return tempOrder;
}

private static int addToStartOrder(int startOrder, int spacesToMove) {
// get the new hour based on moves
int tempOrder = startOrder += spacesToMove;
if (tempOrder > (hours - 1)) {
return tempOrder - hours;
}
return tempOrder;
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe for Post Notifications