2
\$\begingroup\$

Skat

I'm a fan of anagrams, so given two strings s1 and s2 write a program or function that outputs a truthy value if s2 is an anagram of s1, and a falsey value otherwise (not accounting for spaces and capital letters).

For example:

Input: s1 = "Anagram"; s2 = "Nag a ram"

true

Input: s1 = "stack overflow"; s2 = "fewer kool cats"

false

Input: s1 = "apple rocks"; s2 = "paler spock"

true

Rules

  • Program and function allowed.
  • Shortest code in bytes wins.

Duck logo!

\$\endgroup\$
0

4 Answers 4

2
\$\begingroup\$

05AB1E, 8 bytes

lðδKJ€{Ë

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Wow, your answer and mine are literal polar opposites at the same cost; you remove spaces, I add them. Yours is definitely more efficient though. I'm removing mine, this was so much better lol. \$\endgroup\$ Commented Jun 23, 2017 at 16:11
  • \$\begingroup\$ If you sort first you can just remove the trailing newlines and dont have to join afterwards. tl;dr: l€{ðδÛË should also work (1 byte saving yay) \$\endgroup\$
    – Datboi
    Commented Jun 24, 2017 at 22:23
  • \$\begingroup\$ @Datboi Hmm, well, I'll rather answer the original challenge with that. \$\endgroup\$ Commented Jun 25, 2017 at 5:43
0
\$\begingroup\$

Jelly, 8 bytes

ŒlḟṢ¥€⁶E

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Python 3, 74 bytes

def f(a,b):print(g(a)==g(b))
g=lambda a:sorted(a.upper().replace(" ", ""))

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ You can change def f(a,b):print(g(a)==g(b)) for lambda a,b:g(a)==g(b) \$\endgroup\$
    – Cyoce
    Commented Jun 23, 2017 at 16:09
  • \$\begingroup\$ You missed an extra space after .replace()'s comma. \$\endgroup\$
    – manatwork
    Commented Jun 23, 2017 at 16:12
0
\$\begingroup\$

Japt, 13 11 bytes

Takes input as an array.

Ëu ¸¬Ãvá rø

Try it

Ëu ¸¬Ãvá rø     :Implicit input of array
Ë               :Map
 u              :  Uppercase
   ¸            :  Split on spaces
    ¬           :  Join
     Ã          :End map
      v         :Modify first element
       á        :  Permutations
         r      :Reduce by
          ø     :  Contains?
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.