Talk:Two sum: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 11: Line 11:
The English formulation of the task may also need a slight tweak – the phrase "If so, return indices of '''the''' two integers" skips a bit heavily over the thin ice – it seems to express an assumption that any solution would necessarily be unique. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 07:55, 17 October 2016 (UTC)
The English formulation of the task may also need a slight tweak – the phrase "If so, return indices of '''the''' two integers" skips a bit heavily over the thin ice – it seems to express an assumption that any solution would necessarily be unique. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 07:55, 17 October 2016 (UTC)


== (from the task description) given an sorted array of positive integers ... ==
== (from the task description) Given a sorted array of positive integers ... ==
Given that the example list is an ordered list (of positive integers),   then why is   ''zero''   included in the array?   -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 03:17, 19 January 2017 (UTC)
Given that the example list is an ordered list (of positive integers),   then why is   ''zero''   included in the array?   -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 03:17, 19 January 2017 (UTC)

Will either the mention of   ''positive integers''   be amended, or will the list of given numbers be changed   (hopefully before the draft task gets promoted)?

Since everybody has already used the example list   (that contains a non-positive integer, namely zero),   it would probably be easier to change it to:

'' ... Given a sorted array of non-negative integers ...''

  -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 01:17, 23 September 2017 (UTC)

Revision as of 01:18, 23 September 2017

Some ambiguities (inappropriate return type)

What if there is more then one way to get the desired sum? Should it return all of the pairs or only a pair? Are we to assume the integers in the array are unique? --Thundergnat (talk) 22:21, 4 October 2016 (UTC)

What if there is no solution ? E.g. when all numbers in the list are even, and the desired sum is odd. -- Hajo (talk) 13:53, 5 October 2016 (UTC)

One way of putting it is that the proposed return type (list of integers [Int]) is not quite right yet. The structure of the problem would be more clearly expressed by requiring the return of a list of pairs of integers

[(Int, Int)]

i.e. Returning an empty list where no solutions are found, and a list of more than one integer pair where multiple solutions are found.

The English formulation of the task may also need a slight tweak – the phrase "If so, return indices of the two integers" skips a bit heavily over the thin ice – it seems to express an assumption that any solution would necessarily be unique. Hout (talk) 07:55, 17 October 2016 (UTC)

(from the task description) Given a sorted array of positive integers ...

Given that the example list is an ordered list (of positive integers),   then why is   zero   included in the array?   -- Gerard Schildberger (talk) 03:17, 19 January 2017 (UTC)

Will either the mention of   positive integers   be amended, or will the list of given numbers be changed   (hopefully before the draft task gets promoted)?

Since everybody has already used the example list   (that contains a non-positive integer, namely zero),   it would probably be easier to change it to:

  ... Given a sorted array of non-negative integers ...

  -- Gerard Schildberger (talk) 01:17, 23 September 2017 (UTC)