# 04 Examples

What would be a programming language without examples? … just …

• Hello World
• Christmas tree – ASCII-Art
• Geo-Art
• Search for four digits
• Distance
• Divide
• Complex numbers
• Almost perfect numbers
• Sum of divisors
• DATA
• Wurzelzwerg

### Hello World

`PRINT "HELLO WORLD"`

Prints “Hello World” in the output.

### Christmas tree – ASCII art

```Z = 1
WHILE Z != 0
INPUT "ZEILEN:", Z
IF Z = 0 THEN
BREAK
ENDIF
PRINT ""
FOR J = Z TO 1 STEP - 1
ZEILE = " "
FOR I = 1 TO J
ZEILE = ZEILE + " "
NEXT
FOR K = 1 TO (Z+1-J)*2-1
ZEILE = ZEILE + "#"
NEXT
PRINT ZEILE
NEXT
ZEILE = ""
FOR L = 1 TO Z+1
ZEILE = ZEILE + " "
NEXT
ZEILE = ZEILE + "#"
PRINT ZEILE
PRINT ""
WEND  ```

Asks for the number of lines and prints a fir tree in the output.
0 terminates the program.

### Geo-Art

`REM mit Button lat/lon Koordinaten holena = GETLAT()b = GETLON()c = 0.0FOR i = 1 TO 10  PROJECTION(a, b, 100.0, c)  c = c + 36.0  x = GETLAT()  y = GETLON()  WPTSADD(x, y)NEXT`

Reads in a coordinate and saves a circle with radius 100m and 10 points at a distance of 36 degrees in the waypoint list.

### Search for four digits

`FOR Z = 1 TO 9  FOR A = 1 TO 9    FOR H = 1 TO 9      FOR L = 0 TO 9        C = 0        U = Z * 1000 + A * 100 + H * 10 + L        V = A * 1000 + H * 100 + Z * 10 + L        W = H * 1000 + A * 100 + Z * 10 + L        IF ISSQR(U) = 1 THEN           C = C + 1        ENDIF        IF ISSQR(V) = 1 THEN           C = C + 1        ENDIF        IF ISSQR(W) = 1 THEN           C = C + 1        ENDIF        IF C = 3 THEN           PRINT "ZAHL: "; Z, A, H, L        ENDIF      NEXT    NEXT  NEXTNEXT`

Four digits are searched for which, when combined accordingly, form three four-digit square numbers.

### Distance

`R = 197LAT = 50.9621667LON = 11.03585C = 0FOR M = 0 TO 999  FOR S = 1 TO 2    FOR N = 0 TO 999      X = 50 + (57 + M / 1000) / 60      Y = 11 + (S + N / 1000) / 60      D = DISTANCE(LAT, LON, X, Y)      IF D <= R THEN        C = C + 1      ENDIF    NEXT  NEXTNEXTPRINT "Points within radius ", R, " are ", C`

Searches the number of possible coordinates that lie within a radius R around the coordinate (LAT|LON).

### Divide

`FOR A = 1 TO 9 FOR B = 0 TO 9 Z = A * 10000 + 6790 + B C = Z / 72 R = MOD(Z, 72) IF R = 0 THEN PRINT Z, A,B,C ENDIF NEXTNEXT`

These products all cost the same price C and this price is an integer euro amount. (so 1 euro or 2 euros or 3 euros and so on).

The total amount of the purchase price is A679B euros.

Where B is a number from the set of integers from 0 to 9
and A is a number from the set of integers from 1 to 9.
So the total purchase price is five digits.

What are A and B?
And how much does a single product cost now?

### Complex numbers

`DATA 1.91372648, 2.4914364, 3.05909465, 0.71522325DIM LFOR I = 1 TO 2 LISTCLEAR(L) READ X READ Y POLAR(L, X, Y) PRINT LNEXT`

Reads one complex number at a time from a block of data in the form of Cartesian coordinates and converts them to their polar form.

### Almost perfect numbers

`DIM TFOR I = 15 TO 99 LISTCLEAR(T) DIVISORS(T, I) S = SUM(T) - I D = I - 4 IF S = D THEN PRINT I, D, T ENDIFNEXT`

What we are looking for are not perfect numbers, but – let us say – “almost perfect numbers”.

They are defined like this:
A natural number n is said to be an “almost perfect number”, if the sum of all its (positive) divisors except itself is smaller than the number n by a certain difference.

Question: what is the next larger almost perfect number A with respect to the difference 4 after 14?

### Sum of divisors

`DIM TFOR I = 1 TO 999 LISTCLEAR(T) DIVISORS(T, I) S = SUM(T) - I IF S > I THEN PRINT I, S, T END ENDIFNEXT`

There are indeed also natural numbers for which the sum of all their (positive) divisors except themselves is greater than the number itself. What is the smallest natural number B for which this is the case?

### DATA

`DATA 120,064,064,048,008,072,048,000DATA 024,036,004,008,016,032,060,000DATA 012,018,018,012,000,000,000,000DATA 024,036,004,008,004,036,024,000DATA 016,048,080,120,016,016,016,000DATA 000,000,000,000,000,000,000,000DATA 120,064,064,048,008,072,048,000DATA 024,036,004,008,004,036,024,000DATA 120,064,064,048,008,072,048,000DATA 000,000,000,000,000,000,000,000DATA 056,076,076,084,100,100,056,000DATA 016,048,016,016,016,016,056,000DATA 024,036,004,008,004,036,024,000DATA 012,018,018,012,000,000,000,000DATA 056,076,076,084,100,100,056,000DATA 120,064,064,048,008,072,048,000DATA 000,000,000,000,000,000,000,000DATA 016,048,080,120,016,016,016,000DATA 016,048,080,120,016,016,016,000DATA 048,072,072,048,072,072,048,000FOR I = 1 TO 20 FOR J = 1 TO 8 READ A S = CONVERTBASE(A, 10, 2) T = PADLEFT(S, "0", 8) T = SUBST(T, "0", " ", 0) T = SUBST(T, "1", "#", 0) PRINT T NEXT JNEXT I`

`DATA 120,064,064,048,008,072,048,000DATA 024,036,004,008,016,032,060,000DATA 012,018,018,012,000,000,000,000DATA 024,036,004,008,004,036,024,000DATA 016,048,080,120,016,016,016,000DATA 000,000,000,000,000,000,000,000DATA 120,064,064,048,008,072,048,000DATA 024,036,004,008,004,036,024,000DATA 120,064,064,048,008,072,048,000DATA 000,000,000,000,000,000,000,000DATA 056,076,076,084,100,100,056,000DATA 016,048,016,016,016,016,056,000DATA 024,036,004,008,004,036,024,000DATA 012,018,018,012,000,000,000,000DATA 056,076,076,084,100,100,056,000DATA 120,064,064,048,008,072,048,000DATA 000,000,000,000,000,000,000,000DATA 016,048,080,120,016,016,016,000DATA 016,048,080,120,016,016,016,000DATA 048,072,072,048,072,072,048,000SCREEN(1)STROKE(1)ANTIALIAS(0)COLOR(0, 0, 0)FOR I = 1 TO 20 FOR J = 1 TO 8 READ A S = CONVERTBASE(A, 10, 2) T = PADLEFT(S, "0", 8) Y = 100 +I * 9 + J FOR K = 1 TO 8 X = 100 + K C = MID(T, K, 1) IF C = "1" THEN DOT(X, Y) ENDIF NEXT K NEXT JNEXT I`

### Wurzelzwerg

`Lat= 53.4738833Lon= 11.4083167for i = 4 to 20N = i*7 if mod(N,2)=1 then if mod(N,3)=2 then if mod(N,4)=3 then if mod(N,5)=4 then if mod(N,6)=5 then X=N*8+83Y=N*10-8*N-77print "N=",N,"X=",X,"Y=",Yprojection(Lat, Lon, X,Y)La=GETLAT()Lo=GETLON()LaNach=ROUND((La - TRUNC(La))60,3) `
`LoNach=ROUND((Lo - TRUNC(Lo))60,3)`
`print "N"+ STR(TRUNC(La))+"° "+STR(LaNach)+" E"+ STR(TRUNC(Lo))+"° "+STR(LoNach)endifendifendifendifendifnext`

Go from here in the direction of Y degrees exactly X metres.”

To do this find the smallest integer “N” which has a remainder of 1 when divided by 2, a remainder of 2 when divided by 3, a remainder of 3 when divided by 4, a remainder of 4 when divided by 5, a remainder of 5 when divided by 6, but no remainder when divided by 7.

X=N*8+83

Y=N*10-8*N-77