Task: Prime conspiracy

C: #include <assert.h>
#include <stdbool.h>
#include <stdio.h>

typedef unsigned char byte;

struct Transition {
    byte a, b;
    unsigned int c;
} transitions[100];

void init() {
    int i, j;
    for (i = 0; i < 10; i++) {
        for (j = 0; j < 10; j++) {
            int idx = i * 10 + j;
            transitions[idx].a = i;
            transitions[idx].b = j;
            transitions[idx].c = 0;
        }
    }
}

void record(int prev, int curr) {
    byte pd = prev % 10;
    byte cd = curr % 10;
    int i;

    for (i = 0; i < 100; i++) {
        int z = 0;
        if (transitions[i].a == pd) {
            int t = 0;
            if (transitions[i].b == cd) {
                transitions[i].c++;
                break;
            }
        }
    }
}

void printTransitions(int limit, int last_prime) {
    int i;

    printf("%d primes, last prime considered: %d\n", limit, last_prime);

    for (i = 0; i < 100; i++) {
        if (transitions[i].c > 0) {
            printf("%d->%d  count: %5d  frequency: %.2f\n", transitions[i].a, transitions[i].b, transitions[i].c, 100.0 * transitions[i].c / limit);
        }
    }
}

bool isPrime(int n) {
    int s, t, a1, a2;

    if (n % 2 == 0) return n == 2;
    if (n % 3 == 0) return n == 3;
    if (n % 5 == 0) return n == 5;
    if (n % 7 == 0) return n == 7;
    if (n % 11 == 0) return n == 11;
    if (n % 13 == 0) return n == 13;
    if (n % 17 == 0) return n == 17;
    if (n % 19 == 0) return n == 19;

    
    t = 23;
    a1 = 96;
    a2 = 216;
    s = t * t;
    while (s <= n) {
        if (n % t == 0) return false;

        
        s += a1;
        t += 2;
        a1 += 24;
        assert(t * t == s);

        if (s <= n) {
            if (n % t == 0) return false;

            
            s += a2;
            t += 4;
            a2 += 48;
            assert(t * t == s);
        }
    }

    return true;
}

#define LIMIT 1000000
int main() {
    int last_prime = 3, n = 5, count = 2;

    init();
    record(2, 3);

    while (count < LIMIT) {
        if (isPrime(n)) {
            record(last_prime, n);
            last_prime = n;
            count++;
        }
        n += 2;

        if (count < LIMIT) {
            if (isPrime(n)) {
                record(last_prime, n);
                last_prime = n;
                count++;
            }
            n += 4;
        }
    }

    printTransitions(LIMIT, last_prime);

    return 0;
}










Fortran:       PROGRAM INHERIT	
      USE PRIMEBAG	
      INTEGER MBASE,P0,NHIC	
      PARAMETER (MBASE = 13, P0 = 2, NHIC = 100000000)	
      INTEGER N(0:MBASE - 1,0:MBASE - 1,2:MBASE)	
      INTEGER I,B,D1,D2	
      INTEGER P,PP	

      MSG = 6		
      WRITE (MSG,1) MBASE,P0,NHIC	
    1 FORMAT ("Working in base 2 to ",I0," count the transitions "
     1 "from the low-order digit of one prime number ",/,
     2 "to the low-order digit of its successor. Starting with ",I0,
     3 " and making ",I0," advances.")
      IF (.NOT.GRASPPRIMEBAG(66)) STOP "Gan't grab my file

Chug through the primes.
   10 N = 0	
      P = P0	
      DO I = 1,NHIC	
        PP = P			
        P = NEXTPRIME(P)	
        DO B = 2,MBASE		
          D1 = MOD(PP,B)		
          D2 = MOD(P,B)			
          N(D1,D2,B) = N(D1,D2,B) + 1	
        END DO			
      END DO		
      WRITE (MSG,11) P	
   11 FORMAT ("Ending with ",I0)	

Cast forth the results.
   20 DO B = 2,MBASE	
        WRITE (MSG,21) B		
   21   FORMAT (/,"For base ",I0)	
        WRITE (MSG,22) (D1, D1 = 0,B - 1)	
   22   FORMAT (" Last digit ending  ",I2,66I9)	
        DO D2 = 0,B - 1		
          IF (ALL(N(0:B - 1,D2,B).EQ.0)) CYCLE	
          WRITE (MSG,23) D2,N(0:B - 1,D2,B)	
   23     FORMAT (" next prime ends",I3,":",I2,66I9)	
        END DO			
      END DO		
      END