# Input ∩ Source Code

## 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 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.

(ノಠ益ಠ)ノ彡┻━┻                      ->"ಠ益"

Albert Einstein

\__( O__O)_/

## ListSharp, 222 bytes

ROWS T=ROWSPLIT S BY [""]
ROWS R=ROWSPLIT "STRG =EAD[<her>+\".tx]OWPLIBYCFMHVNc#isn()oay\r\n" BY [""]
ROWS R=SELECT FROM T WHERE[EVERY STRG IS ANY STRG IN R]
SHOW=<c#R.Distinct().ToArray()c#>

ridiculous but im entertained

## sed, 47 characters

:s;st[^])(*\1.s2t:[;^]tt;st$$.$$$$.*\1$$t\2t;ts

I'm a little disappointed at how long this came out to be, especially the bit to remove repeated characters.

• Which version of sed is this? GNU sed says sed: -e expression #1, char 47: unterminated `s' command. – Dennis Aug 12 '16 at 3:03
• 43 bytes including 1 for -r: sed -r ':;ss[^][str().*\12;:^]ss;ss(.)(.*\1)s\2s;t' i wrote it before noticing yours and it turned out to be very similar – izabera Aug 12 '16 at 7:23
• @Dennis fixed; turned out having a : after the [ caused it to try and parse a character class – Geoff Reedy Aug 12 '16 at 13:04
• @izabera nice, I'm quite surprised that the : command doesn't actually need a label and that it changes the meaning of t without a label – Geoff Reedy Aug 12 '16 at 13:07
• yeah it's a gnuism – izabera Aug 12 '16 at 13:25

## Java 8 lambda, 152142 140 characters

Quite short:

s->s.chars().mapToObj(i->(char)i).filter(c->"COSTab\"\\cefh(i)j+l-mn.oprstuv>".contains(""+c)).collect(java.util.stream.Collectors.toSet())

Or ungolfed over here:

public class Q89400 {

static Set<Character> inAndQuine(String in) {
return in.chars()
.mapToObj(i->(char)i)
.filter(c->"COSTab\"\\cefh(i)j+l-mn.oprstuv>".contains(""+c))
.collect(java.util.stream.Collectors.toSet());

}
}

Of course the ungolfed solution is wrong, as it doesn't match the curly brackets and some more characters, it's just their for the sake of completeness.

The function takes input as a String and returns a java.util.Set<Character> containing the characters which are present in both input and source.

It turned out that the solution wasn't working. I thought String#contains tests for a regex match but it is just a literal matching. I added some escaping to quote the characters like . but this wasn't necessary but ruined everything instead. Now without this escaping we save some characters and now it actually works :)

Thanks to @NonlinearFruit for reminding me of using one-character variables.

• Rename in to be a single letter like a – NonlinearFruit Aug 12 '16 at 12:16
• @NonlinearFruit you're right :O how could I forget about that?! – Frozn Aug 12 '16 at 13:13

# SQF, 7169 64 bytes

Using the file-as-a-function format:

i="-_h ;""=()sSplitrng"splitString"";i-(i-(_this splitString""))

Call as "STRING" call NAME_OF_COMPILED_FUNCTION