GOPHERSPACE.DE - P H O X Y
gophering on republic.circumlunar.space
2021-04-10: Project Euler #6 in FOCAL                        rak
================================================================

Project Euler problem 6 "Sum square difference" [0] asks you to
calculate the difference of the sum of squares of the first N=10
natural numbers and the square of the sum of the first N natural
numbers. That is, it asks you to compute the difference

    D = SQUARESUM - SUMSQUARES

where

    SQUARESUM  = (1 + 2 + ... + N)^2
    SUMSQUARES = 1^2 + 2^2 + ... + N^2

I decided to implement it using C-FOCAL on a PiDP/8 running
TSS/8 [1]. It uses the identities

          1 + 2 + ... + N = N * (N + 1) / 2,
    1^2 + 2^2 + ... + N^2 = N^3/3 + N^2/2 + N/6.

*WRITE ALL
C-FOCAL,1969

01.01 C PROJECT EULER SUM SQUARE DIFFERENCE PROBLEM 6
01.02 C COPYRIGHT 2021 RYAN KAVANAGH RAK AT RAK.AC
01.03 C GIVEN N OUTPUT (SUM(X=1..N) X)^2 - (SUM(X=1..N) X^2)
01.04 ASK "ENTER N", N
01.05 SET SQUARESUM=^2
01.06 SET SUMSQUARES=N^3/3 + N^2/2 + N/6
01.07 TYPE "(SUM(X=1..N) X)^2 IS ", SQUARESUM, !
01.08 TYPE "SUM(X=1..N) X^2 IS ", SUMSQUARES, !
01.09 TYPE "DIFFERENCE ", SQUARESUM - SUMSQUARES, !
*GOTO 01.01
ENTER N:10
(SUM(X=1..N) X)^2 IS = 3025.0000
SUM(X=1..N) X^2 IS =  385.0000
DIFFERENCE = 2640.0000
*GOTO 01.01
ENTER N:100
(SUM(X=1..N) X)^2 IS = 25502500
SUM(X=1..N) X^2 IS = 338350.00
DIFFERENCE = 25164200

[0] https://projecteuler.net/problem=6
[1] https://tss8.sdf.org/