Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package seelman;
- public class Seelman {
- // 500 million (max_int is only 2.1b)
- public static final int SEQUENCE_MAX = 500000000;
- public static final int SEQUENCE_LENGTH = SEQUENCE_MAX;
- // sequence[i] is the sequence, i.e. sequence[1] = 1, sequence[2] = 3
- int[] sequence = new int[SEQUENCE_LENGTH];
- // is the value (already) in the sequence?
- boolean[] sequenced = new boolean[SEQUENCE_MAX];
- public void checkForEmpties() {
- /*
- * If any sequence from n to (2n-1) is all sequenced while any value x <
- * n is not sequenced, then that value x will be unreachable.
- */
- int firstUnsequenced = SEQUENCE_MAX;
- for (int i = 1; i < SEQUENCE_MAX; i++) {
- if (!sequenced[i]) {
- firstUnsequenced = i;
- break;
- }
- }
- for (int start = firstUnsequenced + 1; start <= SEQUENCE_MAX / 2; start++) {
- boolean broken = false;
- for (int i = start; i < start * 2; i++) {
- if (!sequenced[i]) {
- broken = true;
- break;
- }
- }
- if (!broken) {
- System.out.println("The value " + firstUnsequenced + " is not in the sequence, but every value from "
- + start + " to " + (start * 2 - 1) + " is.");
- return;
- }
- }
- }
- public void createSequence() {
- String str = "";
- for (int i = 1; i < SEQUENCE_LENGTH; i++) {
- int value;
- if (i == 1) {
- value = 1;
- } else {
- int prev = sequence[i - 1];
- value = prev / 2 + prev % 2;
- if (sequenced[value]) {
- value = prev * 3;
- }
- }
- if (value > SEQUENCE_MAX) {
- System.out.println(str);
- System.out.println("Exceeded sequence max after " + i + " entries.");
- checkForEmpties();
- return;
- }
- if (sequenced[value]) {
- System.out.println(str);
- System.out.println("Sequence repeat.");
- return;
- }
- sequence[i] = value;
- sequenced[value] = true;
- str += value + " ";
- if (str.length() > 64) {
- System.out.println(str);
- str = "";
- }
- }
- }
- public static void main(String[] args) {
- Seelman s = new Seelman();
- s.createSequence();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement