[Question]
  [
## Challenge
Given two strings, work out if they both have exactly the same characters in them.
## Example
**Input**
> 
> word, wrdo
> 
> 
> 
This returns `true` because they are the same but just scrambled.
**Input**
> 
> word, wwro
> 
> 
> 
This returns `false`.
**Input**
> 
> boat, toba
> 
> 
> 
This returns `true`
## Rules
Here are the rules!
* Assume input will be at least 1 char long, and no longer than 8 chars.
* No special characters, only `a`–`z`
* All inputs can be assumed to be lowercase
## Test Cases
```
boat, boat = true
toab, boat = true
oabt, toab = true
a, aa = false
zzz, zzzzzzzz = false
zyyyzzzz, yyzzzzzy = true
sleepy, pyels = false
p,p = true
```
  
[Answer]
# Python, 32 bytes
```
f=lambda a,b,S=sorted:S(a)==S(b)
```
[Answer]
### Golfscript, 3 chars?
```
$$=
```
usage: 
```
'boat'$'baot'$=
1
'toab'$'boat'$=
1
'oabt'$'toab'$=
1
'a'$'aa'$=
0
'zzz'$'zzzzzzzz'$=
0
'zyyyzzzz'$'yyzzzzzy'$=
1
'sleepy'$'pyels'$=
0
'p'$'p'$=
1
```
[Answer]
## J, 8
```
-:&(/:~)
```
Literaly, match (`-:`) on (`&`) sort up (`/:~`)
Sample use:
```
   'boat' -:&(/:~) 'boat'
1
   'toab' -:&(/:~) 'boat'
1
   'oabt' -:&(/:~) 'toab'
1
   'a' -:&(/:~) 'aa'
0
   'zzz' -:&(/:~) 'zzzzzzzz'
0
   'zyyyzzzz' -:&(/:~) 'yyzzzzzy'
1
   'sleepy' -:&(/:~) 'pyels'
0
   'p' -:&(/:~) 'p'
1
```
Where do the 64-bit integers come into play?
[Answer]
## Javascript, 192 157 152 147 125 bytes
Ok some of these languages are a lot more flexibile than I thought! Anyway this is the longer way I guess, but a different technique at least.
**Compressed**
Thanks to Peter and David for squeezing more chars out!
```
for(a=[j=p=2];j<123;)a[j]?p%a[++j]<1&&p++&&(j=0):(a[j]=p,j=0);function b(c,i){return c[i=i||0]?a[c.charCodeAt(i)]*b(c,++i):1}
```
Then do:
```
alert(b("hello")==b("elloh"));
```
**Expanded Code**
The compressed has had lots of changes, but this is the basic theory:
```
// Define dictionary of primes
a = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101];
// Returns the unique ID of the word (order irrelevant)
function b(c) {
    r = 1;
    for (i = 0; i < c.length; i++)
        r *= a[c[i].charCodeAt(0) - 97];
    return r
}
alert(b("hello") == b("hlleo"));
```
[Answer]
# Golfscript, 8 bytes
This defines a function called `A`
```
{$\$=}:A
```
Test cases
```
;
'boat' 'boat' A
'toab' 'boat' A
'oabt' 'toab' A
'a' 'aa' A
'zzz' 'zzzzzzzz' A
'zyyyzzzz' 'yyzzzzzy' A
'sleepy' 'pyels' A
'p' 'p' A
```
[Answer]
# Haskell, 31 bytes
## function - 31
```
import List
f=(.sort).(==).sort
```
## program - 81 58 55
```
import List
g=sort`fmap`getLine
main=(`fmap`g).(==)=<<g
```
Usage:
```
$ runghc anagram.hs
boat
boat
True
$ runghc anagram.hs
toab
boat
True
$ runghc anagram.hs
a
aa
False
```
Kudos to [lambdabot](http://www.haskell.org/haskellwiki/Lambdabot) and its [pointfree refactoring](http://www.haskell.org/haskellwiki/Pointfree).
[Answer]
## C#, 129 chars
```
namespace System.Linq{class X{static void Main(string[]a){Console.Write(a[0].OrderBy(_=>_).SequenceEqual(a[1].OrderBy(_=>_)));}}}
```
Readable:
```
namespace System.Linq
{
    class X
    {
        static void Main(string[] a)
        {
            Console.Write(a[0].OrderBy(_ => _)
                  .SequenceEqual(a[1].OrderBy(_ => _)));
        }
    }
}
```
[Answer]
# Ruby, 34 bytes
Using the IO scheme of Peter Taylors Perl solution:
```
p gets.chars.sort==gets.chars.sort
```
[Answer]
# C program, 118
```
t[52],i;main(c){for(;i<52;)(c=getchar())<11?i+=26:t[i+c-97]++;
for(i=27;--i&&t[i-1]==t[i+25];);puts(i?"false":"true");}
```
[Answer]
## Perl, 58 bytes
(complete program, unlike the other Perl answer which is only a function)
```
($c,$d)=map{[sort split//]}<>;print"@$c"eq"@$d"?true:false
```
## 49 as a function
```
sub f{($c,$d)=map{[sort split//]}<>;"@$c"eq"@$d"}
```
[Answer]
# Clojure - 23 chars
As an anonymous function:
```
#(apply = (map sort %))
```
Test case example:
```
(#(apply = (map sort %)) ["boat" "boat"])
=> true
```
[Answer]
**JavaScript**
Based on @zzzzBov's solution.
Comparison, 65 chars (40 without function)
```
function f(a,b){return a.split('').sort()==b.split('').sort()+""}
```
Comparator, 43 chars
```
function f(a){return a.split('').sort()+""}
```
[Answer]
# C++ (104 non-ws chars)
  
Based on counting sort. Note: Assumes strings of the same length, which seems to be implied (though not stated) by the question.
```
int u[123], i;
int a(char **c) {
    for(; c[0][i]; ) {
        u[c[0][i]]++;
        u[c[1][i++]]--;
    }
    i=123;
    while(i && !u[--i]);
    return !i;
}
```
[Answer]
# APL, 2 chars
```
≡⍦
```
This is the [Multiset Match](http://wiki.nars2000.org/index.php/Multisets#Multiset_Match) function from [Nars2000](http://www.nars2000.org/), one of the leading-edge APL implementations. When applied to strings, it computes exactly the function required:
```
      'elvis' ≡⍦ 'lives'
1
      'alec guinness' ≡⍦ 'genuine class'
1
```
[Answer]
# [R](https://www.r-project.org/), 54 bytes
```
function(x,y,`~`=sort,`+`=utf8ToInt)identical(~+x,~+y)
```
[Try it online!](https://tio.run/##VYoxDsMgEAT7PIPKCNKniB@QPg8AOyAhIUDmLPko@Do@g5tsc7tzszX7fja7hxVcDNMhUaqq5hw3kEqoeQf7@sZPAO5@JoBbtZ@qOGQVyJud2BI1MDkOfxCAqJc/QPsyOu@gIGKhEByl4HgkImlUTVXr2@9quTNY9sYkvHw0PjPeTg "R – Try It Online")
[Answer]
# [Knight](https://github.com/knight-lang/knight-lang), 112 bytes
```
;=dF;C=mB;=a 123W<96=a-a 1Id=d!E+"a"aE++"=a"a" 0";=w"+1a";C=lB;=bP:Wb;E++"=a"Ab+wAb=bGb 1Lb;=w"+~1a";Cl;=dT;CmOd
```
[Try it online!](https://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Online")
Knight doesn't have arrays. It does have strings, but it only allows a subset of valid ASCII character codes. So I emulated an array by constructing strings that looks like `"=a{charcode} 0"` and evaling it.
Knight also has blocks. A block works like a niladic function, which can change its behavior depending on global variables. This code uses two blocks: `m` loops over all 26 variables `a97 - a122` initializing or testing something, and `l` handles the part of taking input and iterating over its chars to count occurrences.
```
; = d F                  d = False
; C = m B                define and run block m:
  ; = a 123                a = 123
  : W < 96 = a - a 1       while 96 < (a = a - 1):
    I d                      if d:
      = d ! E + "a" a          d = ! eval("a" + a)
      E + + "=a" a " 0"      else: eval("=a" + a + " 0") (aNN = 0)
                         i.e. d is false on start, so initialize all of a97..a122 to 0
; = w "+1a"              w = "+1a" (which is necessary to run l)
; C = l B                define and run block l:
  ; = b P                  b = one line of input
  : W b                    while b is not empty:
    ; E +                    eval(concatenation of
          + "=a" A b           "=aNN"
          + w A b              w+"NN") (aNN = 1 + aNN)
                             (w = "+~1a" changes this to aNN = -1 + aNN)
    : = b G b 1 L b          b = b[1:length(b)]
                         i.e. count occurrences of chars in the first line
; = w "+~1a"             w = "+~1a"
; C l                    run block l i.e. count negative occurrences in the second line
; = d T                  d = True
; C m                    run block m
                         for each of a122..a97, check if aNN is zero
                         if true, keep checking; otherwise do useless thing
: O d                    print d
```
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), ~~6~~ 4 bytes
```
{I{Q
```
[Try it online!](http://05ab1e.tryitonline.net/#code=e0l7UQ&input=d29yZAp3ZHJv)
This took a while because of input difficulties. Golfed down due to pop.
Explanation:
```
{I{Q    Original code
{       Takes first input e.g. word and sorts -> 'dorw'
 I      Takes second input e.g. 'wrdo'
  {     Sorts second input -> 'dorw'
   Q    Compare if sorted 1 = sorted 2, then print result. 'dorw' = 'dorw', so prints 1.
```
[Answer]
## PHP (command line, 87 characters)
```
function d($s){
    return array_count_values(str_split($s));
}
echo d($argv[1]) == d($argv[2]);
```
[Answer]
# Javascript
A (very) slightly shorter version of @zzzzBov's solution, that uses `.join()` instead of String boxing:
```
function a(b,c){return b.split('').sort().join()==c.split('').sort().join()}
alert(a('abc','bca')); //true
```
Similarly:
```
function a(b){return b.split('').sort().join()}
alert(a('abc')==a('bca')); //true
```
[Answer]
**Clojure REPL 41 chars**
```
(= (sort (read-line)) (sort (read-line)))
```
[Answer]
# Java
(everyone's favorite language apparently!)
173 chars:
```
import java.util.*;class g{public static void main(String[]p){String[]a=p[0].split(""),b=p[1].split("");Arrays.sort(a);Arrays.sort(b);System.out.print(Arrays.equals(a,b));}}
```
(Doesn't print newline char to save 2 chars from println)
Compile and run:
```
javac g.java
java -cp . g abcdef fedcba
true
```
Love to see a shorter one...
[Answer]
# sed, 45 chars
It's even possible in my favourite - `sed`! **Just one regular expression to solve the anagram**! Just keep removing the corresponding letters:
```
:
s/(.)(.*,.*)\1/\2/
t
/\w/{i\false
d}
i\true
```
(to be invoked with `-nE`)
# Perl, 48
```
1while s/(.)(.*,.*)\1/\2/;$_=/\w/?"false":"true"
```
To be invoked with `-p`.
# Perl function, 39
```
sub f{$,while s/(.)(.*,.*)\1/\2/;!/\w/}
```
[Answer]
# Perl, 62 bytes
This function takes the strings as arguments and returns true or false.
```
sub f{my@a;for$.(1,-1){$a[ord]+=$.for split//,pop}!grep{$_}@a}
```
Stores the ASCII values in an array and checks if it evens out. Increments for the first word and decrements for the second word.
[Answer]
## Python 3, ~~107~~ ~~97~~ ~~76~~ 64
```
s=sorted;a,b=input().split(', ')
print(str(s(a)==s(b)).lower())
```
Obviously this can be shortened if we don't take the OP's wording literally and lowercase "true" and "false"...
[Answer]
# Python, 32 bytes
```
p=sorted
f=lambda a,b:p(a)==p(b)
```
[Answer]
# Bash, 88 characters
```
diff <(grep -o .<<<$1|sort) <(grep -o .<<<$2|sort)>/dev/null && echo true || echo false
```
[Answer]
## Scala in REPL (32)
```
readLine.sorted==readLine.sorted
```
## Scala function (43)
```
def f(a:String,b:String)=a.sorted==b.sorted
```
## Scala program (61)
```
object A extends App{println(args(0).sorted==args(1).sorted)}
```
These leverage a neat feature of Scala whereby a String can also be treated as a sequence of characters (`Seq`), with all the operations on `Seq` being available.
[Answer]
# APL - 13 chars
```
{(⍺[⍋⍺])≡⍵[⍋⍵]}
```
Call like this:
```
      'boat' {(⍺[⍋⍺])≡⍵[⍋⍵]} 'baot'
1
      'baot' {(⍺[⍋⍺])≡⍵[⍋⍵]} 'boat'
1
      (,'a') {(⍺[⍋⍺])≡⍵[⍋⍵]} 'aa'
0
```
In the last example, `'a'` represents a single character, and the prefix `,` will convert it into a string.
[Answer]
# Java (134 bytes)
```
int[][]c=new int[2][26];
for(int i=0;i<2;i++)for(byte a:args[i].getBytes())c[i][a-97]++;
System.out.print(Arrays.equals(c[0],c[1]));`
```
This makes an array to count the number of times each letter appears, and then compares the arrays to check if they are equal.
[Answer]
## Perl, 77 75 chars
The I/O of the problem aren't well specified; this reads two lines from stdin and outputs **true** or **false** to stdout.
```
sub p{join'',sort split'',$a}$a=<>;$x=p;$a=<>;print$x eq p()?"true":"false"
```
(Thanks to Tim for 77 -> 75)
]