Two sum: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
m (→version 2: added/changed comments and whitespace.) |
||
Line 2,071: | Line 2,071: | ||
The list of numbers can be in any format, not just integers. Also, they need not be unique. |
The list of numbers can be in any format, not just integers. Also, they need not be unique. |
||
The list of integers |
The list of integers needn't be sorted. |
||
A '''numeric digits 500''' statement was added just in case some |
A '''numeric digits 500''' statement was added just in case some humongous numbers were entered. |
||
No verification was performed to ensure that all items were numeric. |
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. |
A little extra code was added to have the output columns aligned. |
||
Line 2,085: | Line 2,085: | ||
say 'the list: ' list /*echo the list to the terminal*/ |
say 'the list: ' list /*echo the list to the terminal*/ |
||
say 'the target sum: ' targ /* " " target sum " " " */ |
say 'the target sum: ' targ /* " " target sum " " " */ |
||
⚫ | |||
⚫ | |||
⚫ | |||
do #=0 for words(list); _=word(list, #+1) /*examine the list, construct an array.*/ |
do #=0 for words(list); _=word(list, #+1) /*examine the list, construct an array.*/ |
||
@.#= _; w= max(w, length(_) ) |
@.#= _; w= max(w, length(_) ) /*assign a number to an indexed array. */ |
||
end /*#*/ /*W: the maximum width of any number. */ |
end /*#*/ /*W: the maximum width of any number. */ |
||
L= length(#) /*L: " " " " " index. */ |
L= length(#) /*L: " " " " " index. */ |
||
⚫ | |||
say /* [↓] look for sum of 2 numbers=target*/ |
say /* [↓] look for sum of 2 numbers=target*/ |
||
do a=0 for # /*scan up to the last number in array. */ |
do a=0 for # /*scan up to the last number in array. */ |