71
4
Intro
The challenge is to create a program/function that prints the intersection of its own source code and a given string input. This is code golf and to be more precise:
- Let
I
be the input set{"a","b","c"}
- Let
S
be the source code set{"b","f"}
- Then the intersection is what they share
I ∩ S = {"b"}
Input
Input is flexible. It should be able to handle the character encoding used for the source code.
Output
Output is flexible. It should be the set of characters that the input and source code share. Also, sets are unordered collections of distinct objects. In summary:
- Output is flexible:
- Could be any data structure (string or otherwise)
- Could unordered
- Could have a trailing
\n
- Should be distinct
Restriction
Similar to quine challenges, the program/function may not read its own source code and 0-byte solutions are not allowed.
Examples
- #1
functor x(I){ return I ∩ self; }
Inputs Outputs
------ -------
enter preformatted text here -> {"e","n","t","r","f","o","x"}
["Albrt"," Einstin"] -> {"l","r","t","n","s"}
- #2
(_)->_&"(_)->&\"\\"
Inputs Outputs
------ -------
"Security at the expense of -> "
usability comes at the expense
of security."
(0____0) -> (_)
- #3
ಠa益длф
Inputs Outputs
------ -------
Far out in the uncharted backwaters ->"a"
of the unfashionable end of the
Western Spiral arm of the Galaxy lies
a small unregarded yellow sun.
Orbiting this at a distance of roughly
ninety-eight million miles is an
utterly insignificant little blue-green
planet whose ape-descended life forms
are so amazingly primitive that they
still think digital watches are a pretty
neat idea.
(ノಠ益ಠ)ノ彡┻━┻ ->"ಠ益"
Test Cases
Albert Einstein
\__( O__O)_/
!@#$%^&*()_+{}|:"<>?
1234567890-=[]\;',./
(ノಠ益ಠ)ノ彡┻━┻
“¤>%,oỊȤʠ“ØụĊ5D³ṃṠɼQ»j;Ç;“;}¶”
┬──┬ ノ( ゜-゜ノ)
Far out in the uncharted backwaters of the unfashionable end of the Western Spiral arm of the Galaxy lies a small unregarded yellow sun. Orbiting this at a distance of roughly ninety-eight million miles is an utterly insignificant little blue-green planet whose ape-descended life forms are so amazingly primitive that they still think digital watches are a pretty neat idea.
Update
- [16-08-10]: sets are unordered collections of distinct objects
- [16-08-10]: trailing newline is acceptable
2May the output contain duplicate characters? – Digital Trauma – 2016-08-10T18:44:09.617
1@DigitalTrauma From examples #1, #2 and #3 it appears not – Luis Mendo – 2016-08-10T18:50:24.020
@DigitalTrauma Sorry for the ambiguity, sets (in the mathematical sense) ignore order and have no repetition. – NonlinearFruit – 2016-08-10T19:05:37.400
Is a trailing newline acceptable when printing the output? – Dennis – 2016-08-10T19:07:53.237
@Dennis Yes, a trailing newline is acceptable. – NonlinearFruit – 2016-08-10T19:18:19.100
23
Congratulations for coming up with a generalised quine where the best solutions are not based on the language's standard quine. :)
– Martin Ender – 2016-08-10T20:27:45.9001If a set should not have repetition, shouldn't the input sets also not contain repetition? Or is the input actually not a set? – user81655 – 2016-08-11T15:37:08.207
@user81655 When I said "Let
I
be the input set" I meant thatI
is the set of the input not that the input is a set – NonlinearFruit – 2016-08-11T19:49:57.590Are sets typically ordered or not? that is, does the order of the output matter? – cat – 2016-08-13T02:20:55.147
@cat Sets are unordered so the order of the output does not matter. – NonlinearFruit – 2016-08-13T02:26:16.377
TBH, the definition of "set" is not ambiguous in any way. – Andrea Lazzarotto – 2016-08-15T00:47:14.557
@Andrea I'm sorry, did you mean the English definition is unambiguous or the mathematical definition? :P – NonlinearFruit – 2016-08-15T02:39:34.820
Are they different? A set is an unordered collection of non repeating elements. The problem defined in the Q was clear before adding the clarification. :) Especially for people who write code which are expected to know the definition of a "set" in any programming language. – Andrea Lazzarotto – 2016-08-15T10:54:35.960
@AndreaLazzarotto The duplicate knives in my 40-piece silverware set beg to differ... – NonlinearFruit – 2016-09-02T21:00:14.703
@NonlinearFruit eheh... That is another kind of set that has nothing to do with math or programming. I guess a Hollywood movie set could beg to differ as well. :) – Andrea Lazzarotto – 2016-09-02T21:14:00.757