This example finds all "letter" structures.
letter a = LMLMMM
letter b = LMMMMM
letter c = MMLMMM
letter d = MMMMMM
Symbol L = live = prime candidate number Symbol M = multiple = composite number
The code can be found on github. https://github.com/cerebrummi/letterfa
It implements "letter analysis" of the prime and gap structure from my paper: https://zenodo.org/records/16829092
CODE
package common;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Locale;
import enums.Letter;
public class StartLetterFa
{
/**
* max number of steps = 18
* otherwise the length of a string is exceeded
*/
private final static int NUMBER_OF_STEPS = 17;
private static HashMap<String, Integer> counter = new HashMap<>();
public static void main(String[] args)
{
LetterFA letterFA = new LetterFA();
for (int i = letterFA.getWalksetBn(); i < NUMBER_OF_STEPS; i++)
{
letterFA.step();
counter.put(letterFA.getPatternSize() + "_" + (i + 1) + "_a",
letterFA.getCounterA());
counter.put(letterFA.getPatternSize() + "_" + (i + 1) + "_b",
letterFA.getCounterB());
counter.put(letterFA.getPatternSize() + "_" + (i + 1) + "_c",
letterFA.getCounterC());
counter.put(letterFA.getPatternSize() + "_" + (i + 1) + "_d",
letterFA.getCounterD());
}
ArrayList<String> keys = new ArrayList<>(counter.keySet());
handleCounter(keys);
}
public static void handleCounter(ArrayList<String> keys)
{
keys.sort(new Comparator<String>()
{
@Override
public int compare(String o1, String o2)
{
if (o1.split("_")[0].compareTo(o2.split("_")[0]) != 0)
{
int o1Int = Integer.parseInt(o1.split("_")[0]);
int o2Int = Integer.parseInt(o2.split("_")[0]);
return Integer.compare(o1Int, o2Int);
}
if (o1.split("_")[1].compareTo(o2.split("_")[1]) != 0)
{
int o1Int = Integer.parseInt(o1.split("_")[1]);
int o2Int = Integer.parseInt(o2.split("_")[1]);
return Integer.compare(o1Int, o2Int);
}
Collator coll = Collator.getInstance(Locale.GERMAN);
coll.setStrength(Collator.PRIMARY);
return coll.compare(o1.split("_")[2], o2.split("_")[2]);
}
});
int a = 0, b = 0, c = 0, d = 0;
double total = 0;
for (String key : keys)
{
if (Letter.a.name().compareTo(key.split("_")[2]) == 0)
{
a = counter.get(key);
}
else if (Letter.b.name().compareTo(key.split("_")[2]) == 0)
{
b = counter.get(key);
}
else if (Letter.c.name().compareTo(key.split("_")[2]) == 0)
{
c = counter.get(key);
}
else if (Letter.d.name().compareTo(key.split("_")[2]) == 0)
{
d = counter.get(key);
total = a + b + c + d;
}
else
{
System.err.println("wrong letter");
System.exit(1);
}
System.out.println(
key.split("_")[2] + " = " + counter.get(key) + " size = " + key);
if (Letter.d.name().compareTo(key.split("_")[2]) == 0)
{
System.out.println("total = " + total);
System.out.println("a = " + (a/total));
System.out.println("b = " + (b/total));
System.out.println("c = " + (c/total));
System.out.println("d = " + (d/total));
System.out.println("--------------------");
}
}
}
}
AND
package common;
import enums.Letter;
/** A fractal algorithm shows prime number patterning.
*
* @author heeren Heeren, B. (2025). A fractal algorithm shows prime number
* patterning. Zenodo. https://doi.org/10.5281/zenodo.16829092
*/
public class LetterFA
{
/**
* 4 is the step where letter a has formed.
*/
private int walksetBn = 4;
private String walksetBPn = "M";
private int offset = 0;
StringBuilder walksetCPn = new StringBuilder(Letter.a.pattern);
private int counterA;
private int counterB;
private int counterC;
private int counterD;
public void step()
{
walksetBn++;
walksetBPn = String.valueOf(walksetCPn.charAt(0));
fractalProcessMove();
if ("L".equalsIgnoreCase(walksetBPn.toString()))
{
fractalProcessCopy();
fractalProcessChange();
}
counterA = 0;
counterB = 0;
counterC = 0;
counterD = 0;
String copyCPn = walksetCPn.toString();
String head = copyCPn.substring(0, offset);
int start = offset;
int end = offset + 6;
for (; end < copyCPn.length();)
{
String letter = copyCPn.substring(start, end);
start += 6;
end += 6;
matchLetter(letter);
}
matchLetter(copyCPn.substring(start) + head);
}
public void matchLetter(String letter)
{
if (Letter.a.pattern.equals(letter))
{
counterA++;
}
else if (Letter.b.pattern.equals(letter))
{
counterB++;
}
else if (Letter.c.pattern.equals(letter))
{
counterC++;
}
else if (Letter.d.pattern.equals(letter))
{
counterD++;
}
else
{
System.err.println("invalid letter " + letter + " n = " + walksetBn);
System.exit(1);
}
}
private void fractalProcessChange()
{
int index = walksetBn + 1;
for (int i = 0; i < walksetCPn.length(); i++)
{
if ((index % walksetBn) == 0)
{
walksetCPn.replace(i, i + 1, "M");
}
index++;
}
}
private void fractalProcessCopy()
{
String copy = walksetCPn.toString();
for (int i = 1; i < walksetBn; i++)
{
walksetCPn.append(copy);
}
}
private void fractalProcessMove()
{
String firstSymbol = walksetCPn.substring(0, 1);
walksetCPn.append(firstSymbol);
walksetCPn.deleteCharAt(0);
offset--;
if (offset < 0)
{
offset = 5;
}
}
public int getCounterA()
{
return counterA;
}
public int getCounterB()
{
return counterB;
}
public int getCounterC()
{
return counterC;
}
public int getCounterD()
{
return counterD;
}
public int getWalksetBn()
{
return walksetBn;
}
public Integer getPatternSize()
{
return walksetCPn.length();
}
}
AND
package enums;
public enum Letter
{
a("LMLMMM"),
b("LMMMMM"),
c("MMLMMM"),
d("MMMMMM");
public final String pattern;
Letter(String pattern)
{
this.pattern = pattern;
}
}