Created
December 28, 2023 23:04
-
-
Save joriki/08085c75cfb627c400104a00236f5cd0 to your computer and use it in GitHub Desktop.
find palindromic U-shaped triangular arrays in OEIS; see https://math.stackexchange.com/questions/4835012
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.math.BigInteger; | |
public class OEISScanner { | |
public static void main (String [] args) throws IOException { | |
// OEIS sequence data downloaded from https://oeis.org/stripped.gz | |
BufferedReader reader = new BufferedReader (new FileReader (args [0])); | |
outer: | |
for (;;) { | |
String line = reader.readLine(); | |
if (line == null) | |
break; | |
if (line.startsWith("#")) | |
continue; | |
int space = line.indexOf(' '); | |
String name = line.substring(0,space); | |
String [] terms = line.substring(space + 2).split(","); | |
boolean changed = false; | |
for (int n = 1,i = 0;;n++) { | |
int next = i + n; | |
if (next > terms.length) | |
break; | |
BigInteger last = null; | |
for (int j = 0;j <= n - j - 1;j++) { | |
if (!terms [i + j].equals(terms [i + n - j - 1])) | |
continue outer; | |
try { | |
BigInteger value = new BigInteger (terms [i + j]).abs(); | |
if (j != 0) { | |
if (value.compareTo(last) > 0) | |
continue outer; | |
if (!value.equals(last)) | |
changed = true; | |
} | |
last = value; | |
} catch (NumberFormatException nfe) { | |
continue outer; | |
} | |
} | |
i = next; | |
} | |
if (changed) | |
System.out.println("[" + name + "](https://oeis.org/" + name + ")"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment