Facebook
From Colorant Macaque, 4 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 210
  1. public static List<Integer> cellCompete(int[] states, int days) {
  2.     int edge = 0;
  3.     int counter = 1;
  4.     int[] temp = new int[states.length];
  5.     while (counter <= days) {
  6.         for (int i = 0; i <= states.length - 1; i++) {
  7.             if (i == 0) {
  8.                 temp[i] = states[i + 1] == edge ? 0 :1;
  9.             } else if (i == states.length - 1) {
  10.                 temp[i] = states[i - 1] == edge ? 0 : 1;
  11.             } else {
  12.                 temp[i] = states[i - 1] == states[i + 1] ? 0 : 1;
  13.             }
  14.         }
  15.         counter++;
  16.         System.arraycopy(temp, 0, states,0, states.length);
  17.     }
  18.     List<Integer> list = Arrays.stream(states).boxed().collect(Collectors.toList());
  19.     return list;
  20. }

Replies to Untitled rss

Title Name Language When
Re: Untitled Stained Meerkat java 4 Years ago.