# # twosum.icn, find two array elements that add up to a given sum # Dedicated to the public domain # link fullimag procedure main(arglist) sum := pop(arglist) | 21 L := [] if *arglist > 0 then every put(L, integer(!arglist)) & L := sort(L) else L := [0, 2, 11, 19, 90] write(sum) write(fullimage(L)) write(fullimage(twosum(sum, L))) end # assume sorted list, only interested in zero or one solution procedure twosum(sum, L) i := 1 j := *L while i < j do { try := L[i] + L[j] if try = sum then return [i,j] else if try < sum then i +:= 1 else j -:= 1 } return [] end