Two sum: Difference between revisions
Content deleted Content added
Alextretyak (talk | contribs) 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
A '''numeric digits 500''' statement was added just in case some
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 " " " */
@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(_) )
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. */
|