Manage Trash So

35

2

It's become somewhat of a tradition in PPCG that some users temporarily change their names by an anagram (a new name formed by reordering the letters of the old).

Sometimes it gets difficult to find out who is who. I could use a program or function to tell if two phrases are anagrams of each other.

The challenge

The program or function should take two strings and produce a truthy result if they are anagrams of each other, and falsy otherwise.

Rules

  • Input will only contain letters (ASCII 65 to 90 and 97 to 122), digits (ASCII 48 to 57) or space (ASCII 32).
  • The anagram relation is independendent of case. So "Arm" and "RAM" are anagrams.
  • Spaces don't count either. So "keyboard" and "Barked Yo" are anagrams
  • All builtins allowed
  • Input format is flexible (two strings, an array of two strings, a string containing both phrases with a suitable separator ...)

Code golf. Fewest bytes wins.

Test cases

Truthy:

Lynn, Nyl N
Digital Trauma, Tau Digital Arm
Sp3000, P S 3000
Manage Trash So, Those anagrams

Falsy

Calvins Hobbies, Helka Homba
Android, rains odd
In between days, bayed entwine
Code golf, cod elf got

Luis Mendo

Posted 2016-02-25T16:08:54.523

Reputation: 87 464

8Related but different (only letters, no case, no spaces) – Luis Mendo – 2016-02-25T16:09:03.620

4This question's title is *very* perplexing to someone who's not had enough coffee. +1 :D – cat – 2016-02-25T17:36:07.450

1@DonMuesli I would argue that this is still a dupe. The slight changes are very trivial. – Mego – 2016-02-25T17:59:23.753

15Manage Trash So, Those anagrams. Nice. – mbomb007 – 2016-02-25T20:13:04.277

3So, the anagrams... – Leaky Nun – 2016-05-21T17:23:57.237

Scour A Gnomic Put is essentially my only choice ._. – Magic Octopus Urn – 2017-06-23T16:34:36.807

Wait no! Racing Scoot Um Up is so much better. – Magic Octopus Urn – 2017-06-23T16:37:07.313

Answers

13

05AB1E, 9 8 bytes

Code:

lvyð-{}Q

Explanation:

l         # Lowercase the strings
 vy   }   # Map over the list, for each...
   ð-     #   remove spaces
     {    #   and sort
       Q  # Check equality

Try it online!

Adnan

Posted 2016-02-25T16:08:54.523

Reputation: 41 965

... but 2 bytes less! Well done! – Luis Mendo – 2016-02-25T16:28:14.370

It's lvyðK{}Q now. – Magic Octopus Urn – 2017-06-23T16:38:55.490

15

Retina, 25

i+`(\w)(.*,.*)\1
$2
^\W*$

Try it Online! Additionally, you can run a modified multi-line version.

Delete letters from before the comma along with their matches after the comma. If we have no letters left then it was an anagram.

FryAmTheEggman

Posted 2016-02-25T16:08:54.523

Reputation: 16 206

For Retina, if a positive number could be considered a failure, and zero be considered success, this could be three bytes shorter by using \w as the last stage. – FryAmTheEggman – 2016-02-25T20:20:13.687

@dev-null "Input will only contain letters (ASCII 65 to 90 and 97 to 122), digits (ASCII 48 to 57) or space (ASCII 32)" – FryAmTheEggman – 2016-02-26T02:36:11.937

11

Pyth, 11 10 bytes

Thanks to @FryAmTheEggman for teaching me the power of ;!

qFmSr-d;0Q

Try it here!

Takes a list of two strings as input.

Explanation

qFmSr-d;0Q    # Q = input

  m      Q    # map Q with d as lambda variable
     -d;      # filter spaces out of the string
    r   0     # convert to lowercase
   S          # sort all characters in string
qF            # Unfold resulting list and check for equality

Denker

Posted 2016-02-25T16:08:54.523

Reputation: 6 639

10

Python 2, 63 61 bytes

lambda*l:len({`sorted(s.lower())`[2::5].strip()for s in l})<2

An anonymous function that, in fact, takes n arguments and determines if all n of them are mutual palindromes! f("Lynn", "Nyl N") returns True.

This set comprehension trick is by xnor. It saved two bytes, but the old approach looked very neat:

exec"a=`sorted(input().lower())`[2::5].strip();a"*2;print a==aa

Lynn

Posted 2016-02-25T16:08:54.523

Reputation: 55 648

\sorted(input().lower())`.strip(" [',")` is the same length :/ – Sp3000 – 2016-02-25T16:43:14.117

The exec thing is clever but seems too complex. You can do better with lambda*l:len({`sorted(s.lower())`[2::5].strip()for s in l})<2. – xnor – 2016-02-25T16:45:36.333

2Thanks! I'm a bit disappointed – it looked very cool. Keeping it in the post anyway. – Lynn – 2016-02-25T16:50:08.613

7

Jelly, 12 bytes

ḟ€⁶O&95Ṣ€QLḂ

Try it online!

How it works

ḟ€⁶O&95Ṣ€QLḂ  Main link. Input: A (list of strings)

  ⁶           Yield ' '.
ḟ€            Filter it from each string.
   O          Apply ordinal to all characters.
    &95       Take bitwise AND with 95 to make the ordinals case-insensitive.
       Ṣ€     Sort each list of ordinals.
         Q    Deduplicate the list.
          L   Get the length.
           Ḃ  Compute the length's parity (1 -> 1, 2 -> 0).

Alternate version, non-competing (9 bytes)

Jelly's uppercase atom had a bug, and Jelly still had no built-in to test lists for equality...

ḟ⁶ŒuṢµ€⁼/

Try it online!

How it works

ḟ⁶ŒuṢµ€⁼/     Main link. Input: A (list of strings)

     µ€       Map the chain to the left over A.
 ⁶            Yield ' '.
ḟ             Filter it from the string.
  Œu          Cast to uppercase.
    Ṣ         Sort.
       ⁼/     Reduce by equality.

Dennis

Posted 2016-02-25T16:08:54.523

Reputation: 196 637

6

MATL, 11 bytes

2:"jkXvS]X=

EDIT (May 20, 2016) The code in the link uses Xz instead of Xv, owing to recent changes in the language.

Try it online!

2:"     ]       % do this twice
   j            % read input line as a string
    k           % convert to lowercase
     Xv         % remove spaces
       S        % sort
         X=     % are they equal?

Luis Mendo

Posted 2016-02-25T16:08:54.523

Reputation: 87 464

3Did you just change your name for that challenge? – Denker – 2016-02-25T16:34:19.053

3@DenkerAffe I had been thinking about it for some time. I just made it coincide with the challenge :-) – Luis Mendo – 2016-02-25T16:36:16.993

1Don Muesli lol. So you are the Lord of Muesli Luis!? Is this how you keep your healthy complexion? – rayryeng - Reinstate Monica – 2016-02-25T21:00:47.260

@rayryeng Heyyy! Good to see you here, Ray! Get back to golfing! – Luis Mendo – 2016-02-25T21:22:08.747

I promise I will :) once this course ends... I see you are learning CJam now too. Very nice! – rayryeng - Reinstate Monica – 2016-02-25T21:32:41.510

@rayryeng It's a nice language, and much easier than it seems :-) – Luis Mendo – 2016-02-25T21:52:06.883

6

Javascript, 69 61 60 59 bytes

1 byte off thanks @ӍѲꝆΛҐӍΛПҒЦꝆ. 1 byte off with currying (pointed out by @apsillers)

n=>m=>(G=s=>[]+s.toLowerCase().split(/ */).sort())(n)==G(m)

f=n=>m=>
    (G=s=>[]+s.toLowerCase()
        .split(/ */)
        .sort()
    )(n)==G(m)

F=(n,m)=>document.body.innerHTML+=`<pre>f('${n}')('${m}') -> ${f(n)(m)}</pre>`

F('Luis Mendo','Don Muesli')
F('Calvins Hobbies','Helka Homba')
F('Android','rains odd')
F('In between days','bayed entwine')
F('Code golf','cod elf got')
F('Lynn','Nyl N')
F('Digital Trauma','Tau Digital Arm')
F('Sp3000','P S 3000')
F('Manage Trash So','Those anagrams')

removed

Posted 2016-02-25T16:08:54.523

Reputation: 2 785

2Very nice, filtering out spaces and converting to an array at the same time! – Neil – 2016-02-25T17:06:54.363

2

Very nice. You can save one byte using currying, which the community has decided is an acceptable form of arguments: n=>m=>...

– apsillers – 2016-02-25T17:23:19.000

Try n=>m=>(G=s=>[]+s.toLowerCase().split(/\S/).sort())(n)==G(m). Using split instead of match should save you a byte. – Mama Fun Roll – 2016-02-26T03:42:05.287

@ӍѲꝆΛҐӍΛПҒЦꝆ. No, because suppose s='db cz'... Now s.match(/\S/g).sort() results in ['b','c','d','z']... and s.split(/\s/).sort() results in ['cz','db']

– removed – 2016-02-26T12:59:45.280

@ӍѲꝆΛҐӍΛПҒЦꝆ. But... looking into your idea, I changed it a bit and saved one byte... thanks! – removed – 2016-02-26T13:05:23.903

6

CJam, 11 12 14 bytes

3 2 bytes removed thanks to @FryAmTheEggman

{lelS-$}2*=

Try it online!

{      }2*       e# do this twice
 l               e# read line as a string
  el             e# make lowercase
    S-           e# remove spaces from string
      $          e# sort
          =      e# compare strings

Luis Mendo

Posted 2016-02-25T16:08:54.523

Reputation: 87 464

@FryAmTheEggman Thank you! – Luis Mendo – 2016-02-25T16:56:49.867

@FryAmTheEggman Thanks again! I still have much to learn about CJam :-) – Luis Mendo – 2016-02-25T16:59:39.943

3Your code is secretly laughing. lel. – Cyoce – 2016-02-27T21:12:08.297

Or is it a one? lel ==> 1e1 No one knows. It is a mystery. – user48538 – 2016-03-02T12:23:37.700

4

Seriously, 11 9 bytes

2`,ùSô`n=

Try It Online!

Everyone seems to be using the same algorithm. Here it is yet again.

2`    `n          Do it twice
  ,               Read a string
   ù              Make it lowercase
    S             Sort
     ô            Strip spaces.
        =         Check equality.

Edit: realized sorting does work correctly on strings, and sorts spaces to the front so strip() will work.

quintopia

Posted 2016-02-25T16:08:54.523

Reputation: 3 899

4

C, 165 bytes

#define d(x) int x(char*a,char*b){
d(q)return*a&224-*b&224;}
#define n(x) for(qsort(x,strlen(x),1,(__compar_fn_t)q);*x<33;x++);
d(s)n(a)n(b)return strcasecmp(a,b);}

Readable and in working context,

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

// start of comparison
int q(char *a, char *b){
     return ((*a)&0xdf)-((*b)&0xdf); // case-insensitive
}
int s(char *a, char *b){
    for(qsort(a,strlen(a),1,(__compar_fn_t)q); *a<33; a++) /**/;
    for(qsort(b,strlen(b),1,(__compar_fn_t)q); *b<33; b++) /**/;
    return strcasecmp(a,b);
}
// end of comparison

int main(int i, char **v){
    printf("'%s' '%s'", v[1], v[2]);
    printf("=> %d\n", s(v[1], v[2])); // 0 if equalish
    return 0;
}

tucuxi

Posted 2016-02-25T16:08:54.523

Reputation: 583

3

Baloch Gyr, 9 bytes

{ṇ₁cḷ}ᵐpᵈ

Try it online!

Truthy/falsy output is achieved through predicate success/failure, this being Brachylog.

Previously saved a byte using cṇ₁cḷḍ instead of {ṇ₁cḷ}ᵐ under the assumption that the two input strings would be the same length minus whitespace, but I realized that it would succeed where it should fail on Ah Hass, haha.

{    }ᵐ      For both strings in the input,
 ṇ₁          split on spaces,
   c         concatenate,
    ḷ        and lowercase.
       pᵈ    The strings are permutations of each other.

Unrelated String

Posted 2016-02-25T16:08:54.523

Reputation: 5 300

3

zsh, 85 bytes

[ $(for x in $@;{tr -d \ <<<$x|tr A-Z a-z|fold -1|sort|paste -sd x}|uniq|wc -l) = 1 ]

Input as command line arguments, output as return code.

The for syntax makes this Bash-incompatible.

[               # test...
$(for x in $@;  # map over arguments
{tr -d \ <<<$x  # remove spaces
|tr A-Z a-z     # lowercase
|fold -1        # put each character on its own line
|sort           # sort lines
|paste -sd x    # remove all newlines except last
}|uniq          # take only unique lines
|wc -l          # how many lines remain?
) = 1 ]         # if only 1 line left, it must have been an anagram

Doorknob

Posted 2016-02-25T16:08:54.523

Reputation: 68 138

3

Japt, 12 bytes

N®v ¬n ¬xÃä¥

Test it online!

How it works

        // Implicit: N = array of input strings
N®    Ã // Take N, and map each item Z to:
v ¬n    //  Take Z.toLowerCase(), split into chars, and sort.
¬x      //  Join and trim off whitespace.
ä¥      // Reduce each pair of items (that's exactly one pair) X and Y to X == Y.

ETHbot

Posted 2016-02-25T16:08:54.523

Reputation: 111

3

GNU Sed, 33

Score includes +2 for -rn options to sed.

This is almost a direct port of @FryAmTheEggman's Retina answer:

:
s/(\w)(.*,.*)\1/\2/i
t
/\w/Q1

Ideone.

Digital Trauma

Posted 2016-02-25T16:08:54.523

Reputation: 64 644

3

Perl, 34 33 + 1 = 34 bytes

s/(.)(.*,.*)\1/$2/i?redo:say!/\w/

Requires the -n flag and the free -M5.010|-E:

$ perl -M5.010 -ne's/(.)(.*,.*)\1/$2/i?redo:say!/\w/' <<< 'hello, lloeh'
1

How it works:

                                   # '-n' make a implicit while loop around the code
 s/(.)(.*,.*)\1/$2/i               # Remove a letter that occurs on both sides of the comma.
                    ?
                     redo:         # Redo is a glorified goto statement that goes to the top of the while loop
                          say!/\w/ # Check to see if any letter is left

Thanks to msh210 for suggesting using ternary operators to save one byte

andlrc

Posted 2016-02-25T16:08:54.523

Reputation: 1 613

2

Japt, 10 bytes

v á øVrS v

Try it

Shaggy

Posted 2016-02-25T16:08:54.523

Reputation: 24 623

2

PHP, 109 94 bytes

function f($x){return str_split((trim($x));}function g($x,$y){return array_diff(f($x),f($y));}

Blech, the two function/returns are killing me here.

Returns the difference between two string inputs as an array of characters. PHP considers [] falsy, satisfying the return requirements.

ricdesi

Posted 2016-02-25T16:08:54.523

Reputation: 499

3function($x,$y){$S=str_split;return array_diff($S(trim($x)),$S(trim($y)));} --> 75 bytes. Creates an anonymous function that returns the result. I've removed that long function and replaced the calls to str_split with an assignmed variable, to shorten it up. – Ismael Miguel – 2016-02-25T16:52:11.647

Nice. I was tweaking it to reduce it to the one function, this is two steps ahead of that, well done. – ricdesi – 2016-02-25T16:56:40.077

2

Bash + GNU utilities, 51

f()(fold -1<<<${@^^}|sort)
f $1|diff -qBw - <(f $2)
  • Define a function f() which:
    • ${@^^} converts all parameters to upper case
    • fold -1 splits chars - one per line
    • sorts lines
  • call diff with -q to suppress full diff output and -Bw to ignore whitespace changes

Digital Trauma

Posted 2016-02-25T16:08:54.523

Reputation: 64 644

2

Pyke (commit 30, noncompetitive), 9 bytes

Fl1dk:S)q

Explanation:

F      )  -  for _ in eval_or_not(input())
 l1       -     ^.lower()
   dk:    -    ^.replace(" ", "")
      S   -   sorted(^)
        q - ^==^

Blue

Posted 2016-02-25T16:08:54.523

Reputation: 26 661

2

Mathematica, 77 76 bytes

StringMatchQ[##,IgnoreCase->1>0]&@@(""<>Sort[Characters@#/." "->""]&/@{##})&

The first part is actually one of my answers to another question!

CalculatorFeline

Posted 2016-02-25T16:08:54.523

Reputation: 2 608

2

Pike, 54 112 109 109 96 bytes

#define a(x) sort((array)replace(lower_case(x)," ",""))
int s(mixed i){return a(i[0])==a(i[1]);}

mixed happens to be shorter than array(string).

s returns 1 if its arguments are anagrams.

cat

Posted 2016-02-25T16:08:54.523

Reputation: 4 989

2

Q, 25 Bytes

f:{~/{x@<x:x@&~^x:_x}'x}

NOTE.- counting include function name f: to facilitate tests (as lambda we can decrement 2 Bytes)

Readable version

match over {ascending not null lower x} each x

{.. x ..} is an anonymous function with arg x
_x        lowers string x
&~^x      where not null x (space is considered null)
x@..      selects elements of x according to indexes .. 
<x        ascending indexes of x (not values). Ex <"cab" is 1 2 0
x@<x      ascending values of x (x at ascending indexes of x)
~         match (diad function). Ex "one"~"one" is true
f'..      applies function f for each argument ..
f/..      applies function f over elements of sequence (fold)

Test

f("Lynn";"Nyl N")                       
f("Digital Trauma";"Tau Digital Arm")   
f("Sp3000";"P S 3000")                  
f("Manage Trash So";"Those anagrams")   
f("Calvins Hobbies";"Helka Homba")      
f("Android";"rains odd")                
f("In between days";"bayed entwine")    
f("Code golf";"cod elf got")    

generates (1b = true, 0b = false)

1b
1b
1b
1b
0b
0b
0b
0b

About Q

General-purpose language (APL derivative, specialized in data processing) developed by kx.com. Free full functional evaluation version for Windows/Linux/MacOS.

J. Sendra

Posted 2016-02-25T16:08:54.523

Reputation: 396

What do you mean, other languages are not serious? :-P – Luis Mendo – 2016-05-21T08:59:37.047

If the f is required for the code to evaluate properly, then it must be counted. Otherwise, just leave it off of your submission code, and only use it in examples to show how to assign the function. – Mego – 2016-05-21T09:28:36.107

Of course, other languages are as serious as Q. I beg my poor english. But some languages sacrifices readability or are equiped with libraries ad-hoc for this type of contests. Q is a 'general purpose language', in spite of the fact that code is not very readable. – J. Sendra – 2016-05-21T16:59:52.663

You only need to assign x once if you lower later, thus k)~/{x@<x:_x@&~^x}' for 17 bytes.. but I'd say it's 19 as you need the k) bracket as this is K code rather than Q... – streetster – 2017-09-27T14:15:25.923

2

APL, 31 chars

{≡/{x[⍋x←('.'⎕R'\u0')⍵~' ']}¨⍵}

To be used so:

    {≡/{x[⍋x←('.'⎕R'\u0')⍵~' ']}¨⍵}'Sp3000' 'P S 3000' 
1

In English:

  • { ... }¨⍵: for each of the two elements of the argument
  • x←('.'⎕R'\u0')⍵~' ': transform to uppercase (using a regex...) the string without the spaces and assign the temporary result to x
  • x[⍋x]: sort x
  • ≡/: compare the two results of the sorting: if they match, return 1.

lstefano

Posted 2016-02-25T16:08:54.523

Reputation: 850

Is it possible to try it online? I tried with this but I don't really know how to use it

– Luis Mendo – 2016-06-28T11:49:17.290

Sure. Here: definition after which you can just type f 'first avatar' 'second avatar'

– lstefano – 2016-06-28T12:56:55.317

Thanks! Maybe add that to the answer? So that people can try – Luis Mendo – 2016-06-28T13:28:55.190

–9: ≡/{x[⍋x←0~⍨32|⎕UCS⍵]}¨ – Adám – 2016-06-28T15:27:44.717

@Adám: that won't work because ≡/{x[⍋x←0~⍨32|⎕UCS⍵]}¨'pp' '00' gives 1. – lstefano – 2016-06-29T08:52:50.077

Ah, you're right, I forgot about digits. Sorry. – Adám – 2016-06-29T10:17:07.170

Too bad... it was brilliant! – lstefano – 2016-06-29T10:44:04.207

2

Java, 218 Bytes

First time I've ever written Java...

Golfed:

import java.util.Arrays;boolean M(String a,String b){char[]A=a.toUpperCase().replace(" ","").toCharArray();char[]B=b.toUpperCase().replace(" ","").toCharArray();Arrays.sort(A);Arrays.sort(B);return Arrays.equals(A,B);}

Ungolfed:

import java.util.Arrays;
public class ManageTrashSo {
    public boolean M(String a, String b) {
    char[] A = a.toUpperCase().replace(" ", "").toCharArray();
    char[] B = b.toUpperCase().replace(" ", "").toCharArray();
    Arrays.sort(A);
    Arrays.sort(B);
    return Arrays.equals(A, B);
   }
}

Testing:

    ManageTrashSo manageTrashSo = new ManageTrashSo();

    //True
    System.out.println(manageTrashSo.M("Lynn", "Nyl N"));
    System.out.println(manageTrashSo.M("Digital Trauma", "Tau Digital Arm"));

    //False
    System.out.println(manageTrashSo.M("Android", "rains odd"));
    System.out.println(manageTrashSo.M("In between days", "bayed entwine"));

Pete Arden

Posted 2016-02-25T16:08:54.523

Reputation: 1 151

I know it's been almost a year, but you can golf it by 32 bytes like this: boolean f(String...a){java.util.Arrays x=null;String[]A=g(a[0]),B=g(a[1]);x.sort(A);x.sort(B);return x.equals(A,B);}String[]g(String a){return a.replace(" ","").toUpperCase().split("");} (186 bytes) Or if you convert it to a Java 8 lambda, it can be: a->b->{java.util.Arrays x=null;String[]A=g(a),B=g(b);x.sort(A);x.sort(B);return x.equals(A,B);};String[]g(String a){return a.replace(" ","").toUpperCase().split("");} (167 bytes). Here is a TIO with test code.

– Kevin Cruijssen – 2017-09-27T11:48:43.387

1

PHP, 89 bytes

for(;$i++<2;)$r[]=count_chars(join(explode(" ",strtolower($argv[$i]))));echo$r[0]==$r[1];

Try it online!

PHP, 94 bytes

for(;$i++<2;sort($x),$r[]=trim(join($x)))$x=str_split(strtolower($argv[$i]));echo$r[0]==$r[1];

Try it online!

Jörg Hülsermann

Posted 2016-02-25T16:08:54.523

Reputation: 13 026

1

Excel VBA, 122 Bytes

Anonymous VBE immediate window Function that takes input from range [A1:B1] and outputs to the VBE immediate window

a=Replace([A1]," ",""):b=Replace([B1]," ",""):For i=1To Len(a):b=Replace(b,Mid(a,i,1),"|",,1,1):Next:?b=String(len(a),"|")

Taylor Scott

Posted 2016-02-25T16:08:54.523

Reputation: 6 709

1

Ruby, 50 bytes

def f;gets.upcase.chars.sort.join.strip;end
p f==f

Writing f=->{...} and f[]==f[] is just as long. :(

Lynn

Posted 2016-02-25T16:08:54.523

Reputation: 55 648

1

PowerShell, 81 bytes

param([char[]]$a,[char[]]$b)-join($a-replace' '|sort)-eq-join($b-replace' '|sort)

A slight rewrite of my answer on the linked Anagram challenge.

Takes input as char-arrays, performs a -replace operation to remove spaces, sorts them (which sorts alphabetically, not by ASCII value), then -joins them back into a string. The -eq in PowerShell is by default case-insensitive, but here it must be performed on strings, as [char]'a' is not equal to [char]'A', hence the reason for -join.

AdmBorkBork

Posted 2016-02-25T16:08:54.523

Reputation: 41 581

1

Perl, 35 bytes

Include +1 for -p

Somewhat abusive since it depends on the program being given on the commandline.

perl -pe'<>=~s%\S%*_=s/$&//i?_:0%reg;$_=!//'

Then give the strings as 2 consecutive lines on STDIN

A very abusive solution is 30 bytes:

perl -ne'<>=~s%\w%1/!s/$&//i%reg;1/!//'

This crashes if the strings are not anagrams and therefore gives a false exit code from the point of view of the shell. It also gives garbage on STDERR for that case. If the strings are anagrams the program is silent and gives a "true" exit code

Ton Hospel

Posted 2016-02-25T16:08:54.523

Reputation: 14 114

0

D, 99 107 103 102 99 131 116 117 bytes

Edit: forgot about Dre case insensitivity imports lambdas

I don't like this language :D

import std.string,std.algorithm;(string[]a)=>sort(split(strip(a[0].toLower),""))==sort(split(strip(a[1].toLower),""))

To use it, assign it:

import std.string,std.algorithm;

void main () {
    auto x = (string[]a) => sort(split(strip(a[0].toLower),"")) == sort(split(strip(a[1].toLower),""))
}

cat

Posted 2016-02-25T16:08:54.523

Reputation: 4 989

1Did you forget a ) at the end of your lambda? – Zacharý – 2016-11-08T20:55:43.197

1Can strip(a[0].toLower) be replaced by a[0].toLower.strip, likewise with a[1]? – Zacharý – 2016-11-08T21:03:54.937

@ZacharyT Probably, yes – cat – 2016-11-08T21:37:14.767

0

C#, 378 bytes

I need a handicap!!

https://dotnetfiddle.net/FNDt0E

using System;
using System.Linq;
using System.Text;

public class Program
{

    public static void Main()
    {
        var l = "Hello World";

        var r = "Red Who Loll";

        var y = new Func<string,string>(s => new String(s.ToLower().Replace(" ","").OrderBy(v => v).ToArray()));
        var z = new Func<string,string,Func<string,string>,bool>((w,x,f) => f(w) == f(x));
        var o = z(l, r, y);


        Console.WriteLine("{0} & {1} are anagram: {2}",l, r, o);


                Console.WriteLine("C#, {0} bytes", Encoding.Unicode.GetByteCount(@"var y = new Func<string,string>(s => new String(s.ToLower().Replace("" "","""").OrderBy(v => v).ToArray()));
    var z = new Func<string,string,Func<string,string>,bool>((w,x,f) => f(w) == f(x));"));

    }

}

Chris Hayes

Posted 2016-02-25T16:08:54.523

Reputation: 101

4Welcome to Programming Puzzles & Code Golf! General rule is to put your language together with your byte count in the headline of your post. You can do that by adding a leading # to the first line. Also for code-golf questions it is required to golf your program. For the start you should remove unecessary whitespaces and use single-character variable names. Also you can always use a function instead of a full program (unless explicitly forbidden) to save some more bytes. – Denker – 2016-02-28T00:40:33.567

@DenkerAffe you ninja'd me :) – cat – 2016-02-28T00:40:50.597

1Why all the whitespace?? – CalculatorFeline – 2016-03-06T20:32:07.657

0

Factor, 68 bytes

[ [ 32 swap remove >lower natural-sort ] map duplicates length 1 = ]

An anyonymous function. Call it like { "array" "of" "strings" } ~quotation~ call.

cat

Posted 2016-02-25T16:08:54.523

Reputation: 4 989