' PBXA64 Release Template sample
' Theme: 02_algorithms_data
' Focus: search, ordering, recurrence, and state reduction
' This headless program derives a deterministic model checksum and prints it.
#COMPILE EXE
#DIM ALL

FUNCTION SampleMix(BYVAL value AS LONG, BYVAL salt AS LONG) AS LONG
    LOCAL shifted AS LONG
    shifted = (value * 17 + salt * 31) MOD 1000003
    shifted = shifted XOR (salt * 13)
    FUNCTION = shifted
END FUNCTION

FUNCTION SampleSeries(BYVAL startValue AS LONG, BYVAL count AS LONG) AS LONG
    LOCAL i AS LONG, total AS LONG, current AS LONG
    current = startValue
    FOR i = 1 TO count
        current = SampleMix(current, i + 148)
        IF (i MOD 3) = 0 THEN total = total + current
        IF (i MOD 5) = 0 THEN total = total XOR current
    NEXT i
    FUNCTION = total + current
END FUNCTION

FUNCTION SampleInvariant(BYVAL checksum AS LONG) AS LONG
    LOCAL normalized AS LONG
    normalized = checksum MOD 97
    IF normalized < 0 THEN normalized = normalized + 97
    FUNCTION = normalized
END FUNCTION

FUNCTION PBMAIN() AS LONG
    LOCAL checksum AS LONG
    checksum = SampleSeries(148, 10)
    checksum = checksum + SampleInvariant(checksum)
    PRINT "02_algorithms_data sample 03 checksum="; checksum
    FUNCTION = 0
END FUNCTION
