Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to define to the rules in an appropriate way in java code and make all valid permutations of {1,2,3,4,5,6,7} and check, which permutations fit into this rules. I have done this already here for an other permutation question: <a href="https://stackoverflow.com/questions/4366119/java-if-condition-question/4370253#4370253">How to write an &quot;all these numbers are different&quot; condition in Java?</a></p> <p>Adapted on your rules, the code can look like this:</p> <pre><code>import java.util.Arrays; class Graph26 { private static final int A = 0; private static final int B = 1; private static final int C = 2; private static final int D = 3; private static final int E = 4; private static final int F = 5; private static final int G = 6; private final static boolean rule1(final int[] n) { return n[A] != 2; } private final static boolean rule2(final int[] n) { return n[A] + n[B] == n[F]; } private final static boolean rule3(final int[] n) { return n[C] - n[D] == n[G]; } private final static boolean rule4(final int[] n) { return n[D] + n[E] == 2*n[F]; } private final static boolean rule5(final int[] n) { return n[E] + n[G] == n[F]; } private final static boolean isValid(final int[] nodes) { return rule1(nodes) &amp;&amp; rule2(nodes) &amp;&amp; rule3(nodes) &amp;&amp; rule4(nodes) &amp;&amp; rule5(nodes); } class Permutation { private final int[] o; private boolean perms = true; public boolean hasPerms() { return perms; } Permutation(final int[] obj) { o = obj.clone(); } private int[] nextPerm() { int temp; int j = o.length - 2; while (o[j] &gt; o[j + 1]) { j--; if (j &lt; 0) { perms = false; break; } } if (perms) { int k = o.length - 1; while (o[j] &gt; o[k]) { k--; } temp = o[k]; o[k] = o[j]; o[j] = temp; int r = o.length - 1; int s = j + 1; while (r &gt; s) { temp = o[s]; o[s] = o[r]; o[r] = temp; r--; s++; } } return o.clone(); } } public static void main(final String[] args) { int[] nodes = new int[] { 1, 2, 3, 4, 5, 6, 7}; final Graph26 graph = new Graph26(); final Permutation p = graph.new Permutation(nodes); int i = 0; while (p.hasPerms()) { if (isValid(nodes)) { System.out.println(Arrays.toString(nodes)); } i++; nodes = p.nextPerm(); } System.out.println(i); } } </code></pre> <p>This will define rules1..5 regarding the rules defined in the question and perform a check on all !7=5040 permutations of {1,2,3,4,5,6,7}. You can see this in action here: <a href="https://ideone.com/wwxG0" rel="nofollow noreferrer">https://ideone.com/wwxG0</a></p> <p>which results in (A,B,C,D,E,F,G): <code>[3, 2, 7, 6, 4, 5, 1]</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload