Two sum: Difference between revisions

Content added Content deleted
(Added 11l)
m (→‎version 2: added/changed comments and whitespace.)
Line 2,071:
The list of numbers can be in any format,   not just integers.   Also, they need not be unique.
 
The list of integers need   needn''not''t   be sorted.
 
A   '''numeric digits 500'''   statement was added just in case some rather largehumongous numbers were entered.
 
No verification was performed to ensure that all items in the list were numeric.
 
A little extra code was added to have the output columns aligned.
Line 2,085:
say 'the list: ' list /*echo the list to the terminal*/
say 'the target sum: ' targ /* " " target sum " " " */
solw= 0; w=0 sol= 0 /*numberwidth; # of solutions found (so far). */
@solution= 'a solution: zero─based indices ' /*a SAY literal for space conservation.*/
sol=0; w=0 /*number of solutions found (so far). */
do #=0 for words(list); _=word(list, #+1) /*examine the list, construct an array.*/
@.#= _; w= max(w, length(_) ) /*assign a number to an indexed array. */
end /*#*/ /*W: the maximum width of any number. */
L= length(#) /*L: " " " " " index. */
@solution= 'a solution: zero─based indices ' /*a SAY literal for space conservation.*/
say /* [↓] look for sum of 2 numbers=target*/
do a=0 for # /*scan up to the last number in array. */