• 0
Sign in to follow this  
Followers 0

Numbers 25

Question

Posted · Report post

Eksempel in the top left corner means Example...

What is the numbers in ABCDEF....

post-52981-0-03522500-1351168038_thumb.j

0

Share this post


Link to post
Share on other sites

1 answer to this question

  • 0

Posted · Report post

Very nice puzzle...

5u0oyp.jpg


public class Main {

public static void main(String[] args) {

  int[][] connections = { { 1 }, { 0, 2, 3, 9 }, { 1, 6 }, { 1, 4, 5 },

    { 3, 5, 10 }, { 3, 4, 9, 10 }, { 2, 7, 8, 9 }, { 6, 8 },

    { 6, 7, 9, 11 }, { 1, 5, 6, 8, 10, 11 }, { 4, 5, 9, 11 },

    { 8, 9, 10 } };

  int[] values = new int[connections.length];

  int[] sums = { 26, 31, 13, 19, 19, 25, 20, 19, 6, 6, 7, 8 };

  for (int i = 0; i < values.length; i++) {

   values[i] = -1;

  }

  tryValues(connections, values, sums, 0);

}

private static void tryValues(int[][] connections, int[] values,

   int[] sums, int index) {

  if (index >= values.length) {

   System.out.println(java.util.Arrays.toString(values));

   return;

  }

  for (int i = 0; i < values.length; i++) {

   if (!contains(values, i)) {

    values[index] = i;

    if (isLegal(connections, values, sums)) {

	 tryValues(connections, values, sums, index + 1);

    }

    values[index] = -1;

   }

  }

}

private static boolean isLegal(int[][] connections, int[] values, int[] sums) {

  for (int i = 0; i < values.length; i++) {

   if (values[i] >= 0) {

    int sum = 0;

    boolean incomplete = false;

    for (int con : connections[i]) {

	 if (values[con] < 0) {

	  incomplete = true;

	  break;

	 }

	 sum += values[con];

    }

    if (!incomplete) {

	 if (sum != sums[values[i]]) {

	  return false;

	 }

    }

   }

  }

  return true;

}

private static boolean contains(int[] arr, int num) {

  for (int a : arr) {

   if (a == num) {

    return true;

   }

  }

  return false;

}

}

0

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.