This anecdote contains the following intriguing exchange:
"Fine, Fred," Avi interrupted. "Then how would you change this to avoid duplicate entries?"
"Oh, just change that one there to a negative one."
While this claim is not accurate in context, I do wonder if there's some plausible code for which that makes sense.
Your challenge is to write code (a program, a function, whatever) that fits this criteria:
- Merges two input lists into one, keeping duplicates. [edit: You can optionally assume that they are integers, and/or that the lists themselves are unique. You can't assume the integers are positive (the one answer that does this is grandfathered in).]
- A literal "1" appears somewhere in the code. If you change this to a literal "-1", the code does the same thing but removing duplicates.
- The code does not simply branch off of the 1/-1. We're not looking for
if (1 < 1) removeDuplicates()or
[do_nothing, merge_with_dups, merge_without_dups].call(), for example.
Input and output can be in any reasonable format you choose. One example might be
[1,2],[2,3]->[1,2,2,3] before the sign change, and
This is a popularity contest. It is not code golf, unless you want to show off. I'll accept the highest-voted answer in about two weeks.