# associative array handling using hashing                                   #

# the modes allowed as associative array element values - change to suit     #
MODE AAVALUE = STRING;
# the modes allowed as associative array element keys - change to suit       #
MODE AAKEY   = STRING;
# nil element value                                                          #
REF AAVALUE nil value = NIL;

# an element of an associative array                                         #
MODE AAELEMENT = STRUCT( AAKEY key, REF AAVALUE value );
# a list of associative array elements - the element values with a           #
# particular hash value are stored in an AAELEMENTLIST                       #
MODE AAELEMENTLIST = STRUCT( AAELEMENT element, REF AAELEMENTLIST next );
# nil element list reference                                                 #
REF AAELEMENTLIST nil element list = NIL;
# nil element reference                                                      #
REF AAELEMENT     nil element      = NIL;

# the hash modulus for the associative arrays                                #
INT hash modulus = 256;

# generates a hash value from an AAKEY - change to suit                      #
OP HASH = ( STRING key )INT:
BEGIN
    INT result := ABS ( UPB key - LWB key ) MOD hash modulus;
    FOR char pos FROM LWB key TO UPB key DO
        result PLUSAB ( ABS key[ char pos ] - ABS " " );
        result MODAB  hash modulus
    OD;
    result
END; # HASH #

# a mode representing an associative array                                    #
MODE AARRAY = STRUCT( [ 0 : hash modulus - 1 ]REF AAELEMENTLIST elements
                    , INT                                       curr hash
                    , REF AAELEMENTLIST                         curr position
                    );

# initialises an associative array so all the hash chains are empty           #
OP   INIT = ( REF AARRAY array )REF AARRAY:
     BEGIN
         FOR hash value FROM 0 TO hash modulus - 1 DO ( elements OF array )[ hash value ] := nil element list OD;
         array
     END; # INIT #

# gets a reference to the value corresponding to a particular key in an      #
# associative array - the element is created if it doesn't exist             #
PRIO // = 1;
OP   // = ( REF AARRAY array, AAKEY key )REF AAVALUE:
BEGIN
    REF AAVALUE result;
    INT         hash value = HASH key;
    # get the hash chain for the key #
    REF AAELEMENTLIST element := ( elements OF array )[ hash value ];
    # find the element in the list, if it is there #
    BOOL found element := FALSE;
    WHILE ( element ISNT nil element list )
      AND NOT found element
    DO
        found element := ( key OF element OF element = key );
        IF found element
        THEN
            result  := value OF element OF element
        ELSE
            element := next OF element
        FI
    OD;
    IF NOT found element
    THEN
        # the element is not in the list #
        # - add it to the front of the hash chain #
        ( elements OF array )[ hash value ]
                            := HEAP AAELEMENTLIST
                            := ( HEAP AAELEMENT := ( key
                                                   , HEAP AAVALUE := ""
                                                   )
                               , ( elements OF array )[ hash value ]
                               );
        result := value OF element OF ( elements OF array )[ hash value ]
    FI;
    result
END; # // #

# returns TRUE if array contains key, FALSE otherwise                        #
PRIO CONTAINSKEY = 1;
OP   CONTAINSKEY = ( REF AARRAY array, AAKEY key )BOOL:
BEGIN
    # get the hash chain for the key #
    REF AAELEMENTLIST element := ( elements OF array )[ HASH key ];
    # find the element in the list, if it is there #
    BOOL found element := FALSE;
    WHILE ( element ISNT nil element list )
      AND NOT found element
    DO
        found element := ( key OF element OF element = key );
        IF NOT found element
        THEN
            element := next OF element
        FI
    OD;
    found element
END; # CONTAINSKEY #

# gets the first element (key, value) from the array                         #
OP FIRST = ( REF AARRAY array )REF AAELEMENT:
BEGIN
    curr hash     OF array := LWB ( elements OF array ) - 1;
    curr position OF array := nil element list;
    NEXT array
END; # FIRST #

# gets the next element (key, value) from the array                          #
OP NEXT  = ( REF AARRAY array )REF AAELEMENT:
BEGIN
    WHILE ( curr position OF array IS nil element list )
      AND   curr hash     OF array < UPB ( elements OF array )
    DO
        # reached the end of the current element list - try the next         #
        curr hash     OF array +:= 1;
        curr position OF array  := ( elements OF array )[ curr hash OF array ]
    OD;
    IF   curr hash OF array > UPB ( elements OF array )
    THEN
        # no more elements #
        nil element
    ELIF curr position OF array IS nil element list
    THEN
        # reached the end of the table #
        nil element
    ELSE
        # have another element #
        REF AAELEMENTLIST found element = curr position OF array;
        curr position OF array := next OF curr position OF array;
        element OF found element
    FI
END; # NEXT #

# test the associative array #
BEGIN
    # create an array and add some values  #
    REF AARRAY a1 := INIT LOC AARRAY;
    a1 // "k1" := "k1 value";
    a1 // "z2" := "z2 value";
    a1 // "k1" := "new k1 value";
    a1 // "k2" := "k2 value";
    a1 // "2j" := "2j value";
    # iterate over the values #
    REF AAELEMENT e := FIRST a1;
    WHILE e ISNT nil element
    DO
        print( ( "  (" + key OF e + ")[" + value OF e + "]", newline ) );
        e := NEXT a1
    OD
END


doors = [false] * 100

for pass til doors.length
    for i from pass til doors.length by pass + 1
        ! = doors[i]

for i til doors.length
    console.log 'Door %d is %s.', i + 1, if doors[i] then 'open' else 'closed'


; create a dictionary
d: #[
	name: 		"john"
	surname: 	"doe"
	age: 		34
]

; Iterate over key/value pairs
loop d [key,value][
	print ["key =" key ", value =" value]
]

print "----"

; Iterate over keys
loop keys d [k][
	print ["key =" k]
]

print "----"

; Iterate over values
loop values d [v][
	print ["value =" v]
]


doors = []

for pass in [1..100]
  for i in [pass..100] by pass
    doors[i] = !doors[i]

console.log "Doors #{index for index, open of doors when open} are open"

# matrix output
console.log doors.map (open) -> +open


; Create an associative array
obj := Object("red", 0xFF0000, "blue", 0x0000FF, "green", 0x00FF00)
enum := obj._NewEnum()
While enum[key, value]
    t .= key "=" value "`n"
MsgBox % t


	doorCount = 1;
	doorList = "";
	// create all doors and set all doors to open
	while (doorCount LTE 100) {
		doorList = ListAppend(doorList,"1");
		doorCount = doorCount + 1;
	}
	loopCount = 2;
	doorListLen = ListLen(doorList);
	while (loopCount LTE 100) {
		loopDoorListCount = 1;
		while (loopDoorListCount LTE 100) {
			testDoor = loopDoorListCount / loopCount;
			if (testDoor EQ Int(testDoor)) {
				checkOpen = ListGetAt(doorList,loopDoorListCount);
				if (checkOpen EQ 1) {
					doorList = ListSetAt(doorList,loopDoorListCount,"0");
				} else {
					doorList = ListSetAt(doorList,loopDoorListCount,"1");
				}
			}
			loopDoorListCount = loopDoorListCount + 1;
		}
		loopCount = loopCount + 1;
	}


INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit

PROC Main()
  REAL z,res

  Put(125) PutE() ;clear the screen

  IntToReal(0,z)
  Power(z,z,res)

  PrintR(z) Print("^")
  PrintR(z) Print("=")
  PrintRE(res)
RETURN


with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Long_Integer_Text_IO,
  Ada.Long_Long_Integer_Text_IO, Ada.Float_Text_IO, Ada.Long_Float_Text_IO,
  Ada.Long_Long_Float_Text_IO;
use  Ada.Text_IO, Ada.Integer_Text_IO, Ada.Long_Integer_Text_IO,
  Ada.Long_Long_Integer_Text_IO, Ada.Float_Text_IO, Ada.Long_Float_Text_IO,
  Ada.Long_Long_Float_Text_IO;

procedure Test5 is

   I    : Integer           := 0;
   LI   : Long_Integer      := 0;
   LLI  : Long_Long_Integer := 0;
   F    : Float             := 0.0;
   LF   : Long_Float        := 0.0;
   LLF  : Long_Long_Float   := 0.0;
   Zero : Natural           := 0;

begin
   Put ("Integer           0^0 = ");
   Put (I ** Zero, 2);   New_Line;
   Put ("Long Integer      0^0 = ");
   Put (LI ** Zero, 2);  New_Line;
   Put ("Long Long Integer 0^0 = ");
   Put (LLI ** Zero, 2); New_Line;
   Put ("Float           0.0^0 = ");
   Put (F ** Zero);   New_Line;
   Put ("Long Float      0.0^0 = ");
   Put (LF ** Zero);  New_Line;
   Put ("Long Long Float 0.0^0 = ");
   Put (LLF ** Zero); New_Line;
end Test5;


BEGIN {
  a["hello"] = 1
  a["world"] = 2
  a["!"] = 3

  # iterate over keys, undefined order
  for(key in a) {
    print key, a[key]
  }
}


births (('Washington' 1732) ('Lincoln' 1809) ('Roosevelt' 1882) ('Kennedy' 1917)) ls2map ! <


DECLARE associative ASSOC STRING

associative("abc") = "first three"
associative("mn") = "middle two"
associative("xyz") = "last three"

LOOKUP associative TO keys$ SIZE amount
FOR i = 0 TO amount - 1
    PRINT keys$[i], ":", associative(keys$[i])
NEXT


0010 DIM doors#(100)
0020 FOR pass#:=1 TO 100 DO
0030   FOR door#:=pass# TO 100 STEP pass# DO doors#(door#):=NOT doors#(door#)
0040 ENDFOR pass#
0050 FOR door#:=1 TO 100 DO
0060   IF doors#(door#) THEN PRINT "Door ",door#," is open."
0070 ENDFOR door#
0080 END


      REM Store some values with their keys:
      PROCputdict(mydict$, "FF0000", "red")
      PROCputdict(mydict$, "00FF00", "green")
      PROCputdict(mydict$, "0000FF", "blue")

      REM Iterate through the dictionary:
      i% = 1
      REPEAT
        i% = FNdict(mydict$, i%, v$, k$)
        PRINT v$, k$
      UNTIL i% = 0
      END

      DEF PROCputdict(RETURN dict$, value$, key$)
      IF dict$ = "" dict$ = CHR$(0)
      dict$ += key$ + CHR$(1) + value$ + CHR$(0)
      ENDPROC

      DEF FNdict(dict$, I%, RETURN value$, RETURN key$)
      LOCAL J%, K%
      J% = INSTR(dict$, CHR$(1), I%)
      K% = INSTR(dict$, CHR$(0), J%)
      value$ = MID$(dict$, I%+1, J%-I%-1)
      key$ = MID$(dict$, J%+1, K%-J%-1)
      IF K% >= LEN(dict$) THEN K% = 0
      = K%


(  new$hash:?myhash
& (myhash..insert)$(title."Some title")
& (myhash..insert)$(formula.a+b+x^7)
& (myhash..insert)$(fruit.apples oranges kiwis)
& (myhash..insert)$(meat.)
& (myhash..insert)$(fruit.melons bananas)
& (myhash..remove)$formula
& (myhash..insert)$(formula.x^2+y^2)
&   (myhash..forall)
  $ (
    =   key value
      .     whl
          ' ( !arg:(?key.?value) ?arg
            & put$("key:" !key "\nvalue:" !value \n)
            )
        & put$\n
    )
);


10 D=100: DIMD(D): P=1
20 PRINT CHR$(147);"PASS: ";P
22 FOR I=P TO D STEP P: D(I)=NOTD(I): NEXT
30 IF P=100 THEN 40
32 P=P+1: GOTO20
40 PRINT: PRINT"THE FOLLOWING DOORS ARE OPEN: "
42 FOR I=1 TO D: IF D(I)=-1 THEN PRINTI;
44 NEXT


# syntax: GAWK -f ZERO_TO_THE_ZERO_POWER.AWK
BEGIN {
    print(0 ^ 0)
    exit(0)
}


h = [ hello: 1 world: 2 :! : 3]

#Iterate over key, value pairs
h.each { k, v |
  p "Key: #{k} Value: #{v}"
}

#Iterate over keys
h.each_key { k |
  p "Key: #{k}"
}

#Iterate over values
h.each_value { v |
  p "Value: #{v}"
}


using System;
using System.Collections.Generic;

namespace AssocArrays
{
    class Program
    {
        static void Main(string[] args)
        {

            Dictionary<string,int> assocArray = new Dictionary<string,int>();

            assocArray["Hello"] = 1;
            assocArray.Add("World", 2);
            assocArray["!"] = 3;

            foreach (KeyValuePair<string, int> kvp in assocArray)
            {
                Console.WriteLine(kvp.Key + " : " + kvp.Value);
            }

            foreach (string key in assocArray.Keys)
            {
                Console.WriteLine(key);
            }

            foreach (int val in assocArray.Values)
            {
                Console.WriteLine(val.ToString());
            }
        }
    }
}


(defun visit-door (doors doornum value1 value2)
  "visits a door, swapping the value1 to value2 or vice-versa"
  (let ((d (copy-list doors))
        (n (- doornum 1)))
    (if (eql  (nth n d) value1)
        (setf (nth n d) value2)
      (setf (nth n d) value1))
    d))

(defun visit-every (doors num iter value1 value2)
  "visits every 'num' door in the list"
  (if (> (* iter num) (length doors))
      doors
    (visit-every (visit-door doors (* num iter) value1 value2)
                 num
                 (+ 1 iter)
                 value1
                 value2)))

(defun do-all-visits (doors cnt value1 value2)
  "Visits all doors changing the values accordingly"
  (if (< cnt 1)
      doors
    (do-all-visits (visit-every doors cnt 1 value1 value2)
                   (- cnt 1)
                   value1
                   value2)))

(defun print-doors (doors)
  "Pretty prints the doors list"
  (format T "~{~A ~A ~A ~A ~A ~A ~A ~A ~A ~A~%~}~%" doors))

(defun start (&optional (size 100))
  "Start the program"
  (let* ((open "_")
         (shut "#")
         (doors (make-list size :initial-element shut)))
    (print-doors (do-all-visits doors size open shut))))


#include <iostream>
#include <map>
#include <string>

int main() {
  std::map<std::string, int> dict {
    {"One", 1},
    {"Two", 2},
    {"Three", 7}
  };

  dict["Three"] = 3;

  std::cout << "One: " << dict["One"] << std::endl;
  std::cout << "Key/Value pairs: " << std::endl;
  for(auto& kv: dict) {
    std::cout << "  " << kv.first << ": " << kv.second << std::endl;
  }

  return 0;
}


MODULE Doors100;
IMPORT StdLog;

PROCEDURE Do*;
VAR
	i,j: INTEGER;
	closed: ARRAY 101 OF BOOLEAN;
BEGIN
	(* initialization of closed to true *)
	FOR i := 0 TO LEN(closed) - 1 DO closed[i] := TRUE END;
	(* process *)
	FOR i := 1 TO LEN(closed)  DO;
		j := 1;
		WHILE j < LEN(closed) DO
			IF j MOD i = 0 THEN closed[j] := ~closed[j] END;INC(j)
		END
	END;
	(* print results *)
	i := 1;
	WHILE  i < LEN(closed)  DO
		IF (i - 1) MOD 10 = 0 THEN StdLog.Ln END;
		IF closed[i] THEN StdLog.String("C ") ELSE StdLog.String("O ") END;
		INC(i)
	END;
END Do;
END Doors100.


#include <stdio.h>
#include <math.h>
#include <complex.h>

int main()
{
	printf("0 ^ 0 = %f\n", pow(0,0));
        double complex c = cpow(0,0);
	printf("0+0i ^ 0+0i = %f+%fi\n", creal(c), cimag(c));
	return 0;
}


using System;

namespace ZeroToTheZeroeth
{
    class Program
    {
        static void Main(string[] args)
        {
            double k = Math.Pow(0, 0);
            Console.Write("0^0 is {0}", k);
        }
    }
}


#include <iostream>
#include <cmath>
#include <complex>

int main()
{
  std::cout << "0 ^ 0 = " << std::pow(0,0) << std::endl;
  std::cout << "0+0i ^ 0+0i = " <<
    std::pow(std::complex<double>(0),std::complex<double>(0)) << std::endl;
  return 0;
}


F getDivisors(n)
   V divs = [1, n]
   V i = 2
   L i * i <= n
      I n % i == 0
         divs [+]= i

         V j = n I/ i
         I i != j
            divs [+]= j
      i++
   R divs

F isPartSum(divs, sum)
   I sum == 0
      R 1B

   V le = divs.len
   I le == 0
      R 0B

   V last = divs.last
   [Int] newDivs
   L(i) 0 .< le - 1
      newDivs [+]= divs[i]

   I last > sum
      R isPartSum(newDivs, sum)
   E
      R isPartSum(newDivs, sum) | isPartSum(newDivs, sum - last)

F isZumkeller(n)
   V divs = getDivisors(n)
   V s = sum(divs)

   I s % 2 == 1
      R 0B

   I n % 2 == 1
      V abundance = s - 2 * n
      R abundance > 0 & abundance % 2 == 0

   R isPartSum(divs, s I/ 2)

print(‘The first 220 Zumkeller numbers are:’)
V i = 2
V count = 0
L count < 220
   I isZumkeller(i)
      print(‘#3 ’.format(i), end' ‘’)
      count++
      I count % 20 == 0
         print()
   i++

print("\nThe first 40 odd Zumkeller numbers are:")
i = 3
count = 0
L count < 40
   I isZumkeller(i)
      print(‘#5 ’.format(i), end' ‘’)
      count++
      I count % 10 == 0
         print()
   i += 2

print("\nThe first 40 odd Zumkeller numbers which don't end in 5 are:")
i = 3
count = 0
L count < 40
   I i % 10 != 5 & isZumkeller(i)
      print(‘#7 ’.format(i), end' ‘’)
      count++
      I count % 8 == 0
         print()
   i += 2


shared void run() {

	value myMap = map {
		"foo" -> 5,
		"bar" -> 10,
		"baz" -> 15
	};

	for(key in myMap.keys) {
		print(key);
	}

	for(item in myMap.items) {
		print(item);
	}

	for(key->item in myMap) {
		print("``key`` maps to ``item``");
	}

}


var A = [ "H2O" => "water", "NaCl" => "salt", "O2" => "oxygen" ];

for k in A.domain do
    writeln("have key: ", k);

for v in A do
    writeln("have value: ", v);

for (k,v) in zip(A.domain, A) do
    writeln("have element: ", k, " -> ", v);


(doseq [[k v] {:a 1, :b 2, :c 3}]
  (println k "=" v))

(doseq [k  (keys {:a 1, :b 2, :c 3})]
  (println k))

(doseq [v  (vals {:a 1, :b 2, :c 3})]
  (println v))


Require Import List.

Fixpoint rep {A} (a : A) n :=
  match n with
    | O => nil
    | S n' => a::(rep a n')
  end.

Fixpoint flip (l : list bool) (n k : nat) : list bool :=
  match l with
    | nil => nil
    | cons h t => match k with
                | O => (negb h) :: (flip t n n)
                | S k' => h :: (flip t n k')
              end
  end.

Definition flipeach l n := flip l n n.

Fixpoint flipwhile l n :=
  match n with
    | O => flipeach l 0
    | S n' => flipwhile (flipeach l (S n')) n'
  end.

Definition prison cells := flipwhile (rep false cells) cells.


ZEROPOW
  // default behavior is incorrect:
  set (x,y) = 0
  w !,"0 to the 0th power (wrong): "_(x**y)  ; will output 0

  // if one or both of the values is a double, this works
  set (x,y) = $DOUBLE(0)
  w !,"0 to the 0th power (right): "_(x**y)

  quit


user=> (use 'clojure.math.numeric-tower)
user=> (expt 0 0)
1

; alternative java-interop route:
user=> (Math/pow 0 0)
1.0


start_up = proc ()
    zz_int: int := 0 ** 0
    zz_real: real := 0.0 ** 0.0

    po: stream := stream$primary_output()
    stream$putl(po, "integer 0**0: " || int$unparse(zz_int))
    stream$putl(po, "real 0**0: " || f_form(zz_real, 1, 1))
end start_up


identification division.
program-id. zero-power-zero-program.
data division.
working-storage section.
77  n                         pic 9.
procedure division.
    compute n = 0**0.
    display n upon console.
    stop run.


<cfset zeroPowerTag = 0^0>
<cfoutput>"#zeroPowerTag#"</cfoutput>


/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program zumkellex641.s   */

/* REMARK 1 : this program use routines in a include file
   see task Include a file language arm assembly
   for the routine affichageMess conversion10
   see at end of this program the instruction include */

/* REMARK 2 : this program is not optimized.
   Not search First 40 odd Zumkeller numbers not divisible by 5 */

/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"

.equ NBDIVISORS,             100

/*******************************************/
/* Structures                               */
/********************************************/
/* structurea area divisors  */
    .struct  0
div_ident:                     // ident
    .struct  div_ident + 8
div_flag:                      // value 0, 1 or 2
    .struct  div_flag + 8
div_fin:
/*******************************************/
/* Initialized data                        */
/*******************************************/
.data
szMessStartPgm:          .asciz "Program start \n"
szMessEndPgm:            .asciz "Program normal end.\n"
szMessErrorArea:         .asciz "\033[31mError : area divisors too small.\n"
szMessError:             .asciz "\033[31mError  !!!\n"

szCarriageReturn:        .asciz "\n"

/* datas message display */
szMessEntete:            .asciz "The first 220 Zumkeller numbers are:\n"
sNumber:                 .space 4*20,' '
                         .space 12,' '     // for end of conversion
szMessListDivi:          .asciz "Divisors list : \n"
szMessListDiviHeap:      .asciz "Heap 1 Divisors list : \n"
szMessResult:            .ascii " "
sValue:                  .space 12,' '
                         .asciz ""

szMessEntete1:           .asciz "The first 40 odd Zumkeller numbers are:\n"
/*******************************************/
/* UnInitialized data                      */
/*******************************************/
.bss
.align 4
tbDivisors:              .skip div_fin * NBDIVISORS  // area divisors
sZoneConv:               .skip 30
/*******************************************/
/*  code section                           */
/*******************************************/
.text
.global main
main:                               // program start
    ldr x0,qAdrszMessStartPgm       // display start message
    bl affichageMess

    ldr x0,qAdrszMessEntete         // display message
    bl affichageMess
    mov x2,#1                       // counter number
    mov x3,#0                       // counter zumkeller number
    mov x4,#0                       // counter for line display
1:
    mov x0,x2                       //  number
    mov x1,#0                       // display flag
    bl testZumkeller
    cmp x0,#1                       // zumkeller ?
    bne 3f                          // no
    mov x0,x2
    ldr x1,qAdrsZoneConv            // and convert ascii string
    bl conversion10
    ldr x0,qAdrsZoneConv            // copy result in display line
    ldr x1,qAdrsNumber
    lsl x5,x4,#2
    add x1,x1,x5
11:
    ldrb w5,[x0],1
    cbz w5,12f
    strb w5,[x1],1
    b 11b
12:
    add x4,x4,#1
    cmp x4,#20
    blt 2f
    //add x1,x1,#3                  // carriage return at end of display line
    mov x0,#'\n'
    strb w0,[x1]
    mov x0,#0
    strb w0,[x1,#1]                 // end of display line
    ldr x0,qAdrsNumber              // display result message
    bl affichageMess
    mov x4,#0
2:
    add x3,x3,#1                    // increment counter
3:
    add x2,x2,#1                    // increment number
    cmp x3,#220                     // end ?
    blt 1b

    /* raz display line  */
    ldr x0,qAdrsNumber
    mov x1,' '
    mov x2,0
31:
    strb w1,[x0,x2]
    add x2,x2,1
    cmp x2,4*20
    blt 31b

    /* odd zumkeller numbers  */
    ldr x0,qAdrszMessEntete1
    bl affichageMess
    mov x2,#1
    mov x3,#0
    mov x4,#0
4:
    mov x0,x2                       //  number
    mov x1,#0                       // display flag
    bl testZumkeller
    cmp x0,#1
    bne 6f
    mov x0,x2
    ldr x1,qAdrsZoneConv            // and convert ascii string
    bl conversion10
    ldr x0,qAdrsZoneConv            // copy result in display line
    ldr x1,qAdrsNumber
    lsl x5,x4,#3
    add x1,x1,x5
41:
    ldrb w5,[x0],1
    cbz w5,42f
    strb w5,[x1],1
    b 41b
42:
    add x4,x4,#1
    cmp x4,#8
    blt 5f
    mov x0,#'\n'
    strb w0,[x1]
    strb wzr,[x1,#1]
    ldr x0,qAdrsNumber              // display result message
    bl affichageMess
    mov x4,#0
5:
    add x3,x3,#1
6:
    add x2,x2,#2
    cmp x3,#40
    blt 4b

    ldr x0,qAdrszMessEndPgm         // display end message
    bl affichageMess
    b 100f
99:                                 // display error message
    ldr x0,qAdrszMessError
    bl affichageMess
100:                                // standard end of the program
    mov x0, #0                      // return code
    mov x8, #EXIT                   // request to exit program
    svc 0                           // perform system call
qAdrszMessStartPgm:        .quad szMessStartPgm
qAdrszMessEndPgm:          .quad szMessEndPgm
qAdrszMessError:           .quad szMessError
qAdrszCarriageReturn:      .quad szCarriageReturn
qAdrszMessResult:          .quad szMessResult
qAdrsValue:                .quad sValue
qAdrszMessEntete:          .quad szMessEntete
qAdrszMessEntete1:         .quad szMessEntete1
qAdrsNumber:               .quad sNumber
qAdrsZoneConv:             .quad sZoneConv
/******************************************************************/
/*     test if number is Zumkeller number                         */
/******************************************************************/
/* x0 contains the number  */
/* x1 contains display flag (<>0: display, 0: no display ) */
/* x0 return 1 if Zumkeller number else return 0  */
testZumkeller:
    stp x1,lr,[sp,-16]!         // save  registers
    stp x2,x3,[sp,-16]!         // save  registers
    stp x4,x5,[sp,-16]!         // save  registers
    stp x6,x7,[sp,-16]!         // save  registers
    mov x7,x1                   // save flag
    ldr x1,qAdrtbDivisors
    bl divisors                 // create area of divisors
    cmp x0,#0                   // 0 divisors or error ?
    ble 98f
    mov x5,x0                   // number of dividers
    mov x6,x1                   // number of odd dividers
    cmp x7,#1                   // display divisors ?
    bne 1f
    ldr x0,qAdrszMessListDivi   // yes
    bl affichageMess
    mov x0,x5
    mov x1,#0
    ldr x2,qAdrtbDivisors
    bl printHeap
1:
    tst x6,#1                   // number of odd divisors is odd ?
    bne 99f
    mov x0,x5
    mov x1,#0
    ldr x2,qAdrtbDivisors
    bl sumDivisors              // compute divisors sum
    tst x0,#1                   // sum is odd ?
    bne 99f                     // yes -> end
    lsr x6,x0,#1                // compute sum /2
    mov x0,x6                   // x0 contains sum / 2
    mov x1,#1                   // first heap
    mov x3,x5                   // number divisors
    mov x4,#0                   // N° element to start
    bl searchHeap
    cmp x0,#-2
    beq 100f                    // end
    cmp x0,#-1
    beq 100f                    // end

    cmp x7,#1                   // print flag ?
    bne 2f
    ldr x0,qAdrszMessListDiviHeap
    bl affichageMess
    mov x0,x5                   // yes print divisors of first heap
    ldr x2,qAdrtbDivisors
    mov x1,#1
    bl printHeap
2:
    mov x0,#1                   // ok
    b 100f
98:
    mov x0,-1
    b 100f
99:
    mov x0,#0
    b 100f
100:
    ldp x6,x7,[sp],16          // restaur  2 registers
    ldp x4,x5,[sp],16          // restaur  2 registers
    ldp x2,x3,[sp],16          // restaur  2 registers
    ldp x1,lr,[sp],16          // restaur  2 registers
    ret                        // return to address lr x30
qAdrtbDivisors:          .quad tbDivisors
qAdrszMessListDiviHeap:  .quad szMessListDiviHeap
/******************************************************************/
/*     search sum divisors = sum / 2                             */
/******************************************************************/
/* x0 contains sum to search */
/* x1 contains  flag (1 or 2) */
/* x2 contains address of divisors area */
/* x3 contains elements number   */
/* x4 contains N° element to start */
/* x0 return -2  end search */
/* x0 return -1  no heap   */
/* x0 return 0   Ok */
/* recursive routine */
searchHeap:
    stp x3,lr,[sp,-16]!            // save  registers
    stp x4,x5,[sp,-16]!            // save  registers
    stp x6,x8,[sp,-16]!            // save  registers
1:
    cmp x4,x3                   // indice = elements number
    beq 99f
    lsl x6,x4,#4                // compute element address
    add x6,x6,x2
    ldr x7,[x6,#div_flag]       // flag equal ?
    cmp x7,#0
    bne 6f
    ldr x5,[x6,#div_ident]
    cmp x5,x0                   // element value = remaining amount
    beq 7f                      // yes
    bgt 6f                      // too large
                                // too less
    mov x8,x0                   // save sum
    sub x0,x0,x5                // new sum to find
    add x4,x4,#1                // next divisors
    bl searchHeap               // other search
    cmp x0,#0                   // find -> ok
    beq 5f
    mov x0,x8                   // sum begin
    sub x4,x4,#1                // prev divisors
    bl razFlags                 // zero in all flags > current element
4:
    add x4,x4,#1                // last divisors
    b 1b
5:
    str x1,[x6,#div_flag]       // flag -> area element flag
    b 100f
6:
    add x4,x4,#1                // last divisors
    b 1b
7:
    str x1,[x6,#div_flag]       // flag -> area element flag
    mov x0,#0                   // search ok
    b 100f
8:
    mov x0,#-1                  // end search
    b 100f
99:
    mov x0,#-2
    b 100f
100:
    ldp x6,x8,[sp],16          // restaur  2 registers
    ldp x4,x5,[sp],16          // restaur  2 registers
    ldp x3,lr,[sp],16          // restaur  2 registers
    ret                        // return to address lr x30
/******************************************************************/
/*     raz flags                                                  */
/******************************************************************/
/* x0 contains sum to search */
/* x1 contains  flag (1 or 2) */
/* x2 contains address of divisors area */
/* x3 contains elements number   */
/* x4 contains N° element to start */
/* x5 contains current sum */
/* REMARK  : NO SAVE REGISTERS x14 x15 x16 AND LR */
razFlags:
    mov x14,x4
1:
    cmp x14,x3                   // indice > nb elements ?
    bge 100f                     // yes -> end
    lsl x15,x14,#4
    add x15,x15,x2               // compute address element
    ldr x16,[x15,#div_flag]      // load flag
    cmp x1,x16                   // equal ?
    bne 2f
    str xzr,[x15,#div_flag]      // yes -> store 0
2:
    add x14,x14,#1               // increment indice
    b 1b                         // and loop
100:
    ret                          // return to address lr x30
/******************************************************************/
/*     compute sum of divisors                         */
/******************************************************************/
/* x0 contains elements number */
/* x1 contains  flag (0  1 or 2)
/* x2 contains address of divisors area
/* x0 return divisors sum */
/* REMARK  : NO SAVE REGISTERS x13 x14 x15 x16 AND LR */
sumDivisors:
    mov x13,#0                   // indice
    mov x16,#0                   // sum
1:
    lsl x14,x13,#4               // N° element * 16
    add x14,x14,x2
    ldr x15,[x14,#div_flag]      // compare flag
    cmp x15,x1
    bne 2f
    ldr x15,[x14,#div_ident]     // load value
    add x16,x16,x15              // and add
2:
    add x13,x13,#1
    cmp x13,x0
    blt 1b
    mov x0,x16                   // return sum
100:
    ret                          // return to address lr x30
/******************************************************************/
/*     print heap                         */
/******************************************************************/
/* x0 contains elements number */
/* x1 contains  flag (0  1 or 2) */
/* x2 contains address of divisors area */
printHeap:
    stp x2,lr,[sp,-16]!         // save  registers
    stp x3,x4,[sp,-16]!         // save  registers
    stp x5,x6,[sp,-16]!         // save  registers
    stp x1,x7,[sp,-16]!         // save  registers
    mov x6,x0
    mov x5,x1
    mov x3,#0                   // indice
1:
    lsl x1,x3,#4                // N° element * 16
    add x1,x1,x2
    ldr x4,[x1,#div_flag]
    cmp x4,x5
    bne 2f
    ldr x0,[x1,#div_ident]
    ldr x1,qAdrsValue           // and convert ascii string
    bl conversion10
    ldr x0,qAdrszMessResult     // display result message
    bl affichageMess
2:
    add x3,x3,#1
    cmp x3,x6
    blt 1b
    ldr x0,qAdrszCarriageReturn
    bl affichageMess
100:
    ldp x1,x8,[sp],16          // restaur  2 registers
    ldp x5,x6,[sp],16          // restaur  2 registers
    ldp x3,x4,[sp],16          // restaur  2 registers
    ldp x2,lr,[sp],16          // restaur  2 registers
    ret                        // return to address lr x30
/******************************************************************/
/*     divisors function                         */
/******************************************************************/
/* x0 contains the number  */
/* x1 contains address of divisors area
/* x0 return divisors number */
/* x1 return counter odd divisors */
/* REMARK  : NO SAVE REGISTERS x10 x11 x12 x13 x14 x15 x16 x17 x18 */
divisors:
    str lr,[sp,-16]!            // save  register LR
    cmp x0,#1                   // = 1 ?
    ble 98f
    mov x17,x0
    mov x18,x1
    mov x11,#1                  // counter odd divisors
    mov x0,#1                   // first divisor = 1
    str x0,[x18,#div_ident]
    mov x0,#0
    str x0,[x18,#div_flag]
    tst x17,#1                  // number is odd ?
    cinc  x11,x11,ne            // count odd divisors
    mov x0,x17                  // last divisor = N
    add x10,x18,#16             // store at next element
    str x0,[x10,#div_ident]
    mov x0,#0
    str x0,[x10,#div_flag]

    mov x16,#2                  // first divisor
    mov x15,#2                  // Counter divisors
2:                              // begin loop
    udiv x12,x17,x16
    msub x13,x12,x16,x17
    cmp x13,#0                  // remainder = 0 ?
    bne 3f
    cmp x12,x16
    blt 4f                      // quot<divisor  end
    lsl x10,x15,#4              // N° element * 16
    add x10,x10,x18             // and add at area begin address
    str x12,[x10,#div_ident]
    str xzr,[x10,#div_flag]
    add x15,x15,#1              // increment counter
    cmp x15,#NBDIVISORS         // area maxi ?
    bge 99f
    tst x12,#1
    cinc  x11,x11,ne            // count odd divisors
    cmp x12,x16                 // quotient = divisor ?
    ble 4f
    lsl x10,x15,#4              // N° element * 16
    add x10,x10,x18             // and add at area begin address
    str x16,[x10,#div_ident]
    str xzr,[x10,#div_flag]
    add x15,x15,#1              // increment counter
    cmp x15,#NBDIVISORS         // area maxi ?
    bge 99f
    tst x16,#1
    cinc  x11,x11,ne            // count odd divisors
3:
    cmp x12,x16
    ble 4f
    add x16,x16,#1              // increment divisor
    b 2b                        // and loop

4:
    mov x0,x15                  // return divisors number
    mov x1,x11                  // return count odd divisors
    b 100f
98:
    mov x0,0
    b 100f
99:                             // error
    ldr x0,qAdrszMessErrorArea
    bl affichageMess
    mov x0,-1
100:
    ldr lr,[sp],16              // restaur  1 registers
    ret                         // return to address lr x30
qAdrszMessListDivi:           .quad szMessListDivi
qAdrszMessErrorArea:          .quad szMessErrorArea
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"


-- Sum n's proper divisors.
on aliquotSum(n)
    if (n < 2) then return 0
    set sum to 1
    set sqrt to n ^ 0.5
    set limit to sqrt div 1
    if (limit = sqrt) then
        set sum to sum + limit
        set limit to limit - 1
    end if
    repeat with i from 2 to limit
        if (n mod i is 0) then set sum to sum + i + n div i
    end repeat

    return sum
end aliquotSum

-- Return n's proper divisors.
on properDivisors(n)
    set output to {}

    if (n > 1) then
        set sqrt to n ^ 0.5
        set limit to sqrt div 1
        if (limit = sqrt) then
            set end of output to limit
            set limit to limit - 1
        end if
        repeat with i from limit to 2 by -1
            if (n mod i is 0) then
                set beginning of output to i
                set end of output to n div i
            end if
        end repeat
        set beginning of output to 1
    end if

    return output
end properDivisors

-- Does a subset of the given list of numbers add up to the target value?
on subsetOf:numberList sumsTo:target
    script o
        property lst : numberList
        property someNegatives : false

        on ssp(target, i)
            repeat while (i > 1)
                set n to item i of my lst
                set i to i - 1
                if ((n = target) or (((n < target) or (someNegatives)) and (ssp(target - n, i)))) then return true
            end repeat
            return (target = beginning of my lst)
        end ssp
    end script
    -- The search can be more efficient if it's known the list contains no negatives.
    repeat with n in o's lst
        if (n < 0) then
            set o's someNegatives to true
            exit repeat
        end if
    end repeat

    return o's ssp(target, count o's lst)
end subsetOf:sumsTo:

-- Is n a Zumkeller number?
on isZumkeller(n)
    -- Yes if its aliquot sum is greater than or equal to it, the difference between them is even, and
    -- either n is odd or a subset of its proper divisors sums to half the sum of the divisors and it.
    -- Using aliquotSum() to get the divisor sum and then calling properDivisors() too if a list's actually
    -- needed is generally faster than using properDivisors() in the first place and summing the result.
    set sum to aliquotSum(n)
    return ((sum ≥ n) and ((sum - n) mod 2 = 0) and ¬
        ((n mod 2 = 1) or (my subsetOf:(properDivisors(n)) sumsTo:((sum + n) div 2))))
end isZumkeller

-- Task code:
-- Find and return q Zumkeller numbers, starting the search at n and continuing at the
-- given interval, applying the Zumkeller test only to numbers passing the given filter.
on zumkellerNumbers(q, n, interval, filter)
    script o
        property zumkellers : {}
    end script

    set counter to 0
    repeat until (counter = q)
        if ((filter's OK(n)) and (isZumkeller(n))) then
            set end of o's zumkellers to n
            set counter to counter + 1
        end if
        set n to n + interval
    end repeat

    return o's zumkellers
end zumkellerNumbers

on joinText(textList, delimiter)
    set astid to AppleScript's text item delimiters
    set AppleScript's text item delimiters to delimiter
    set txt to textList as text
    set AppleScript's text item delimiters to astid

    return txt
end joinText

on formatForDisplay(resultList, heading, resultsPerLine, separator)
    script o
        property input : resultList
        property output : {heading}
    end script

    set len to (count o's input)
    repeat with i from 1 to len by resultsPerLine
        set j to i + resultsPerLine - 1
        if (j > len) then set j to len
        set end of o's output to joinText(items i thru j of o's input, separator)
    end repeat

    return joinText(o's output, linefeed)
end formatForDisplay

on doTask(cheating)
    set output to {}
    script noFilter
        on OK(n)
            return true
        end OK
    end script
    set header to "1st 220 Zumkeller numbers:"
    set end of output to formatForDisplay(zumkellerNumbers(220, 1, 1, noFilter), header, 20, "  ")
    set header to "1st 40 odd Zumkeller numbers:"
    set end of output to formatForDisplay(zumkellerNumbers(40, 1, 2, noFilter), header, 10, "  ")

    -- Stretch goal:
    set header to "1st 40 odd Zumkeller numbers not ending with 5:"
    script no5Multiples
        on OK(n)
            return (n mod 5 > 0)
        end OK
    end script
    if (cheating) then
        -- Knowing that the HCF of the first 203 odd Zumkellers not ending with 5
        -- is 63, just check 63 and each 126th number thereafter.
        -- For the 204th - 907th such numbers, the HCF reduces to 21, so adjust accordingly.
        -- (See Horsth's comments on the Talk page.)
        set zumkellers to zumkellerNumbers(40, 63, 126, no5Multiples)
    else
        -- Otherwise check alternate numbers from 1.
        set zumkellers to zumkellerNumbers(40, 1, 2, no5Multiples)
    end if
    set end of output to formatForDisplay(zumkellers, header, 10, "  ")

    return joinText(output, linefeed & linefeed)
end doTask

local cheating
set cheating to false
doTask(cheating)


hash =
  a: 'one'
  b: 'two'

for key, value of hash
  console.log key, value

for key of hash
  console.log key


;; iterate using dolist, destructure manually
(dolist (pair alist)
  (destructuring-bind (key . value) pair
    (format t "~&Key: ~a, Value: ~a." key value)))

;; iterate and destructure with loop
(loop for (key . value) in alist
      do (format t "~&Key: ~a, Value: ~a." key value))


include "cowgol.coh";

var doors: uint8[101];  # one extra so we can start at 1
var pass: @indexof doors;
var door: @indexof doors;

MemZero(&doors as [uint8], @bytesof doors);

pass := 1;
while pass <= 100 loop
    door := pass;
    while door <= 100 loop
        doors[door] := 1-doors[door];
        door := door + pass;
    end loop;
    pass := pass + 1;
end loop;

door := 1;
while door <= 100 loop
    if doors[door] == 1 then
        print_i8(door);
        print(" is open\n");
    end if;
    door := door + 1;
end loop;


void main() {
    import std.stdio, std.math, std.bigint, std.complex;

    writeln("Int:     ", 0 ^^ 0);
    writeln("Ulong:   ", 0UL ^^ 0UL);
    writeln("Float:   ", 0.0f ^^ 0.0f);
    writeln("Double:  ", 0.0 ^^ 0.0);
    writeln("Real:    ", 0.0L ^^ 0.0L);
    writeln("pow:     ", pow(0, 0));
    writeln("BigInt:  ", 0.BigInt ^^ 0);
    writeln("Complex: ", complex(0.0, 0.0) ^^ 0);
}


/* ARM assembly Raspberry PI  */
/* program zumkeller4.s   */
/* new version 10/2020 */

 /* REMARK 1 : this program use routines in a include file
   see task Include a file language arm assembly
   for the routine affichageMess conversion10
   see at end of this program the instruction include */
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes                       */
/************************************/
.include "../constantes.inc"

.equ NBDIVISORS,             1000

/*******************************************/
/* Initialized data                        */
/*******************************************/
.data
szMessStartPgm:          .asciz "Program start \n"
szMessEndPgm:            .asciz "Program normal end.\n"
szMessErrorArea:         .asciz "\033[31mError : area divisors too small.\n"
szMessError:             .asciz "\033[31mError  !!!\n"
szMessErrGen:            .asciz "Error end program.\n"
szMessNbPrem:            .asciz "This number is prime !!!.\n"
szMessResultFact:        .asciz "@ "

szCarriageReturn:        .asciz "\n"

/* datas message display */
szMessEntete:            .asciz "The first 220 Zumkeller numbers are:\n"
sNumber:                 .space 4*20,' '
                         .space 12,' '     @ for end of conversion
szMessListDivi:          .asciz "Divisors list : \n"
szMessListDiviHeap:      .asciz "Heap 1 Divisors list : \n"
szMessResult:            .ascii " "
sValue:                  .space 12,' '
                         .asciz ""

szMessEntete1:            .asciz "The first 40 odd Zumkeller numbers are:\n"
szMessEntete2:            .asciz "First 40 odd Zumkeller numbers not divisible by 5:\n"
/*******************************************/
/* UnInitialized data                      */
/*******************************************/
.bss
.align 4
sZoneConv:               .skip 24
tbZoneDecom:             .skip 8 * NBDIVISORS          // facteur 4 octets, nombre 4
/*******************************************/
/*  code section                           */
/*******************************************/
.text
.global main
main:                               @ program start
    ldr r0,iAdrszMessStartPgm       @ display start message
    bl affichageMess

    ldr r0,iAdrszMessEntete         @ display result message
    bl affichageMess
    mov r2,#1
    mov r3,#0
    mov r4,#0
1:
    mov r0,r2                       @  number
    bl testZumkeller
    cmp r0,#1
    bne 3f
    mov r0,r2
    ldr r1,iAdrsNumber              @ and convert ascii string
    lsl r5,r4,#2
    add r1,r5
    bl conversion10
    add r4,r4,#1
    cmp r4,#20
    blt 2f
    add r1,r1,#3
    mov r0,#'\n'
    strb r0,[r1]
    mov r0,#0
    strb r0,[r1,#1]
    ldr r0,iAdrsNumber         @ display result message
    bl affichageMess
    mov r4,#0
2:
    add r3,r3,#1
3:
    add r2,r2,#1
    cmp r3,#220
    blt 1b

    /* odd zumkeller numbers  */
    ldr r0,iAdrszMessEntete1
    bl affichageMess
    mov r2,#1
    mov r3,#0
    mov r4,#0
4:
    mov r0,r2                       @  number
    bl testZumkeller
    cmp r0,#1
    bne 6f
    mov r0,r2
    ldr r1,iAdrsNumber              @ and convert ascii string
    lsl r5,r4,#3
    add r1,r5
    bl conversion10
    add r4,r4,#1
    cmp r4,#8
    blt 5f
    add r1,r1,#8
    mov r0,#'\n'
    strb r0,[r1]
    mov r0,#0
    strb r0,[r1,#1]
    ldr r0,iAdrsNumber              @ display result message
    bl affichageMess
    mov r4,#0
5:
    add r3,r3,#1
6:
    add r2,r2,#2
    cmp r3,#40
    blt 4b
    /* odd zumkeller numbers not multiple5 */
61:
    ldr r0,iAdrszMessEntete2
    bl affichageMess
    mov r3,#0
    mov r4,#0
7:
    lsr r8,r2,#3                   @ divide counter by 5
    add r8,r8,r2,lsr #4
    add r8,r8,r8,lsr #4
    add r8,r8,r8,lsr #8
    add r8,r8,r8,lsr #16
    add r9,r8,r8,lsl #2            @ multiply result by 5
    sub r9,r2,r9
    mov r6,#13
    mul r9,r6,r9
    lsr r9,#6
    add r9,r8                      @ it is a quotient
    add r9,r9,r9,lsl #2            @ multiply by 5
    sub r9,r2,r9                   @ compute remainder
    cmp r9,#0                      @ remainder = zero ?
    beq 9f
    mov r0,r2                      @  number
    bl testZumkeller
    cmp r0,#1
    bne 9f
    mov r0,r2
    ldr r1,iAdrsNumber              @ and convert ascii string
    lsl r5,r4,#3
    add r1,r5
    bl conversion10
    add r4,r4,#1
    cmp r4,#8
    blt 8f
    add r1,r1,#8
    mov r0,#'\n'
    strb r0,[r1]
    mov r0,#0
    strb r0,[r1,#1]
    ldr r0,iAdrsNumber         @ display result message
    bl affichageMess
    mov r4,#0
8:
    add r3,r3,#1
9:
    add r2,r2,#2
    cmp r3,#40
    blt 7b

    ldr r0,iAdrszMessEndPgm         @ display end message
    bl affichageMess
    b 100f
99:                                 @ display error message
    ldr r0,iAdrszMessError
    bl affichageMess
100:                                @ standard end of the program
    mov r0, #0                      @ return code
    mov r7, #EXIT                   @ request to exit program
    svc 0                           @ perform system call
iAdrszMessStartPgm:        .int szMessStartPgm
iAdrszMessEndPgm:          .int szMessEndPgm
iAdrszMessError:           .int szMessError
iAdrszCarriageReturn:      .int szCarriageReturn
iAdrszMessResult:          .int szMessResult
iAdrsValue:                .int sValue
iAdrtbZoneDecom:           .int tbZoneDecom
iAdrszMessEntete:          .int szMessEntete
iAdrszMessEntete1:         .int szMessEntete1
iAdrszMessEntete2:         .int szMessEntete2
iAdrsNumber:               .int sNumber

/******************************************************************/
/*     test if number is Zumkeller number                         */
/******************************************************************/
/* r0 contains the number  */
/* r0 return 1 if Zumkeller number else return 0  */
testZumkeller:
    push {r1-r6,lr}              @ save  registers
    mov r6,r0                    @ save number
    ldr r1,iAdrtbZoneDecom
    bl decompFact                @ create area of divisors
    cmp r0,#1                    @ no divisors
    movle r0,#0
    ble 100f
    tst r2,#1                    @ odd sum ?
    movne r0,#0
    bne 100f                     @ yes -> end
    tst r1,#1                    @ number of odd divisors is odd ?
    movne r0,#0
    bne 100f                     @ yes -> end
    lsl r5,r6,#1                 @ abondant number
    cmp r5,r2
    movgt r0,#0
    bgt 100f                     @ no -> end
    mov r3,r0
    mov r4,r2                    @ save sum
    ldr r0,iAdrtbZoneDecom
    mov r1,#0
    mov r2,r3
    bl shellSort                 @ sort table

    mov r1,r3                    @ factors number
    ldr r0,iAdrtbZoneDecom
    lsr r2,r4,#1                 @ sum / 2
    bl computePartIter           @

100:
    pop {r1-r6,lr}              @ restaur registers
    bx lr                       @ return

/******************************************************************/
/*     search factors to sum = entry value                         */
/******************************************************************/
/* r0 contains address of divisors area */
/* r1 contains elements number */
/* r2 contains divisors sum / 2  */
/* r0 return 1 if ok 0 else */
computePartIter:
    push {r1-r7,fp,lr}         @ save  registers
    lsl r7,r1,#3               @ compute size of temp table
    sub sp,r7                  @ and reserve on stack
    mov fp,sp                  @ frame pointer = stack address = begin table
    mov r5,#0                  @ stack indice
    sub r3,r1,#1
1:
    ldr r4,[r0,r3,lsl #2]      @ load factor
    cmp r4,r2                  @ compare value
    bgt 2f
    beq 90f                    @ equal -> end ok
    cmp r3,#0                  @ first item ?
    beq 3f
    sub r3,#1                  @ push indice item in temp table
    add r6,fp,r5,lsl #3
    str r3,[r6]
    str r2,[r6,#4]             @ push sum in temp table
    add r5,#1
    sub r2,r4                  @ substract divisors from sum
    b 1b
2:
    sub r3,#1                 @ other divisors
    cmp r3,#0                 @ first item ?
    bge 1b
3:                            @ first item
    cmp r5,#0                 @ stack empty ?
    moveq r0,#0               @ no sum factors equal to value
    beq 100f                  @ end
    sub r5,#1                 @ else pop stack
    add r6,fp,r5,lsl #3       @ and restaur
    ldr r3,[r6]               @ indice
    ldr r2,[r6,#4]            @ and value
    b 1b                      @ and loop

90:
    mov r0,#1                 @ it is ok
100:
    add sp,r7                 @ stack alignement
    pop {r1-r7,fp,lr}         @ restaur registers
    bx lr                     @ return

/******************************************************************/
/*     factor decomposition                                               */
/******************************************************************/
/* r0 contains number */
/* r1 contains address of divisors area */
/* r0 return divisors items in table */
/* r1 return the number of odd divisors  */
/* r2 return the sum of divisors  */
decompFact:
    push {r3-r8,lr}              @ save  registers
    mov r5,r1
    mov r8,r0                    @ save number
    bl isPrime                   @ prime ?
    cmp r0,#1
    beq 98f                      @ yes is prime
    mov r1,#1
    str r1,[r5]                  @ first factor
    mov r12,#1                   @ divisors sum
    mov r11,#1                   @ number odd divisors
    mov r4,#1                    @ indice divisors table
    mov r1,#2                    @ first divisor
    mov r6,#0                    @ previous divisor
    mov r7,#0                    @ number of same divisors
2:
    mov r0,r8                    @ dividende
    bl division                  @  r1 divisor r2 quotient r3 remainder
    cmp r3,#0
    bne 5f                       @ if remainder <> zero  -> no divisor
    mov r8,r2                    @ else quotient -> new dividende
    cmp r1,r6                    @ same divisor ?
    beq 4f                       @ yes
    mov r7,r4                    @ number factors in table
    mov r9,#0                    @ indice
21:
    ldr r10,[r5,r9,lsl #2 ]      @ load one factor
    mul r10,r1,r10               @ multiply
    str r10,[r5,r7,lsl #2]       @ and store in the table
    tst r10,#1                   @ divisor odd ?
    addne r11,#1
    add r12,r10
    add r7,r7,#1                 @ and increment counter
    add r9,r9,#1
    cmp r9,r4
    blt 21b
    mov r4,r7
    mov r6,r1                    @ new divisor
    b 7f
4:                               @ same divisor
    sub r9,r4,#1
    mov r7,r4
41:
    ldr r10,[r5,r9,lsl #2 ]
    cmp r10,r1
    subne r9,#1
    bne 41b
    sub r9,r4,r9
42:
    ldr  r10,[r5,r9,lsl #2 ]
    mul r10,r1,r10
    str r10,[r5,r7,lsl #2]       @ and store in the table
    tst r10,#1                   @ divsor odd ?
    addne r11,#1
    add r12,r10
    add r7,r7,#1                 @ and increment counter
    add r9,r9,#1
    cmp r9,r4
    blt 42b
    mov r4,r7
    b 7f                         @ and loop

    /* not divisor -> increment next divisor */
5:
    cmp r1,#2                    @ if divisor = 2 -> add 1
    addeq r1,#1
    addne r1,#2                  @ else add 2
    b 2b

    /* divisor -> test if new dividende is prime */
7:
    mov r3,r1                    @ save divisor
    cmp r8,#1                    @ dividende = 1 ? -> end
    beq 10f
    mov r0,r8                    @ new dividende is prime ?
    mov r1,#0
    bl isPrime                   @ the new dividende is prime ?
    cmp r0,#1
    bne 10f                      @ the new dividende is not prime

    cmp r8,r6                    @ else dividende is same divisor ?
    beq 9f                       @ yes
    mov r7,r4                    @ number factors in table
    mov r9,#0                    @ indice
71:
    ldr r10,[r5,r9,lsl #2 ]      @ load one factor
    mul r10,r8,r10               @ multiply
    str r10,[r5,r7,lsl #2]       @ and store in the table
    tst r10,#1                   @ divsor odd ?
    addne r11,#1
    add r12,r10
    add r7,r7,#1                 @ and increment counter
    add r9,r9,#1
    cmp r9,r4
    blt 71b
    mov r4,r7
    mov r7,#0
    b 11f
9:
    sub r9,r4,#1
    mov r7,r4
91:
    ldr r10,[r5,r9,lsl #2 ]
    cmp r10,r8
    subne r9,#1
    bne 91b
    sub r9,r4,r9
92:
    ldr  r10,[r5,r9,lsl #2 ]
    mul r10,r8,r10
    str r10,[r5,r7,lsl #2]       @ and store in the table
    tst r10,#1                   @ divisor odd ?
    addne r11,#1
    add r12,r10
    add r7,r7,#1                 @ and increment counter
    add r9,r9,#1
    cmp r9,r4
    blt 92b
    mov r4,r7
    b 11f

10:
    mov r1,r3                    @ current divisor = new divisor
    cmp r1,r8                    @ current divisor  > new dividende ?
    ble 2b                       @ no -> loop

    /* end decomposition */
11:
    mov r0,r4                    @ return number of table items
    mov r2,r12                   @ return sum
    mov r1,r11                   @ return number of odd divisor
    mov r3,#0
    str r3,[r5,r4,lsl #2]        @ store zéro in last table item
    b 100f

98:
    //ldr r0,iAdrszMessNbPrem
    //bl   affichageMess
    mov r0,#1                   @ return code
    b 100f
99:
    ldr r0,iAdrszMessError
    bl   affichageMess
    mov r0,#-1                  @ error code
    b 100f
100:
    pop {r3-r8,lr}              @ restaur registers
    bx lr
iAdrszMessNbPrem:           .int szMessNbPrem
/***************************************************/
/*   check if a number is prime              */
/***************************************************/
/* r0 contains the number            */
/* r0 return 1 if prime  0 else */
@2147483647
@4294967297
@131071
isPrime:
    push {r1-r6,lr}    @ save registers
    cmp r0,#0
    beq 90f
    cmp r0,#17
    bhi 1f
    cmp r0,#3
    bls 80f            @ for 1,2,3 return prime
    cmp r0,#5
    beq 80f            @ for 5 return prime
    cmp r0,#7
    beq 80f            @ for 7 return prime
    cmp r0,#11
    beq 80f            @ for 11 return prime
    cmp r0,#13
    beq 80f            @ for 13 return prime
    cmp r0,#17
    beq 80f            @ for 17 return prime
1:
    tst r0,#1          @ even ?
    beq 90f            @ yes -> not prime
    mov r2,r0          @ save number
    sub r1,r0,#1       @ exposant n - 1
    mov r0,#3          @ base
    bl moduloPuR32     @ compute base power n - 1 modulo n
    cmp r0,#1
    bne 90f            @ if <> 1  -> not prime

    mov r0,#5
    bl moduloPuR32
    cmp r0,#1
    bne 90f

    mov r0,#7
    bl moduloPuR32
    cmp r0,#1
    bne 90f

    mov r0,#11
    bl moduloPuR32
    cmp r0,#1
    bne 90f

    mov r0,#13
    bl moduloPuR32
    cmp r0,#1
    bne 90f

    mov r0,#17
    bl moduloPuR32
    cmp r0,#1
    bne 90f
80:
    mov r0,#1        @ is prime
    b 100f
90:
    mov r0,#0        @ no prime
100:                 @ fin standard de la fonction
    pop {r1-r6,lr}   @ restaur des registres
    bx lr            @ retour de la fonction en utilisant lr
/********************************************************/
/*   Calcul modulo de b puissance e modulo m  */
/*    Exemple 4 puissance 13 modulo 497 = 445         */
/*                                             */
/********************************************************/
/* r0  nombre  */
/* r1 exposant */
/* r2 modulo   */
/* r0 return result  */
moduloPuR32:
    push {r1-r7,lr}    @ save registers
    cmp r0,#0          @ verif <> zero
    beq 100f
    cmp r2,#0          @ verif <> zero
    beq 100f           @ TODO: vérifier les cas d erreur
1:
    mov r4,r2          @ save modulo
    mov r5,r1          @ save exposant
    mov r6,r0          @ save base
    mov r3,#1          @ start result

    mov r1,#0          @ division de r0,r1 par r2
    bl division32R
    mov r6,r2          @ base <- remainder
2:
    tst r5,#1          @  exposant even or odd
    beq 3f
    umull r0,r1,r6,r3
    mov r2,r4
    bl division32R
    mov r3,r2          @ result <- remainder
3:
    umull r0,r1,r6,r6
    mov r2,r4
    bl division32R
    mov r6,r2          @ base <- remainder

    lsr r5,#1          @ left shift 1 bit
    cmp r5,#0          @ end ?
    bne 2b
    mov r0,r3
100:                   @ fin standard de la fonction
    pop {r1-r7,lr}     @ restaur des registres
    bx lr              @ retour de la fonction en utilisant lr

/***************************************************/
/*   division number 64 bits in 2 registers by number 32 bits */
/***************************************************/
/* r0 contains lower part dividende   */
/* r1 contains upper part dividende   */
/* r2 contains divisor   */
/* r0 return lower part quotient    */
/* r1 return upper part quotient    */
/* r2 return remainder               */
division32R:
    push {r3-r9,lr}    @ save registers
    mov r6,#0          @ init upper upper part remainder  !!
    mov r7,r1          @ init upper part remainder with upper part dividende
    mov r8,r0          @ init lower part remainder with lower part dividende
    mov r9,#0          @ upper part quotient
    mov r4,#0          @ lower part quotient
    mov r5,#32         @ bits number
1:                     @ begin loop
    lsl r6,#1          @ shift upper upper part remainder
    lsls r7,#1         @ shift upper  part remainder
    orrcs r6,#1
    lsls r8,#1         @ shift lower  part remainder
    orrcs r7,#1
    lsls r4,#1         @ shift lower part quotient
    lsl r9,#1          @ shift upper part quotient
    orrcs r9,#1
                       @ divisor sustract  upper  part remainder
    subs r7,r2
    sbcs  r6,#0        @ and substract carry
    bmi 2f             @ négative ?

                       @ positive or equal
    orr r4,#1          @ 1 -> right bit quotient
    b 3f
2:                     @ negative
    orr r4,#0          @ 0 -> right bit quotient
    adds r7,r2         @ and restaur remainder
    adc  r6,#0
3:
    subs r5,#1         @ decrement bit size
    bgt 1b             @ end ?
    mov r0,r4          @ lower part quotient
    mov r1,r9          @ upper part quotient
    mov r2,r7          @ remainder
100:                   @ function end
    pop {r3-r9,lr}     @ restaur registers
    bx lr
/***************************************************/
/*   shell Sort                                    */
/***************************************************/

/* r0 contains the address of table */
/* r1 contains the first element but not use !!   */
/*   this routine use first element at index zero !!!  */
/* r2 contains the number of element */
shellSort:
    push {r0-r7,lr}              @save registers
    sub r2,#1                    @ index last item
    mov r1,r2                    @ init gap = last item
1:                               @ start loop 1
    lsrs r1,#1                   @ gap = gap / 2
    beq 100f                     @ if gap = 0 -> end
    mov r3,r1                    @ init loop indice 1
2:                               @ start loop 2
    ldr r4,[r0,r3,lsl #2]        @ load first value
    mov r5,r3                    @ init loop indice 2
3:                               @ start loop 3
    cmp r5,r1                    @ indice < gap
    blt 4f                       @ yes -> end loop 2
    sub r6,r5,r1                 @ index = indice - gap
    ldr r7,[r0,r6,lsl #2]        @ load second value
    cmp r4,r7                    @ compare values
    strlt r7,[r0,r5,lsl #2]      @ store if <
    sublt r5,r1                  @ indice = indice - gap
    blt 3b                       @ and loop
4:                               @ end loop 3
    str r4,[r0,r5,lsl #2]        @ store value 1 at indice 2
    add r3,#1                    @ increment indice 1
    cmp r3,r2                    @ end ?
    ble 2b                       @ no -> loop 2
    b 1b                         @ yes loop for new gap

100:                             @ end function
    pop {r0-r7,lr}               @ restaur registers
    bx lr                        @ return
/******************************************************************/
/*     display divisors function                         */
/******************************************************************/
/* r0 contains address of divisors area */
/* r1 contains the number of area items  */
displayDivisors:
    push {r2-r8,lr}            @ save  registers
    cmp r1,#0
    beq 100f
    mov r2,r1
    mov r3,#0                   @ indice
    mov r4,r0
1:
    add r5,r4,r3,lsl #2
    ldr r0,[r5]                 @ load factor

    ldr r1,iAdrsZoneConv
    bl conversion10             @ call décimal conversion
    ldr r0,iAdrszMessResultFact
    ldr r1,iAdrsZoneConv        @ insert conversion in message
    bl strInsertAtCharInc
    bl affichageMess            @ display message
    add r3,#1                   @ other ithem
    cmp r3,r2                   @ items maxi ?
    blt 1b
    ldr r0,iAdrszCarriageReturn
    bl affichageMess
    b 100f

100:
    pop {r2-r8,lr}             @ restaur registers
    bx lr                       @ return
iAdrszMessResultFact:    .int szMessResultFact
iAdrsZoneConv:           .int sZoneConv
/***************************************************/
/*      ROUTINES INCLUDE                 */
/***************************************************/
.include "../affichage.inc"


dict = {'A' => 1, 'B' => 2}

dict.each { |pair|
  puts pair
}

dict.each_key { |key|
  puts key
}

dict.each_value { |value|
  puts value
}


import std.stdio: writeln;

void main() {
    // the associative array
    auto aa = ["alice":2, "bob":97, "charlie":45];

    // how to iterate key/value pairs:
    foreach (key, value; aa)
        writeln("1) Got key ", key, " with value ", value);
    writeln();

    // how to iterate the keys:
    foreach (key, _; aa)
        writeln("2) Got key ", key);
    writeln();

    // how to iterate the values:
    foreach (value; aa)
        writeln("3) Got value ", value);
    writeln();

    // how to extract the values, lazy:
    foreach (value; aa.byValue())
        writeln("4) Got value ", value);
    writeln();

    // how to extract the keys, lazy:
    foreach (key; aa.byKey())
        writeln("5) Got key ", key);
    writeln();

    // how to extract all the keys:
    foreach (key; aa.keys)
        writeln("6) Got key ", key);
    writeln();

    // how to extract all the values:
    foreach (value; aa.values)
        writeln("7) Got value ", value);
}


doors = Array.new(100, false)

1.upto(100) do |i|
  i.step(by: i, to: 100) do |j|
    doors[j - 1] = !doors[j - 1]
  end
end

doors.each_with_index do |open, i|
  puts "Door #{i + 1} is #{open ? "open" : "closed"}"
end


;; trying the 16 combinations
;; all return the integer 1

(lib 'bigint)
(define zeroes '(integer: 0 inexact=float: 0.000 complex: 0+0i bignum: #0))
(for* ((z1 zeroes) (z2 zeroes)) (write (expt z1 z2)))
    →  1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1


using System;
using System.Collections.Generic;
using System.Linq;

namespace ZumkellerNumbers {
    class Program {
        static List<int> GetDivisors(int n) {
            List<int> divs = new List<int> {
                1, n
            };
            for (int i = 2; i * i <= n; i++) {
                if (n % i == 0) {
                    int j = n / i;
                    divs.Add(i);
                    if (i != j) {
                        divs.Add(j);
                    }
                }
            }
            return divs;
        }

        static bool IsPartSum(List<int> divs, int sum) {
            if (sum == 0) {
                return true;
            }
            var le = divs.Count;
            if (le == 0) {
                return false;
            }
            var last = divs[le - 1];
            List<int> newDivs = new List<int>();
            for (int i = 0; i < le - 1; i++) {
                newDivs.Add(divs[i]);
            }
            if (last > sum) {
                return IsPartSum(newDivs, sum);
            }
            return IsPartSum(newDivs, sum) || IsPartSum(newDivs, sum - last);
        }

        static bool IsZumkeller(int n) {
            var divs = GetDivisors(n);
            var sum = divs.Sum();
            // if sum is odd can't be split into two partitions with equal sums
            if (sum % 2 == 1) {
                return false;
            }
            // if n is odd use 'abundant odd number' optimization
            if (n % 2 == 1) {
                var abundance = sum - 2 * n;
                return abundance > 0 && abundance % 2 == 0;
            }
            // if n and sum are both even check if there's a partition which totals sum / 2
            return IsPartSum(divs, sum / 2);
        }

        static void Main() {
            Console.WriteLine("The first 220 Zumkeller numbers are:");
            int i = 2;
            for (int count = 0; count < 220; i++) {
                if (IsZumkeller(i)) {
                    Console.Write("{0,3} ", i);
                    count++;
                    if (count % 20 == 0) {
                        Console.WriteLine();
                    }
                }
            }

            Console.WriteLine("\nThe first 40 odd Zumkeller numbers are:");
            i = 3;
            for (int count = 0; count < 40; i += 2) {
                if (IsZumkeller(i)) {
                    Console.Write("{0,5} ", i);
                    count++;
                    if (count % 10 == 0) {
                        Console.WriteLine();
                    }
                }
            }

            Console.WriteLine("\nThe first 40 odd Zumkeller numbers which don't end in 5 are:");
            i = 3;
            for (int count = 0; count < 40; i += 2) {
                if (i % 10 != 5 && IsZumkeller(i)) {
                    Console.Write("{0,7} ", i);
                    count++;
                    if (count % 8 == 0) {
                        Console.WriteLine();
                    }
                }
            }
        }
    }
}


dict = { 'def' => 1, 'abc' => 2 }

for( keyvalue in dict ) io.writeln( keyvalue );
for( key in dict.keys(); value in dict.values() ) io.writeln( key, value )
dict.iterate { [key, value]
    io.writeln( key, value )
}


main(){
	var fruits = {
		'apples':  'red',
		'oranges': 'orange',
		'bananas': 'yellow',
		'pears':   'green',
		'plums':   'purple'
	};

	print('Key Value pairs:');
	fruits.forEach( (fruits, color) => print( '$fruits are $color' ) );

	print('\nKeys only:');
	fruits.keys.forEach( ( key ) => print( key ) );

	print('\nValues only:');
	fruits.values.forEach( ( value ) => print( value ) );
}


import std.stdio;
const N = 101; // #doors + 1
void main() {
  bool[N] doors = false;
  for(auto door=1; door<N; door++ ) {
    for(auto i=door; i<N; i+=door ) doors[i] = !doors[i];
    if (doors[door]) write(door, " ");
  }
}


import extensions;

public program()
{
    console.printLine("0^0 is ",0.power:0)
}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>

using namespace std;

// Returns n in binary right justified with length passed and padded with zeroes
const uint* binary(uint n, uint length);

// Returns the sum of the binary ordered subset of rank r.
// Adapted from Sympy implementation.
uint sum_subset_unrank_bin(const vector<uint>& d, uint r);

vector<uint> factors(uint x);

bool isPrime(uint number);

bool isZum(uint n);

ostream& operator<<(ostream& os, const vector<uint>& zumz) {
    for (uint i = 0; i < zumz.size(); i++) {
        if (i % 10 == 0)
            os << endl;
        os << setw(10) << zumz[i] << ' ';
    }
    return os;
}

int main() {
    cout << "First 220 Zumkeller numbers:" << endl;
    vector<uint> zumz;
    for (uint n = 2; zumz.size() < 220; n++)
        if (isZum(n))
            zumz.push_back(n);
    cout << zumz << endl << endl;

    cout << "First 40 odd Zumkeller numbers:" << endl;
    vector<uint> zumz2;
    for (uint n = 2; zumz2.size() < 40; n++)
        if (n % 2 && isZum(n))
            zumz2.push_back(n);
    cout << zumz2 << endl << endl;

    cout << "First 40 odd Zumkeller numbers not ending in 5:" << endl;
    vector<uint> zumz3;
    for (uint n = 2; zumz3.size() < 40; n++)
        if (n % 2 && (n % 10) !=  5 && isZum(n))
            zumz3.push_back(n);
    cout << zumz3 << endl << endl;

    return 0;
}

// Returns n in binary right justified with length passed and padded with zeroes
const uint* binary(uint n, uint length) {
    uint* bin = new uint[length];	    // array to hold result
    fill(bin, bin + length, 0);         // fill with zeroes
    // convert n to binary and store right justified in bin
    for (uint i = 0; n > 0; i++) {
        uint rem = n % 2;
        n /= 2;
        if (rem)
            bin[length - 1 - i] = 1;
    }

    return bin;
}

// Returns the sum of the binary ordered subset of rank r.
// Adapted from Sympy implementation.
uint sum_subset_unrank_bin(const vector<uint>& d, uint r) {
    vector<uint> subset;
    // convert r to binary array of same size as d
    const uint* bits = binary(r, d.size() - 1);

    // get binary ordered subset
    for (uint i = 0; i < d.size() - 1; i++)
        if (bits[i])
            subset.push_back(d[i]);

    delete[] bits;

    return accumulate(subset.begin(), subset.end(), 0u);
}

vector<uint> factors(uint x) {
    vector<uint> result;
    // this will loop from 1 to int(sqrt(x))
    for (uint i = 1; i * i <= x; i++) {
        // Check if i divides x without leaving a remainder
        if (x % i == 0) {
            result.push_back(i);

            if (x / i != i)
                result.push_back(x / i);
        }
    }

    // return the sorted factors of x
    sort(result.begin(), result.end());
    return result;
}

bool isPrime(uint number) {
    if (number < 2) return false;
    if (number == 2) return true;
    if (number % 2 == 0) return false;
    for (uint i = 3; i * i <= number; i += 2)
        if (number % i == 0) return false;

    return true;
}

bool isZum(uint n) {
    // if prime it ain't no zum
    if (isPrime(n))
        return false;

    // get sum of divisors
    const auto d = factors(n);
    uint s = accumulate(d.begin(), d.end(), 0u);

    // if sum is odd or sum < 2*n it ain't no zum
    if (s % 2 || s < 2 * n)
        return false;

    // if we get here and n is odd or n has at least 24 divisors it's a zum!
    // Valid for even n < 99504. To test n beyond this bound, comment out this condition.
    // And wait all day. Thanks to User:Horsth for taking the time to find this bound!
    if (n % 2 || d.size() >= 24)
        return true;

    if (!(s % 2) && d[d.size() - 1] <= s / 2)
        for (uint x = 2; (uint) log2(x) < (d.size() - 1); x++) // using log2 prevents overflow
            if (sum_subset_unrank_bin(d, x) == s / 2)
                return true; // congratulations it's a zum num!!

    // if we get here it ain't no zum
    return false;
}


program AssociativeArrayIteration;

{$APPTYPE CONSOLE}

uses SysUtils, Generics.Collections;

var
  i: Integer;
  s: string;
  lDictionary: TDictionary<string, Integer>;
  lPair: TPair<string, Integer>;
begin
  lDictionary := TDictionary<string, Integer>.Create;
  try
    lDictionary.Add('foo', 5);
    lDictionary.Add('bar', 10);
    lDictionary.Add('baz', 15);
    lDictionary.AddOrSetValue('foo', 6);

    for lPair in lDictionary do
      Writeln(Format('Pair: %s = %d', [lPair.Key, lPair.Value]));
    for s in lDictionary.Keys do
      Writeln('Key: ' + s);
    for i in lDictionary.Values do
      Writeln('Value: ', i);
  finally
    lDictionary.Free;
  end;
end.


datatype Door = Closed | Open

method InitializeDoors(n:int) returns (doors:array<Door>)
  // Precondition: n must be a valid array size.
  requires n >= 0
  // Postcondition: doors is an array, which is not an alias for any other
  // object, with a length of n, all of whose elements are Closed. The "fresh"
  // (non-alias) condition is needed to allow doors to be modified by the
  // remaining code.
  ensures doors != null && fresh(doors) && doors.Length == n
  ensures forall j :: 0 <= j < doors.Length ==> doors[j] == Closed;
{
  doors := new Door[n];
  var i := 0;
  // Invariant: i is always a valid index inside the loop, and all doors less
  // than i are Closed. These invariants are needed to ensure the second
  // postcondition.
  while i < doors.Length
    invariant i <= doors.Length
    invariant forall j :: 0 <= j < i ==> doors[j] == Closed;
  {
    doors[i] := Closed;
    i := i + 1;
  }
}

method Main ()
{
  var doors := InitializeDoors(100);

  var pass := 1;
  while pass <= doors.Length
  {
    var door := pass;
    while door < doors.Length
    {
      doors[door] := if doors[door] == Closed then Open else Closed;
      door := door + pass;
    }
    pass := pass + 1;
  }
  var i := 0;
  while i < doors.Length
  {
    print i, " is ", if doors[i] == Closed then "closed\n" else "open\n";
    i := i + 1;
  }
}


USING: math.functions.private ; ! ^complex
0 0 ^
C{ 0 0 } C{ 0 0 } ^complex


/* created by Aykayayciti Earl Lamont Montgomery
April 9th, 2018 */

x = 0
y = 0
z = x**y
> "z=", z


import std.algorithm;
import std.stdio;

int[] getDivisors(int n) {
    auto divs = [1, n];
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            divs ~= i;

            int j = n / i;
            if (i != j) {
                divs ~= j;
            }
        }
    }
    return divs;
}

bool isPartSum(int[] divs, int sum) {
    if (sum == 0) {
        return true;
    }
    auto le = divs.length;
    if (le == 0) {
        return false;
    }
    auto last = divs[$ - 1];
    int[] newDivs;
    for (int i = 0; i < le - 1; i++) {
        newDivs ~= divs[i];
    }
    if (last > sum) {
        return isPartSum(newDivs, sum);
    } else {
        return isPartSum(newDivs, sum) || isPartSum(newDivs, sum - last);
    }
}

bool isZumkeller(int n) {
    auto divs = getDivisors(n);
    auto sum = divs.sum();
    // if sum is odd can't be split into two partitions with equal sums
    if (sum % 2 == 1) {
        return false;
    }
    // if n is odd use 'abundant odd number' optimization
    if (n % 2 == 1) {
        auto abundance = sum - 2 * n;
        return abundance > 0 && abundance % 2 == 0;
    }
    // if n and sum are both even check if there's a partition which totals sum / 2
    return isPartSum(divs, sum / 2);
}

void main() {
    writeln("The first 220 Zumkeller numbers are:");
    int i = 2;
    for (int count = 0; count < 220; i++) {
        if (isZumkeller(i)) {
            writef("%3d ", i);
            count++;
            if (count % 20 == 0) {
                writeln;
            }
        }
    }

    writeln("\nThe first 40 odd Zumkeller numbers are:");
    i = 3;
    for (int count = 0; count < 40; i += 2) {
        if (isZumkeller(i)) {
            writef("%5d ", i);
            count++;
            if (count % 10 == 0) {
                writeln;
            }
        }
    }

    writeln("\nThe first 40 odd Zumkeller numbers which don't end in 5 are:");
    i = 3;
    for (int count = 0; count < 40; i += 2) {
        if (i % 10 != 5 && isZumkeller(i)) {
            writef("%7d ", i);
            count++;
            if (count % 8 == 0) {
                writeln;
            }
        }
    }
}


def map := [
  "a" => 1,
  "b" => 2,
  "c" => 3,
]

for key => value in map {
  println(`$key $value`)
}

for value in map {     # ignore keys
  println(`. $value`)
}

for key => _ in map {  # ignore values
  println(`$key .`)
}

for key in map.domain() {     # iterate over the set whose values are the keys
  println(`$key .`)
}


(lib 'hash) ;; load hash.lib
(define H (make-hash))
;; fill hash table
(hash-set H 'Simon 42)
(hash-set H 'Albert 666)
(hash-set H 'Antoinette 33)

;; iterate over (key . value ) pairs
(for ([kv H]) (writeln kv))
(Simon . 42)
(Albert . 666)
(Antoinette . 33)

;; iterate over keys
(for ([k (hash-keys H)]) (writeln 'key-> k))
key->     Simon
key->     Albert
key->     Antoinette

;; iterate over values
(for ([v (hash-values H)]) (writeln 'value-> v))
value->     42
value->     666
value->     33


program zero
double precision :: i, j
double complex :: z1, z2
i = 0.0D0
j = 0.0D0
z1 = (0.0D0,0.0D0)
z2 = (0.0D0,0.0D0)
write(*,*) 'When integers are used, we have 0^0 = ', 0**0
write(*,*) 'When double precision numbers are used, we have 0.0^0.0 = ', i**j
write(*,*) 'When complex numbers are used, we have (0.0+0.0i)^(0.0+0.0i) = ', z1**z2
end program


// Zumkeller numbers: Nigel Galloway. May 16th., 2021
let rec fG n g=match g with h::_ when h>=n->h=n |h::t->fG n t || fG(n-h) t |_->false
let fN g=function n when n&&&1=1->false
                 |n->let e=n/2-g in match compare e 0 with 0->true
                                                          |1->let l=[1..e]|>List.filter(fun n->g%n=0)
                                                              match compare(l|>List.sum) e with 1->fG e l |0->true |_->false
                                                          |_->false
Seq.initInfinite((+)1)|>Seq.map(fun n->(n,sod n))|>Seq.filter(fun(n,g)->fN n g)|>Seq.take 220|>Seq.iter(fun(n,_)->printf "%d " n); printfn "\n"
Seq.initInfinite((*)2>>(+)1)|>Seq.map(fun n->(n,sod n))|>Seq.filter(fun(n,g)->fN n g)|>Seq.take 40|>Seq.iter(fun(n,_)->printf "%d " n); printfn "\n"
Seq.initInfinite((*)2>>(+)1)|>Seq.filter(fun n->n%10<>5)|>Seq.map(fun n->(n,sod n))|>Seq.filter(fun(n,g)->fN n g)|>Seq.take 40|>Seq.iter(fun(n,_)->printf "%d " n); printfn "\n"


import system'collections;
import system'routines;
import extensions;

public program()
{
    // 1. Create
    var map := Dictionary.new();
    map["key"] := "foox";
    map["key"] := "foo";
    map["key2"]:= "foo2";
    map["key3"]:= "foo3";
    map["key4"]:= "foo4";

    // Enumerate
    map.forEach:
        (keyValue){ console.printLine(keyValue.Key," : ",keyValue.Value) }
}


IO.inspect d = Map.new([foo: 1, bar: 2, baz: 3])
Enum.each(d, fn kv -> IO.inspect kv end)
Enum.each(d, fn {k,v} -> IO.puts "#{inspect k} => #{v}" end)
Enum.each(Map.keys(d), fn key -> IO.inspect key end)
Enum.each(Map.values(d), fn value -> IO.inspect value end)


-module(assoc).
-compile([export_all]).

test_create() ->
    D = dict:new(),
    D1 = dict:store(foo,1,D),
    D2 = dict:store(bar,2,D1),
    print_vals(D2).

print_vals(D) ->
    lists:foreach(fun (K) ->
                          io:format("~p: ~b~n",[K,dict:fetch(K,D)])
                  end, dict:fetch_keys(D)).


## NB: This code uses the dc command "r" via register "r".
##     You may comment out the unwanted version.
[SxSyLxLy]sr    # this should work with every "dc"
[r]sr           # GNU dc can exchange top 2 stack values by "r"
## Now use "lrx" instead of "r" ...

0k              # we work without decimal places
[q]sq           # useful e.g. as loop termination

## (x)(y)>R  ==  if (y)>(x) eval R
## isle         x y --> (x <= y)
[
    [1q]S. [ !<. 0 ]x s.L.
]sl
## l: isle

[
    100 llx
]sL
## L: isle100

## for  initcode condcode incrcode body
##       [1]      [2]      [3]      [4]
[
    [q]S. 4:. 3:. 2:. 1:.  1;.x [2;.x 0=. 4;.x 3;.x 0;.x]d0:.x Os.L.o
]sf
## f: for
##----------------------------------------------------------------------------

##      for( i=1 ; i<=100 ; ++i ) {
##          door[i] = 0;
##      }
#[init ...]P []ps-
[1si] [li lLx] [li1+si] [
    li 0:d
]lfx

##      for( s=1 ; s<=100 ; ++s ) {
##          for( i=s ; i<=100 ; i+=s ) {
##              door[i] = 1 - door[i]
##          }
##      }
[1ss] [ls lLx] [ls1+ss] [
    #[step ]P lsn [ ...]ps-
    [lssi] [li lLx] [lils+si] [
        1 li;d - li:d
    ]lfx
]lfx

##      long output:
##          for( i=1 ; i<=100 ; ++i ) {
##              print "door #", i, " is ", (door[i] ? "open" : "closed")), NL
##          }
[
    [1si] [li lLx] [li1+si] [
        [door #]P
        li n
        [ is ]P
            [closed]
            [open]
        li;d 0=r lrx s- n
        [.]ps-
    ]lfx
]

##      terse output:
##          for( i=1 ; i<=100 ; ++i ) {
##              if( door[i] ) {
##                  print i
##              }
##              print NL
##          }
[
    [1si] [li lLx] [li1+si] [
        [] [ [ ]n lin ]
        li;d 0=r lrx s- x
    ]lfx
    []ps-
]

lrx             # comment out for the long output version
s- x
#[stack rest...]P []ps- f


package main

import (
    "fmt"
    "math"
    "math/big"
    "math/cmplx"
)

func main() {
    fmt.Println("float64:    ", math.Pow(0, 0))
    var b big.Int
    fmt.Println("big integer:", b.Exp(&b, &b, nil))
    fmt.Println("complex:    ", cmplx.Pow(0, 0))
}


import Data.Complex

main = do
  print $ 0 ^ 0
  print $ 0.0 ^ 0
  print $ 0 ^^ 0
  print $ 0 ** 0
  print $ (0 :+ 0) ^ 0
  print $ (0 :+ 0) ** (0 :+ 0)


F average(x)
   R sum(x) / Float(x.len)

print(average([0, 0, 3, 1, 4, 1, 5, 9, 0, 0]))


AVGP     CSECT
         USING  AVGP,12
         LR     12,15
         SR     3,3                i=0
         SR     6,6                sum=0
LOOP     CH     3,=AL2(NN-T-1)     for i=1 to nn
         BH     ENDLOOP
         L      2,T(3)             t(i)
         MH     2,=H'100'          scaling factor=2
         AR     6,2                sum=sum+t(i)
         LA     3,4(3)             next i
         B      LOOP
ENDLOOP  LR     5,6                sum
         LA     4,0
         D      4,NN               sum/nn
         XDECO  5,Z                edit binary
         MVC    U,Z+10             descale
         MVI    Z+10,C'.'
         MVC    Z+11(2),U
         XPRNT  Z,80               output
         XR     15,15
         BR     14
T        DC     F'10',F'9',F'8',F'7',F'6',F'5',F'4',F'3',F'2',F'1'
NN       DC     A((NN-T)/4)
Z        DC     CL80' '
U        DS     CL2
         END    AVGP


ArithmeticMean:		PHA
			TYA
			PHA		;push accumulator and Y register onto stack

			LDA #0
			STA Temp
			STA Temp+1	;temporary 16-bit storage for total

			LDY NumberInts
			BEQ Done	;if NumberInts = 0 then return an average of zero

			DEY		;start with NumberInts-1
AddLoop:		LDA (ArrayPtr),Y
			CLC
			ADC Temp
			STA Temp
			LDA Temp+1
			ADC #0
			STA Temp+1
			DEY
			CPY #255
			BNE AddLoop

			LDY #-1
DivideLoop:		LDA Temp
			SEC
			SBC NumberInts
			STA Temp
			LDA Temp+1
			SBC #0
			STA Temp+1
			INY
			BCS DivideLoop

Done:			STY ArithMean	;store result here
			PLA		;restore accumulator and Y register from stack
			TAY
			PLA
			RTS		;return from routine


USING: combinators grouping io kernel lists lists.lazy math
math.primes.factors memoize prettyprint sequences ;

MEMO: psum? ( seq n -- ? )
    {
        { [ dup zero? ] [ 2drop t ] }
        { [ over length zero? ] [ 2drop f ] }
        { [ over last over > ] [ [ but-last ] dip psum? ] }
        [
            [ [ but-last ] dip psum? ]
            [ over last - [ but-last ] dip psum? ] 2bi or
        ]
    } cond ;

: zumkeller? ( n -- ? )
    dup divisors dup sum
    {
        { [ dup odd? ] [ 3drop f ] }
        { [ pick odd? ] [ nip swap 2 * - [ 0 > ] [ even? ] bi and ] }
        [ nipd 2/ psum? ]
    } cond ;

: zumkellers ( -- list )
    1 lfrom [ zumkeller? ] lfilter ;

: odd-zumkellers ( -- list )
    1 [ 2 + ] lfrom-by [ zumkeller? ] lfilter ;

: odd-zumkellers-no-5 ( -- list )
    odd-zumkellers [ 5 mod zero? not ] lfilter ;

: show ( count list row-len -- )
    [ ltake list>array ] dip group simple-table. nl ;

"First 220 Zumkeller numbers:" print
220 zumkellers 20 show

"First 40 odd Zumkeller numbers:" print
40 odd-zumkellers 10 show

"First 40 odd Zumkeller numbers not ending with 5:" print
40 odd-zumkellers-no-5 8 show


package main

import "fmt"

func getDivisors(n int) []int {
    divs := []int{1, n}
    for i := 2; i*i <= n; i++ {
        if n%i == 0 {
            j := n / i
            divs = append(divs, i)
            if i != j {
                divs = append(divs, j)
            }
        }
    }
    return divs
}

func sum(divs []int) int {
    sum := 0
    for _, div := range divs {
        sum += div
    }
    return sum
}

func isPartSum(divs []int, sum int) bool {
    if sum == 0 {
        return true
    }
    le := len(divs)
    if le == 0 {
        return false
    }
    last := divs[le-1]
    divs = divs[0 : le-1]
    if last > sum {
        return isPartSum(divs, sum)
    }
    return isPartSum(divs, sum) || isPartSum(divs, sum-last)
}

func isZumkeller(n int) bool {
    divs := getDivisors(n)
    sum := sum(divs)
    // if sum is odd can't be split into two partitions with equal sums
    if sum%2 == 1 {
        return false
    }
    // if n is odd use 'abundant odd number' optimization
    if n%2 == 1 {
        abundance := sum - 2*n
        return abundance > 0 && abundance%2 == 0
    }
    // if n and sum are both even check if there's a partition which totals sum / 2
    return isPartSum(divs, sum/2)
}

func main() {
    fmt.Println("The first 220 Zumkeller numbers are:")
    for i, count := 2, 0; count < 220; i++ {
        if isZumkeller(i) {
            fmt.Printf("%3d ", i)
            count++
            if count%20 == 0 {
                fmt.Println()
            }
        }
    }
    fmt.Println("\nThe first 40 odd Zumkeller numbers are:")
    for i, count := 3, 0; count < 40; i += 2 {
        if isZumkeller(i) {
            fmt.Printf("%5d ", i)
            count++
            if count%10 == 0 {
                fmt.Println()
            }
        }
    }
    fmt.Println("\nThe first 40 odd Zumkeller numbers which don't end in 5 are:")
    for i, count := 3, 0; count < 40; i += 2 {
        if (i % 10 != 5) && isZumkeller(i) {
            fmt.Printf("%7d ", i)
            count++
            if count%8 == 0 {
                fmt.Println()
            }
        }
    }
    fmt.Println()
}


let myMap = [ ("Hello", 1); ("World", 2); ("!", 3) ]

for k, v in myMap do
  printfn "%s -> %d" k v


H{ { "hi" "there" } { "a" "b" } } [ ": " glue print ] assoc-each


class Main
{
  public static Void main ()
  {
    Int:Str map := [1:"alpha", 2:"beta", 3:"gamma"]

    map.keys.each |Int key|
    {
      echo ("Key is: $key")
    }

    map.vals.each |Str value|
    {
      echo ("Value is: $value")
    }

    map.each |Str value, Int key|
    {
      echo ("Key $key maps to $value")
    }
  }
}


$! doors.com
$! Excecute by running @doors at prompt.
$ square = 1
$ incr = 3
$ count2 = 0
$ d = 1
$ LOOP2:
$       count2 = count2 + 1
$       IF (d .NE. square)
$               THEN WRITE SYS$OUTPUT "door ''d' is closed"
$       ELSE WRITE SYS$OUTPUT "door ''d' is open"
$               square = incr + square
$               incr = incr + 2
$       ENDIF
$       d = d + 1
$       IF (count2 .LT. 100) THEN GOTO LOOP2


(defun mean-r (xs)
   (if (endp xs)
       (mv 0 0)
       (mv-let (m j)
               (mean-r (rest xs))
          (mv (+ (first xs) m) (+ j 1)))))

(defun mean (xs)
   (if (endp xs)
       0
       (mv-let (n d)
               (mean-r xs)
          (/ n d))))


import Data.List (group, sort)
import Data.List.Split (chunksOf)
import Data.Numbers.Primes (primeFactors)

-------------------- ZUMKELLER NUMBERS -------------------

isZumkeller :: Int -> Bool
isZumkeller n =
  let ds = divisors n
      m = sum ds
   in ( even m
          && let half = div m 2
              in elem half ds
                   || ( all (half >=) ds
                          && summable half ds
                      )
      )

summable :: Int -> [Int] -> Bool
summable _ [] = False
summable x xs@(h : t) =
  elem x xs
    || summable (x - h) t
    || summable x t

divisors :: Int -> [Int]
divisors x =
  sort
    ( foldr
        ( flip ((<*>) . fmap (*))
            . scanl (*) 1
        )
        [1]
        (group (primeFactors x))
    )

--------------------------- TEST -------------------------
main :: IO ()
main =
  mapM_
    ( \(s, n, xs) ->
        putStrLn $
          s
            <> ( '\n' :
                 tabulated
                   10
                   (take n (filter isZumkeller xs))
               )
    )
    [ ("First 220 Zumkeller numbers:", 220, [1 ..]),
      ("First 40 odd Zumkeller numbers:", 40, [1, 3 ..])
    ]

------------------------- DISPLAY ------------------------
tabulated ::
  Show a =>
  Int ->
  [a] ->
  String
tabulated nCols = go
  where
    go xs =
      let ts = show <$> xs
          w = succ (maximum (length <$> ts))
       in unlines
            ( concat
                <$> chunksOf
                  nCols
                  (justifyRight w ' ' <$> ts)
            )

justifyRight :: Int -> Char -> String -> String
justifyRight n c = (drop . length) <*> (replicate n c <>)


include ffl/hct.fs
include ffl/hci.fs

\ Create hashtable and iterator in dictionary
10     hct-create htable
htable hci-create hiter

\ Insert entries
1 s" hello" htable hct-insert
2 s" world" htable hct-insert
3 s" !"     htable hct-insert

: iterate
  hiter hci-first
  BEGIN
  WHILE
    ." key = " hiter hci-key type ." , value = " . cr
    hiter hci-next
  REPEAT
;

iterate


#include"assoc.bas"

function get_dict_data_string( d as dicitem ) as string
    select case d.datatype
        case BOOL
            if d.value.bool then return "true" else return "false"
        case INTEG
            return str(d.value.integ)
        case STRNG
            return """"+d.value.strng+""""
        case FLOAT
            return str(d.value.float)
        case BYYTE
            return str(d.value.byyte)
        case else
            return "DATATYPE ERROR"
    end select
end function

sub print_keyval_pair( d as dicentry )
    print using "{&} : {&}";get_dict_data_string( d.key ); get_dict_data_string(d.value)

end sub

for i as uinteger = 0 to ubound(Dictionary)
    print_keyval_pair(Dictionary(i))
next i


proc nonrec main() void:
    byte DOORS = 100;
    [DOORS+1] bool door_open;
    unsigned DOORS i, j;

    /* make sure all doors are closed */
    for i from 1 upto DOORS do door_open[i] := false od;

    /* pass through the doors */
    for i from 1 upto DOORS do
        for j from i by i upto DOORS do
            door_open[j] := not door_open[j]
        od
    od;

    /* show the open doors */
    for i from 1 upto DOORS do
        if door_open[i] then
            writeln("Door ", i, " is open.")
        fi
    od
corp


def power(y): y as $y | if $y == 0 then 1 elif . == 0 then 0 else log * $y | exp end;


using Printf

const types = (Complex, Float64, Rational, Int, Bool)

for Tb in types, Te in types
    zb, ze = zero(Tb), zero(Te)
    r = zb ^ ze
    @printf("%10s ^ %-10s = %7s ^ %-7s = %-12s (%s)\n", Tb, Te, zb, ze, r, typeof(r))
end


:mypower
    dup not (
      [ drop sign dup 0 equal [ drop 1 ] if ]
      [ power ]
    ) if
;

0 0 mypower print nl

"End " input


// version 1.0.6

fun main(args: Array<String>) {
   println("0 ^ 0 = ${Math.pow(0.0, 0.0)}")
}


INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit

PROC Mean(INT ARRAY a INT count REAL POINTER result)
  INT i
  REAL x,sum,tmp

  IntToReal(0,sum)
  FOR i=0 TO count-1
  DO
    IntToReal(a(i),x)
    RealAdd(sum,x,tmp)
    RealAssign(tmp,sum)
  OD
  IntToReal(count,tmp)
  RealDiv(sum,tmp,result)
RETURN

PROC Test(INT ARRAY a INT count)
  INT i
  REAL result

  Mean(a,count,result)
  Print("mean(")
  FOR i=0 TO count-1
  DO
    PrintI(a(i))
    IF i<count-1 THEN
      Put(',)
    FI
  OD
  Print(")=")
  PrintRE(result)
RETURN

PROC Main()
  INT ARRAY a1=[1 2 3 4 5 6]
  INT ARRAY a2=[1 10 100 1000 10000]
  INT ARRAY a3=[9]

  Put(125) PutE() ;clear screen
  Test(a1,6)
  Test(a2,5)
  Test(a3,1)
  Test(a3,0)
RETURN


function mean(vector:Vector.<Number>):Number
{
	var sum:Number = 0;
	for(var i:uint = 0; i < vector.length; i++)
		sum += vector[i];
	return vector.length == 0 ? 0 : sum / vector.length;
}


with Ada.Float_Text_Io; use Ada.Float_Text_Io;
with Ada.Text_IO; use Ada.Text_IO;

procedure Mean_Main is
   type Vector is array (Positive range <>) of Float;
   function Mean (Item : Vector) return float with pre => Item'length > 0;
   function Mean (Item : Vector) return Float is
      Sum : Float := 0.0;
   begin
      for I in Item'range loop
         Sum := Sum + Item(I);
      end loop;
	  return Sum / Float(Item'Length);
   end Mean;
   A : Vector := (3.0, 1.0, 4.0, 1.0, 5.0, 9.0);
begin
    Put(Item => Mean (A), Fore => 1, Exp => 0);
   New_Line;
   -- test for zero length vector
   Put(Item => Mean(A (1..0)), Fore => 1, Exp => 0);
   New_Line;
end Mean_Main;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ZumkellerNumbers {

    public static void main(String[] args) {
        int n = 1;
        System.out.printf("First 220 Zumkeller numbers:%n");
        for ( int count = 1 ; count <= 220 ; n += 1 ) {
            if ( isZumkeller(n) ) {
                System.out.printf("%3d  ", n);
                if ( count % 20 == 0 ) {
                    System.out.printf("%n");
                }
                count++;
            }
        }

        n = 1;
        System.out.printf("%nFirst 40 odd Zumkeller numbers:%n");
        for ( int count = 1 ; count <= 40 ; n += 2 ) {
            if ( isZumkeller(n) ) {
                System.out.printf("%6d", n);
                if ( count % 10 == 0 ) {
                    System.out.printf("%n");
                }
                count++;
            }
        }

        n = 1;
        System.out.printf("%nFirst 40 odd Zumkeller numbers that do not end in a 5:%n");
        for ( int count = 1 ; count <= 40 ; n += 2 ) {
            if ( n % 5 != 0 && isZumkeller(n) ) {
                System.out.printf("%8d", n);
                if ( count % 10 == 0 ) {
                    System.out.printf("%n");
                }
                count++;
            }
        }

    }

    private static boolean isZumkeller(int n) {
        //  numbers congruent to 6 or 12 modulo 18 are Zumkeller numbers
        if ( n % 18 == 6 || n % 18 == 12 ) {
            return true;
        }

        List<Integer> divisors = getDivisors(n);
        int divisorSum = divisors.stream().mapToInt(i -> i.intValue()).sum();

        //  divisor sum cannot be odd
        if ( divisorSum % 2 == 1 ) {
            return false;
        }

        // numbers where n is odd and the abundance is even are Zumkeller numbers
        int abundance = divisorSum - 2 * n;
        if ( n % 2 == 1 && abundance > 0 && abundance % 2 == 0 ) {
            return true;
        }

        Collections.sort(divisors);
        int j = divisors.size() - 1;
        int sum = divisorSum/2;

        //  Largest divisor larger than sum - then cannot partition and not Zumkeller number
        if ( divisors.get(j) > sum ) {
            return false;
        }

        return canPartition(j, divisors, sum, new int[2]);
    }

    private static boolean canPartition(int j, List<Integer> divisors, int sum, int[] buckets) {
        if ( j < 0 ) {
            return true;
        }
        for ( int i = 0 ; i < 2 ; i++ ) {
            if ( buckets[i] + divisors.get(j) <= sum ) {
                buckets[i] += divisors.get(j);
                if ( canPartition(j-1, divisors, sum, buckets) ) {
                    return true;
                }
                buckets[i] -= divisors.get(j);
            }
            if( buckets[i] == 0 ) {
                break;
            }
        }
        return false;
    }

    private static final List<Integer> getDivisors(int number) {
        List<Integer> divisors = new ArrayList<Integer>();
        long sqrt = (long) Math.sqrt(number);
        for ( int i = 1 ; i <= sqrt ; i++ ) {
            if ( number % i == 0 ) {
                divisors.add(i);
                int div = number / i;
                if ( div != i ) {
                    divisors.add(div);
                }
            }
        }
        return divisors;
    }

}


program AssociativeArrayIteration;
{$mode delphi}{$ifdef windows}{$apptype console}{$endif}
uses Generics.Collections;

type
  TlDictionary =  TDictionary<string, Integer>;
  TlPair = TPair<string,integer>;

var
  i: Integer;
  s: string;
  lDictionary: TlDictionary;
  lPair: TlPair;
begin
  lDictionary := TlDictionary.Create;
  try
    lDictionary.Add('foo', 5);
    lDictionary.Add('bar', 10);
    lDictionary.Add('baz', 15);
    lDictionary.AddOrSetValue('foo',6);
    for lPair in lDictionary do
      Writeln('Pair: ',Lpair.Key,' = ',lPair.Value);
    for s in lDictionary.Keys do
      Writeln('Key: ' + s);
    for i in lDictionary.Values do
      Writeln('Value: ', i);
  finally
    lDictionary.Free;
  end;
end.


d = new dict[[[1, "one"], [2, "two"]]]
for [key, value] = d
   println["$key\t$value"]

println[]
for key = keys[d]
   println["$key"]


Module Checkit {
      x=0
      y=0
      Print x**y=1, x^y=1    ' True True
}
Checkit


real
mean(list l)
{
    real sum, x;

    sum = 0;
    for (, x in l) {
        sum += x;
    }

    sum / ~l;
}

integer
main(void)
{
    o_form("%f\n", mean(list(4.5, 7.25, 5r, 5.75)));

    0;
}


PROC mean = (REF[]REAL p)REAL:
# Calculates the mean of qty REALs beginning at p. #
  IF LWB p > UPB p THEN 0.0
  ELSE
    REAL total := 0.0;
    FOR i FROM LWB p TO UPB p DO total +:= p[i] OD;
    total / (UPB p - LWB p + 1)
  FI;

main:(
  [6]REAL test := (1.0, 2.0, 5.0, -5.0, 9.5, 3.14159);
  print((mean(test),new line))
)