Skip to main content
added PHP version hint
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41

#PHP, 138 133 129 bytes

PHP beats Mathematica - a rare occurence.

for(;$s=fgets(STDIN);$s>G?print$$a[$b]?$s<L:$s>L&&@array_intersect_key($$a,$$b):$$a[$b]=$$b[$a]=1)[,$a,$b]=explode(" ",trim($s));

prints 1 for truthy, empty string for falsy. Run with -nr or test it online.
needs PHP 7.1 for the list assignment; user names are case sensitive and should exclude a, b, s.

breakdown

for(;$s=fgets(STDIN);                       # loop through input
    $s>G                                        # 2. evaluate command
        ?print$$a[$b]
            # command KNOW: true if $$a[$b]
            ?$s<L
            # command SUGGEST: true if !$$a[$b] and array_intersect_key returns truthy
            :$s>L&&@array_intersect_key($$a,$$b)
        # command FRIEND: set keys in $$a and $$b
        :$$a[$b]=$$b[$a]=1
)
    [,$a,$b]=explode(" ",trim($s));             # 1. parse user names to $a and $b
  • user names are case sensitive and should exclude a, b and s.
  • $s has to be trimmed because it includes the newline character.
  • array_intersect_key has to be muted or it would yield warnings for empty $$a or $$b.
  • +18 +15 bytes for all user names: Replace $$a with $f[$a] and $$b with $f[$b].

#PHP, 138 133 129 bytes

PHP beats Mathematica - a rare occurence.

for(;$s=fgets(STDIN);$s>G?print$$a[$b]?$s<L:$s>L&&@array_intersect_key($$a,$$b):$$a[$b]=$$b[$a]=1)[,$a,$b]=explode(" ",trim($s));

prints 1 for truthy, empty string for falsy. Run with -nr or test it online.

breakdown

for(;$s=fgets(STDIN);                       # loop through input
    $s>G                                        # 2. evaluate command
        ?print$$a[$b]
            # command KNOW: true if $$a[$b]
            ?$s<L
            # command SUGGEST: true if !$$a[$b] and array_intersect_key returns truthy
            :$s>L&&@array_intersect_key($$a,$$b)
        # command FRIEND: set keys in $$a and $$b
        :$$a[$b]=$$b[$a]=1
)
    [,$a,$b]=explode(" ",trim($s));             # 1. parse user names to $a and $b
  • user names are case sensitive and should exclude a, b and s.
  • $s has to be trimmed because it includes the newline character.
  • array_intersect_key has to be muted or it would yield warnings for empty $$a or $$b.
  • +18 +15 bytes for all user names: Replace $$a with $f[$a] and $$b with $f[$b].

#PHP, 138 133 129 bytes

PHP beats Mathematica - a rare occurence.

for(;$s=fgets(STDIN);$s>G?print$$a[$b]?$s<L:$s>L&&@array_intersect_key($$a,$$b):$$a[$b]=$$b[$a]=1)[,$a,$b]=explode(" ",trim($s));

prints 1 for truthy, empty string for falsy. Run with -nr or test it online.
needs PHP 7.1 for the list assignment; user names are case sensitive and should exclude a, b, s.

breakdown

for(;$s=fgets(STDIN);                       # loop through input
    $s>G                                        # 2. evaluate command
        ?print$$a[$b]
            # command KNOW: true if $$a[$b]
            ?$s<L
            # command SUGGEST: true if !$$a[$b] and array_intersect_key returns truthy
            :$s>L&&@array_intersect_key($$a,$$b)
        # command FRIEND: set keys in $$a and $$b
        :$$a[$b]=$$b[$a]=1
)
    [,$a,$b]=explode(" ",trim($s));             # 1. parse user names to $a and $b
  • $s has to be trimmed because it includes the newline character.
  • array_intersect_key has to be muted or it would yield warnings for empty $$a or $$b.
  • +18 +15 bytes for all user names: Replace $$a with $f[$a] and $$b with $f[$b].
reordered print conditions (-4 bytes)
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41

#PHP, 138 133 133129 bytes

PHP beats Mathematica - a rare occurence.

for(;$s=fgets(STDIN);$s>G?print$s>L?!$$a[$b]&&@array_intersect_key($$print$$a[$b]?$s<L:$s>L&&@array_intersect_key($$a,$$b):$$a[$b]:$$a[$b]=$$b[$a]=1a[$b]=$$b[$a]=1)[,$a,$b]=explode(" ",trim($s));

prints 1 for truthy, empty string for falsy. Run with -nr or test it onlinetest it online.

breakdown

for(;$s=fgets(STDIN);                       # loop through input
    $s>G                                        # 2. evaluate command
        ?print$s>Lprint$$a[$b]
            # command KNOW: true if $$a[$b]
            ?!$$a[$b]&&@array_intersect_key($$a,$$b)    # command SUGGEST
            :$$a[$b]                        $s<L
            # command KNOW
        SUGGEST:$$a[$b]=$$b[$a]=1                        true if #!$$a[$b] and array_intersect_key returns truthy
            :$s>L&&@array_intersect_key($$a,$$b)
        # command FRIEND: set keys in $$a commandand FRIEND$$b
        :$$a[$b]=$$b[$a]=1
)
    [,$a,$b]=explode(" ",trim($s));             # 1. parse user names to $a and $b
  • user names are case sensitive and should exclude a, b and s.
  • $s has to be trimmed because it includes the newline character.
  • array_intersect_key has to be muted or it would yield warnings for empty $$a or $$b.
  • +18+18 +15 bytes for all user names: Replace $$a with $f[$a] and $$b with $f[$b].

#PHP, 138 133 bytes

PHP beats Mathematica - a rare occurence.

for(;$s=fgets(STDIN);$s>G?print$s>L?!$$a[$b]&&@array_intersect_key($$a,$$b):$$a[$b]:$$a[$b]=$$b[$a]=1)[,$a,$b]=explode(" ",trim($s));

prints 1 for truthy, empty string for falsy. Run with -nr or test it online.

breakdown

for(;$s=fgets(STDIN);                       # loop through input
    $s>G                                        # 2. evaluate command
        ?print$s>L
            ?!$$a[$b]&&@array_intersect_key($$a,$$b)    # command SUGGEST
            :$$a[$b]                                    # command KNOW
        :$$a[$b]=$$b[$a]=1                          # command FRIEND
)
    [,$a,$b]=explode(" ",trim($s));             # 1. parse user names to $a and $b
  • user names are case sensitive and should exclude a, b and s.
  • $s has to be trimmed because it includes the newline character.
  • array_intersect_key has to be muted or it would yield warnings for empty $$a or $$b.
  • +18 bytes for all user names: Replace $$a with $f[$a] and $$b with $f[$b].

#PHP, 138 133 129 bytes

PHP beats Mathematica - a rare occurence.

for(;$s=fgets(STDIN);$s>G?print$$a[$b]?$s<L:$s>L&&@array_intersect_key($$a,$$b):$$a[$b]=$$b[$a]=1)[,$a,$b]=explode(" ",trim($s));

prints 1 for truthy, empty string for falsy. Run with -nr or test it online.

breakdown

for(;$s=fgets(STDIN);                       # loop through input
    $s>G                                        # 2. evaluate command
        ?print$$a[$b]
            # command KNOW: true if $$a[$b]
            ?$s<L
            # command SUGGEST: true if !$$a[$b] and array_intersect_key returns truthy
            :$s>L&&@array_intersect_key($$a,$$b)
        # command FRIEND: set keys in $$a and $$b
        :$$a[$b]=$$b[$a]=1
)
    [,$a,$b]=explode(" ",trim($s));             # 1. parse user names to $a and $b
  • user names are case sensitive and should exclude a, b and s.
  • $s has to be trimmed because it includes the newline character.
  • array_intersect_key has to be muted or it would yield warnings for empty $$a or $$b.
  • +18 +15 bytes for all user names: Replace $$a with $f[$a] and $$b with $f[$b].
improved description
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41

#PHP, 138 133 bytes

PHP beats Mathematica - a rare occurence.

for(;$s=fgets(STDIN);$s>G?print$s>L?!$$a[$b]&&@array_intersect_key($$a,$$b):$$a[$b]:$$a[$b]=$$b[$a]=1)[,$a,$b]=explode(" ",trim($s));

prints 1 for truthy, empty string for falsy. Run with -nr or test it online.
user names should exclude a, b and s.

breakdown

for(;$s=fgets(STDIN);                       # loop through input
    $s>G                                        # 2. evaluate command
        ?print$s>L
            ?!$$a[$b]&&@array_intersect_key($$a,$$b)    # command SUGGEST
            :$$a[$b]                                    # command KNOW
        :$$a[$b]=$$b[$a]=1                          # command FRIEND
)
    [,$a,$b]=explode(" ",trim($s));             # 1. parse user names to $a and $b

+18 bytes for all user names: Replace $$a with $f[$a] and $$b with $f[$b].

  • user names are case sensitive and should exclude a, b and s.
  • $s has to be trimmed because it includes the newline character.
  • array_intersect_keyarray_intersect_key has to be muted or it would yield warnings for empty $$a or $$b.
  • +18 bytes for all user names: Replace $$a with $f[$a] and $$b with $f[$b].

#PHP, 138 133 bytes

PHP beats Mathematica - a rare occurence.

for(;$s=fgets(STDIN);$s>G?print$s>L?!$$a[$b]&&@array_intersect_key($$a,$$b):$$a[$b]:$$a[$b]=$$b[$a]=1)[,$a,$b]=explode(" ",trim($s));

prints 1 for truthy, empty string for falsy. Run with -nr or test it online.
user names should exclude a, b and s.

breakdown

for(;$s=fgets(STDIN);                       # loop through input
    $s>G                                        # 2. evaluate command
        ?print$s>L
            ?!$$a[$b]&&@array_intersect_key($$a,$$b)    # command SUGGEST
            :$$a[$b]                                    # command KNOW
        :$$a[$b]=$$b[$a]=1                          # command FRIEND
)
    [,$a,$b]=explode(" ",trim($s));             # 1. parse user names to $a and $b

+18 bytes for all user names: Replace $$a with $f[$a] and $$b with $f[$b].

  • $s has to be trimmed because it includes the newline character
  • array_intersect_key has to be muted or it would yield warnings for empty $$a or $$b.

#PHP, 138 133 bytes

PHP beats Mathematica - a rare occurence.

for(;$s=fgets(STDIN);$s>G?print$s>L?!$$a[$b]&&@array_intersect_key($$a,$$b):$$a[$b]:$$a[$b]=$$b[$a]=1)[,$a,$b]=explode(" ",trim($s));

prints 1 for truthy, empty string for falsy. Run with -nr or test it online.

breakdown

for(;$s=fgets(STDIN);                       # loop through input
    $s>G                                        # 2. evaluate command
        ?print$s>L
            ?!$$a[$b]&&@array_intersect_key($$a,$$b)    # command SUGGEST
            :$$a[$b]                                    # command KNOW
        :$$a[$b]=$$b[$a]=1                          # command FRIEND
)
    [,$a,$b]=explode(" ",trim($s));             # 1. parse user names to $a and $b
  • user names are case sensitive and should exclude a, b and s.
  • $s has to be trimmed because it includes the newline character.
  • array_intersect_key has to be muted or it would yield warnings for empty $$a or $$b.
  • +18 bytes for all user names: Replace $$a with $f[$a] and $$b with $f[$b].
use $s instead of $c (-2 bytes), split parsing from ternary (+0), for instead of while (-3)
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41
Loading
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41
Loading