[Question]
  [
Given a number *n* (0 <= *n* <= 2642245), check if *n* and *n*3 have the same set of digits, and output a truthy or falsey value accordingly.
For example, let's check the number 100.
1003 is 1000000.
The set of digits in 100 is {0, 1}.
The set of digits in 1000000 is {0, 1}.
Therefore, 100 should give a truthy value.
### Test cases
```
0 -> True
1 -> True
10 -> True
107624 -> True
251894 -> True
251895 -> False
102343 -> False
```
Remember, this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the code with the fewest bytes wins.
[OEIS A029795](http://oeis.org/A029795)
  
[Answer]
# Python 3, ~~36~~ 32 bytes
```
lambda x:{*str(x)}=={*str(x**3)}
```
I think this only works in Python 3.5 and later.
Four bytes have gone, thanks to Copper.
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 6 bytes
05AB1E uses [CP-1252](http://www.cp1252.com) encoding.
```
3mê¹êQ
```
[Try it online!](http://05ab1e.tryitonline.net/#code=M23DqsK5w6pR&input=MjUxODk0)
**Explanation**
```
3m       # input^3
  ê      # sorted with duplicates removed
     Q   # is equal to
   ¹ê    # input sorted with duplicates removed
```
[Answer]
# C, 73 bytes
```
k;b(i){k=0;while(i)k|=1<<i%10,i/=10;return k;}f(n){return b(n)-b(n*n*n);}
```
Creates the set via bits. Returns `0` for same set, anything else for different sets.
Ungolfed:
```
k;
b(i){
  k=0;
  while(i)
    k|=1<<i%10,
    i/=10;
  return k;
}
f(n){
  return b(n)-b(n*n*n);
}
```
[Answer]
# Perl, 31 + 2 (`-pl` flag) = ~~25~~ ~~21~~ ~~18~~ ~~34~~ 33 bytes
```
$_=($==$_**3)!~/[^$_]/*!/[^$=]/
```
Using:
```
perl -ple '$_=($==$_**3)!~/[^$_]/*!/[^$=]/' <<< 251894
```
Output: `1\n` or `0\n`.
Thanx to @Dada for 3 bytes, Gabriel Benamy for 1 byte, & @Zaid for bug reports.
[Answer]
# Mathematica, 34 bytes
```
f=Union@*IntegerDigits;f@#==f[#^3]&
```
Direct implementation (unnamed function of one integer argument).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
,3*\D‘ṬE
```
[Try it online!](http://jelly.tryitonline.net/#code=LDMqXETigJjhuaxF&input=&args=MTA2MjM5) or [verify all test cases](http://jelly.tryitonline.net/#code=LDMqXETigJjhuaxFCsW8w4figqxH&input=&args=MTAwLCAwLCAxLCAxMCwgMTA3NjI0LCAyNTE4OTQsIDI1MTg5NSwgMTAyMzQzLCAxMDYyMzksIDIxMDM4NjksIDE2NTY0).
### How it works
```
,3*\D‘ṬE  Main link. Argument: n
,3        Pair; yield [n, 3].
  *\      Cumulative reduce by exponentation. Yields [n, n³].
    D     Decimal; yield the digit arrays of n and n³.
     ‘    Increment, mapping 0 ... 9 to 1 ... 10.
      Ṭ   Untruth (vectorizes); map digit array [a, b, c, ...] to the smallest
          of zeroes with ones at indices a, b, c, ...
       E  Test the results for equality.
```
[Answer]
## CJam, 8 bytes
```
l_~3#s^!
```
[Test suite.](http://cjam.tryitonline.net/#code=cU4vezpMOwoKTF9-MyNzXiEKCl1ufS8&input=MAoxCjEwCjEwNzYyNAoyNTE4OTQKMjUxODk1CjEwMjM0Mw)
### Explanation
```
l   e# Read input.
_~  e# Duplicate and evaluate.
3#  e# Raise to third power.
s   e# Convert back to string.
^   e# Symmetric set difference. Gives an empty list iff the two sets
    e# are equal.
!   e# Logical NOT.
```
[Answer]
## Haskell, 47 bytes
```
n%p=[c|c<-['0'..],elem c$show$n^p]
f n=n%1==n%3
```
Very slow. Test with `c<-['0'..'9']`.
Tests every character for inclusion in the string representation of `n`, and makes a list of those included. Does likewise for `n^3` and checks if the lists are equal.
[Answer]
# JavaScript ES6, ~~55~~ 51 bytes
Thanks to Downgoat for 3 bytes! You can save a byte by converting to ES7 and using `n**3` instead of `n*n*n`.
```
n=>(f=s=>[...new Set(s+[])].sort()+[])(n)==f(n*n*n)
```
Simple enough.
[Answer]
# C#, ~~241~~ ~~208~~ ~~205~~ ~~201~~ ~~193~~ ~~233~~ ~~222~~ ~~220~~ ~~212~~ ~~203~~ ~~177~~ 159 bytes (109 alternate)
```
I=>{x=s=>{var a=new int[10];foreach(var h in s+"")a[h-'0']++;return a;};var i=x(I);var j=x(I*I*I);for(var k=0;k<10;)if(i[k]>0^j[k++]>0)return 0>1;return 1>0;};
```
The lambda's must specifically use the `ulong` type:
```
System.Func<ulong, bool> b; // = I=>{...};
System.Func<ulong, int[]> x; // inner lambda
```
Thanks to @Corak and @Dennis\_E for saving some bytes, and @TimmyD for finding a problem with my original solution. Thanks to @SaxxonPike for pointing out the ulong/long/decimal/etc problem (which actually also saved me some bytes).
---
There is also a **109 byte** solution using HashSets, similar to the Java answers here, but I'm going to stick to my original solution for my score.
```
using System.Collections.Generic;I=>{return new HashSet<char>(I+"").SetEquals(new HashSet<char>(I*I*I+""));};
```
[Answer]
# Java 8, 154 characters
```
a->java.util.Arrays.equals((a+"").chars().distinct().sorted().toArray(),(new java.math.BigInteger(a+"").pow(3)+"").chars().distinct().sorted().toArray());
```
Called like this:
```
interface Y {
    boolean n(int x);
}
static Y y = a->java.util.Arrays.equals((a+"").chars().distinct().sorted().toArray(),(new java.math.BigInteger(a+"").pow(3)+"").chars().distinct().sorted().toArray());
public static void main(String[] args) {
    System.out.println(y.n(0));
    System.out.println(y.n(1));
    System.out.println(y.n(10));
    System.out.println(y.n(107624));
    System.out.println(y.n(251894));
    System.out.println(y.n(251895));
    System.out.println(y.n(102343));
}
```
Outputs:
```
true
true
true
true
true
false
false
```
A very Java 8-y answer, using a lambda as well as streams including some fancy number-to-string conversions. 
Unfortunately we need to use `BigInteger.pow(3)` instead of `Math.pow(a,3)` due to Math.pow using non-precise doubles, which return incorrect values with large numbers (starting with `2103869`).
[Answer]
# BASH, ~~69~~, 59 bytes
*UPDATE* 
Another nice way to do this in bash is to use *tr* (62 bytes, but can probably be squeezed a bit more)
```
T() { m=`bc<<<$1^3`;[ -z "`tr -d $m <<<$1;tr -d $1 <<<$m`" ];}
```
*EDIT:* Some more optimizations (Thx ! @manatwork)
**Golfed**
```
T() { S(){ fold -1|sort -u;};bc<<<$1^3|S|diff - <(S<<<$1);}
```
**Test**
```
TEST() {
 T $1 >/dev/null; echo $?
}
TEST 0
0
TEST 1
0
TEST 11
1
TEST 10
0
TEST 107624
0
TEST 251894
0
TEST 251895
1
TEST 102343
1
TEST 106239
1
```
0 - for success (exit code)
1 - for failure (exit code)
[Answer]
# x86-64 machine code function, 40 bytes.
# Or 37 bytes if 0 vs. non-zero is allowed as "truthy", like strcmp.
Thanks to Karl Napf's C answer for the bitmap idea, which x86 can do very efficiently with [BTS](http://www.felixcloutier.com/x86/BTS.html).
Function signature: `_Bool cube_digits_same(uint64_t n);`, using the x86-64 System V ABI. (`n` in RDI, boolean return value (0 or 1) in AL).
`_Bool` is defined by ISO C11, and is typically used by `#include <stdbool.h>` to define `bool` with the same semantics as C++ `bool`.
Potential savings:
* 3 bytes: Returning the inverse condition (non-zero if there's a difference). Or from inline asm: returning a flag condition (which is possible with gcc6)
* 1 byte: If we could clobber EBX (doing so would give this function a non-standard calling convention). (could do that from inline asm)
* 1 byte: the RET instruction (from inline asm)
All of these are possible if this was an inline-asm fragment instead of a function, which would make it **35 bytes for inline-asm**.
```
0000000000000000 <cube_digits_same>:
   0:   89 f8           mov    eax,edi
   2:   48 f7 e7        mul    rdi          # can't avoid a REX prefix: 2642245^2 doesn't fit in 32 bits
   5:   48 f7 e7        mul    rdi          # rax = n^3, rdx=0
   8:   44 8d 52 0a     lea    r10d,[rdx+0xa]  # EBX would save a REX prefix, but it's call-preserved in this ABI.
   c:   8d 4a 02        lea    ecx,[rdx+0x2]
000000000000000f <cube_digits_same.repeat>:
   f:   31 f6           xor    esi,esi
0000000000000011 <cube_digits_same.cube_digits>:
  11:   31 d2           xor    edx,edx
  13:   49 f7 f2        div    r10         ; rax = quotient.  rdx=LSB digit
  16:   0f ab d6        bts    esi,edx     ; esi |= 1<<edx
  19:   48 85 c0        test   rax,rax     ; Can't skip the REX: (2^16 * 10)^3 / 10 has all-zero in the low 32.
  1c:   75 f3           jne    11 <cube_digits_same.cube_digits>
                                         ; 1st iter:                 2nd iter:                both:
  1e:   96              xchg   esi,eax   ; eax=n^3 bitmap            eax=n bitmap             esi=0
  1f:   97              xchg   edi,eax   ; edi=n^3 bitmap, eax=n     edi=n bmp, eax=n^3 bmp
  20:   e2 ed           loop   f <cube_digits_same.repeat>
  22:   39 f8           cmp    eax,edi
  24:   0f 94 d0        sete   al
                  ;; The ABI says it's legal to leave garbage in the high bytes of RAX for narrow return values
                  ;; so leaving the high 2 bits of the bitmap in AH is fine.
  27:   c3              ret    
0x28: end of function.
```
LOOP seems like the smallest way to repeat once. I also looked at just repeating the loop (without REX prefixes, and a different bitmap register), but that's slightly larger. I also tried using PUSH RSI, and using `test spl, 0xf` / `jz` to loop once (since the ABI requires that RSP is 16B aligned before CALL, so one push aligns it, and another misaligns it again). There's no `test r32, imm8` encoding, so the smallest way was with a 4B TEST instruction (including a REX prefix) to test just the low byte of RSP against an imm8. Same size as LEA + LOOP, but with extra PUSH/POP instructions required.
Tested for all n in the test range, vs. steadybox's C implementation (since it uses a different algorithm). In the two cases of different results that I looked at, my code was correct and steadybox's was wrong. I think my code is correct for all n.
```
_Bool cube_digits_same(unsigned long long n);
#include <stdio.h>
#include <stdbool.h>
int main()
{
    for(unsigned n=0 ; n<= 2642245 ; n++) {
        bool c = f(n);
        bool asm_result = cube_digits_same(n);
        if (c!=asm_result)
            printf("%u problem: c=%d asm=%d\n", n, (int)c, (int)asm_result);
    }
}
```
The only lines printed have c=1 asm=0: false-positives for the C algorithm.
Also tested against a `uint64_t` version of Karl's C implementation of the same algorithm, and the results match for all inputs.
[Answer]
# [Dyalog APL](http://goo.gl/9KrKoM), 10 [bytes](http://meta.codegolf.stackexchange.com/a/9429/43319)
```
⍕≡⍕∪(⍕*∘3)
```
`⍕≡` is the argument's text representation identical to
`⍕∪` the union of the argument's text representation and
`(⍕*∘3)` the text representation of the cubed argument?
[TryAPL online!](http://tryapl.org/?a=%u2395pp%u219017%20%u22C4%20f%u2190%u2355%u2261%u2355%u222A%28%u2355*%u22183%29%20%u22C4%20f%A80%201%2010%20107624%20251894%20251895%20102343&run)
**Note:** For large numbers, set `⎕PP←34 ⋄ ⎕FR←1287` (34 significant digits, 128 bit floats)
[Answer]
# Clojure, 35 bytes
```
#(=(set(str %))(set(str(* % % %))))
```
[Answer]
# Haskell, ~~54~~ 52 bytes
Thanks @Laikoni for saving two bytes.
```
(%)=all.flip elem
k n|[a,b]<-show<$>[n,n^3]=b%a&&a%b
```
[Answer]
# Java 7, ~~185~~ 178 characters
```
import java.util.*;
boolean a(int n){return new HashSet(Arrays.asList((n+"").split(""))).equals(new HashSet(Arrays.asList((new java.math.BigInteger(n+"").pow(3)+"").split(""))));}
```
Call as:
```
public static void main(String [] args) {
    System.out.println(0 + " -> " + a(0));
    System.out.println(1 + " -> " + a(1));
    System.out.println(10 + " -> " + a(10));
    System.out.println(107624 + " -> " + a(107624));
    System.out.println(2103869 + " -> " + a(2103869));
    System.out.println(251894 + " -> " + a(251894));
    System.out.println(251895 + " -> " + a(251895));
    System.out.println(102343 + " -> " + a(102343));
    System.out.println(106239 + " -> " + a(106239));
}
```
Output:
```
0 -> true
1 -> true
10 -> true
107624 -> true
2103869 -> true
251894 -> true
251895 -> false
102343 -> false
106239 -> false
```
*(I'm never sure if I have to count imports and method definitions as well... I've seen either way. The code itself would be only 141 bytes long though.)*
[Answer]
# R, ~~65~~ ~~79~~ 70 bytes
Takes `n` from stdin, splits `n` and `n^3` into single digits, and compares the two sets. Uses the `gmp` package to handle large integers (thanks to Billywob for pointing out that shortcoming). Now uses `substring` to cut up `n` and `n^3`, thanks to @MickyT for the suggestion. (Previous versions used `scan` and `gsub` in a hacky way.)
```
s=substring
setequal(s(n<-gmp::as.bigz(scan()),p<-1:1e2,p),s(n^3,p,p))
```
[Answer]
# [Jelly](http://github.com/DennisMitchell/jelly), 8 bytes
```
*3ṢQ⁼ṢQ$
```
[Try it online!](http://jelly.tryitonline.net/#code=KjPhuaJR4oG84bmiUSQ&input=&args=MTAw)
Explanation:
```
       $    # As a monadic (single argument) link:
    ⁼       # Return true if the following are equal
     ṢQ     # The unique sorted elements of 'n'
  ṢQ        # and The unique sorted elements
*3          # of 'n^3'
```
[Answer]
# Pyth, 10 bytes
Because we don't have enough variety with Pyth answers, let's add not one, but two more! Both are 10 bytes, and have been tested with `106239` as a sample input (which some other answers failed).
```
!s.++Q,`**
```
Explanation:
```
!s.++Q,`**QQQQ   Implicit input filling
        **QQQ    Q ^ 3
       `         repr(Q^3)
      ,      Q   [repr(Q^3),Q]
    +Q           [Q,repr(Q^3),Q]
  .+             Deltas ([Digits in Q but not in Q^3, digits in Q^3 but not in Q])
!s               Are both empty?
```
[Try the first answer using an online test suite.](http://pyth.herokuapp.com/?code=%21s.%2B%2BQ%2C%60%2a%2a&test_suite=1&test_suite_input=106239%0A0%0A1%0A10%0A107624%0A251894%0A251895%0A102343&debug=0)
Second answer:
```
qFmS{`d,**
```
Explanation:
```
qFmS{`d,**QQQQ   Implicit input filling
        **QQQ    Q ^ 3
       ,     Q   [Q^3, Q]
  m              map over each element d of [Q^3, Q]:
     `d           the element's string representation
    {             with duplicates removed
   S              and sorted
qF               Fold over equality (are the two the same?)
```
[Try the second answer using an online test suite.](http://pyth.herokuapp.com/?code=qFmS%7B%60d%2C%2a%2a&test_suite=1&test_suite_input=106239%0A0%0A1%0A10%0A107624%0A251894%0A251895%0A102343&debug=0)
[Answer]
# Kotlin: 46/88/96 bytes
The question doesn't specify from where the input comes from, so here's the usual 3 input sources.
---
### Function: 46 bytes
```
fun f(i:Long)="$i".toSet()=="${i*i*i}".toSet()
```
---
[Answer]
## JavaScript (ES6), 44 bytes
```
g=n=>n<1?0:g(n/10)|1<<n%10
n=>g(n)==g(n*n*n)
```
Port of @KarlNapf's excellent C answer. ES7 saves a byte via `n**3`. Only works up to 208063 due to JavaScript's limited numeric precision; if you only need it to work up to 1290, you can save another byte.
[Answer]
# [Perl 6](https://perl6.org), 22 bytes
```
{!(.comb⊖$_³.comb)}
```
## Expanded:
```
{ # bare block lambda with implicit parameter ｢$_｣
  !(
    .comb # get a list of the graphemes ( digits )
    ⊖ # Symmetric Set difference
    $_³.comb # cube and get a list of the graphemes
  )
}
```
The [Symmetric Set difference ｢⊖｣ operator](https://docs.perl6.org/routine/(%5E)) returns an empty [Set](https://docs.perl6.org/type/Set) if both sides are equivalent Sets (automatically turns a list into a Set). At that point the only thing left to do is invert it logically.
[Answer]
# C++, 82 bytes
```
t(int a){int b=a*a*a,c,d;while(a|b)c|=1<<a%10,a/=10,d|=1<<b%10,b/=10;return c==d;}
```
The function t(a) returns the answer. Uses an int as a set. Printed nicely:
```
t(int a)
{
    int b = a*a*a, c, d;
    while(a|b) c|=1 << a%10, a/=10, d|=1 << b%10, b/=10;
    return c==d;
}
```
[Answer]
# C++14, 93 bytes
```
int b(auto i){int k=0;while(i)k|=1<<i%10,i/=10;return k;}int f(auto n){return b(n)-b(n*n*n);}
```
Port of my [C answer](https://codegolf.stackexchange.com/a/99836/53667), works for big numbers (call with `L` suffix).
[Answer]
# Ruby, 48 bytes
```
->n{(f=->x{x.to_s.chars.uniq.sort})[n]==f[n**3]}
```
[Answer]
## Haskell, 47 bytes
```
import Data.Set
s=fromList.show
f n=s n==s(n^3)
```
Usage example: `f 102343` -> `False`.
Uses sets from the `Data.Set` module. The helper function `s` turns a number into its string representation and than makes a set out of the characters. 
[Answer]
# [Brachylog](http://github.com/JCumin/Brachylog), 11 bytes
```
doI,?:3^doI
```
[Try it online!](http://brachylog.tryitonline.net/#code=ZG9JLD86M15kb0k&input=MTAyMzQz)
Thanks to @DestructibleWatermelon for pointing out a problem with my original answer.
### Explanation
```
(?)doI,           I is the Input sorted with no duplicates
       ?:3^       Compute Input^3
           doI    Input^3 sorted with no duplicates is I
```
[Answer]
## PowerShell v2+, ~~94~~ 93 bytes
```
filter f($n){-join("$n"[0..99]|sort|select -u)}
(f($x=$args[0]))-eq(f("[bigint]$x*$x*$x"|iex))
```
*(Newline for clarity, not included in bytecount)*
The first line defines `f` as a `filter` (similar-ish enough to a function for our purposes here to not go into specifics) that takes input `$n` and does the following:
```
filter f($n){-join("$n"[0..99]|sort|select -u)}
       f($n)                                    # Input
                   "$n"                         # Cast as string
                       [0..99]                  # Index as char-array
                              |sort             # Sorted alphabetically
                                   |select -u   # Only select the -Unique elements
             -join(                          )  # Join those back together into a string
                                                 # Implicit return
```
The second line takes the input `$args`, performs `f` on it, and checks whether it's `-eq`ual to `f` performed on `$x` cubed. Note the explicit `[bigint]` cast, required else we'll get the result back in scientific notation, which will obviously not work.
The Boolean result is left on the pipeline, and output is implicit.
```
PS C:\Tools\Scripts\golfing> 0,1,10,107624,251894,251895,102343,106239,2103869|%{"$_ --> "+(.\do-n-n3-same-digits.ps1 $_)}
0 --> True
1 --> True
10 --> True
107624 --> True
251894 --> True
251895 --> False
102343 --> False
106239 --> False
2103869 --> True
```
*Saved a byte thanks to @ConnorLSW*
[Answer]
# Groovy, 35 ~~51~~ chars/bytes
I was sad not to see Groovy included, so here's my original 51-byte attempt:
`def x(def n){"$n".toSet()=="${n.power(3)}".toSet()}`
Rewritten as a 35-byte anonymous closure and with `**` for exponentiation, thanks to manatwork:
`{"$it".toSet()=="${it**3}".toSet()}`
Some test cases for the original function:
```
println x(0)
println x(1)
println x(10)
println x(107624)
println x(251894)
println x(251895)
println x(102343)
```
A named closure `c` could be called like this: `println c.call(107624)`. The anonymous 35-byte closure could be called like this: `println ({"$it".toSet()=="${it**3}".toSet()}(107624))`
Outputs:
```
true
true
true
true
true
false
false
```
Please note: I learned that something like code golf exists just now, so hopefully I got this right!
]