text:
The Art of Word Shaping
The Art of Word Shaping
Given a binary matrix and a string of letters, replace all 1's in the matrix, moving from top to bottom and from left to right within each row, with the letters of the string. Once the letters have been formed into the shape of the matrix, print the matrix, replacing 0's with spaces. It's probably easier to just give an example or two.

Case: Base case...
Input One:
[0,0,1,0,0]
[0,1,0,1,0]
[1,0,0,0,1]
[0,1,0,1,0]
[0,0,1,0,0]

"PPCGPPCG"

Output One:
  P
 P C
G   P
 P C
  G

Case: If the input string is longer than the number of ones...
Input Two:
[1,0,0]
[0,1,0]
[1,0,1]

lambda

Output Two:
l
 a
m b

Case: If the input string is shorter than the number of ones...
Input Three:
[1,1,1]
[1,0,1]
[1,1,1]

PPCG

Output Three:
PPC
G P
PCG

Available Assumptions

You may assume the input string is never empty.
You may assume the matrix will never be empty.
You may not assume that the binary matrix will never be all zeros.

Rules

If the string is shorter than the number of ones, repeat the string; all ones must be replaced.
If the string is longer than the number of ones, only use what is needed.
You may use True/False in place of integers/bits for the input.
Trailing spaces ARE REQUIRED, all zeros must be replaced with spaces.
A single trailing newline is acceptable.
This is code-golf, lowest byte count wins.

Does the matrix have to be input as an array or can I use a multiline-string?

@Titus that's fine, Martin Ender already did.

The base case is not left to right. Do you mean top to bottom, then left to right?

If the matrix is, for example, a 2x2 grid of zeroes, should we output a single space or a 2x2 grid of spaces?

@pieman2201 cleared up test case #4 to be better.

@BlueEyedBeast good call, made an edit to make it more clear on pieman's question and forgot that it wasn't even a valid input scenario.

Must the output contain spaces or can it contain characters which are rendered as spaces? For example, in Python print '\x00' looks the same as print ' '

@wnnmaw ASCII character code 32 is the only usable thing ;).

Trailing spaces ARE REQUIRED, all zeros must be replaced with spaces. um, can we have extra trailing spaces?

@DestructibleWatermelon no. That's what "all zeros must be replaced with spaces" was covering.

MATL, 11 bytes
yz:)1Gg!(c!

Inputs are a numeric matrix (with ; as row separator) and a string.
Try it online! Or verify test cases: 1, 2, 3.
y       % Take the two inputs implicitly. Duplicate the first
        % STACK: [1,0,0; 0,1,0; 1,0,1], 'lambda', [1,0,0; 0,1,0; 1,0,1]
z       % Number of nonzeros
        % STACK: [1,0,0; 0,1,0; 1,0,1], 'lambda', 4
:       % Range
        % STACK: [1,0,0; 0,1,0; 1,0,1], 'lambda', [1 2 3 4]
)       % Reference indexing (select values)
        % STACK: [1,0,0; 0,1,0; 1,0,1], 'lamb'
1Gg     % Push first input as a logical matrix; will be used as index
        % STACK: [1,0,0; 0,1,0; 1,0,1], 'lamb', [1,0,0; 0,1,0; 1,0,1]
!       % Transpose. This is necessary because MATL uses column-major order
        % (down, then accross)
(       % Assignment indexing (fill with values). Since the original matrix
        % is numeric, the new values are introduced as their ASCII codes
        % STACK: [108, 0, 109; 0, 97, 0; 1, 0, 98]
c       % Convert to char
        % STACK: ['l m'; ' a '; '  b']
!       % Transpose back. Implicitly display
        % STACK: ['l  '; ' a '; 'm b']

MATL basically redefines how I've always seen collections...

@carusocomputing Like in Matlab, the main data type is "rectangular" arrays: matrices or their n-dimensional analogues. They can contain numbers, chars or Boolean values. There are also cell arrays, that can contain arbitrary things, like Python's lists

Best answer selected after 2 weeks open.

Vim, 44 42 bytes
qqy$P0xjf1"_xP{@qq@q:s/0/ /g^M:s/,/^V^M/g^M{D

Saved 2 bytes thanks to @DjMcMoylex!
Here, the ^M is a literal newline, and the ^V is CTRL-V
Takes the input in this format:
PPCG
00100,01010,10001,01010,00100

Disclaimer: If the string is longer than ~40 chars long, your computer might run out of ram.
Explanation:
qq             @qq@q                            # Start recording a recursive macro.
  y$P0x                                         # Duplicate the string and cut out the first character
       jf1"_xP{                                 # Find the first 1, and replace it with the cut character from the string.
                                                # Now we have replaced all the 1's with their respective character, but we still have the array in the original format, and we have the string massivly duplicated at the first line, so we need to clean it up:
                    :s/0/ /g^M                  # Replace all 0's with a space
                              :s/,/^V^M/g^M     # Replace all ,'s with a newline. The ^V acts like a backslash, it escapes the newline so that the command isn't run too soon
                                           {D   # Delete the first line

Here's a gif of me "running" the "program":

Hahaha, love the disclaimer.

You could use { in place of gg to take a couple off.

Ok, the gif is really neat, but do you think you could include it via link only? It lags my chrome every time I try to scroll past :(

JavaScript ES6, 67 53 50 49 bytes
Saved 3 bytes thanks to @ETHproductions
Saved 1 more thanks to @Neil
(a,b,i)=>a.replace(/./g,c=>+c?b[++i]||b[i=0]:' ')

f=
(a,b,i)=>a.replace(/./g,c=>+c?b[++i]||b[i=0]:' ')

G=_=>h.innerHTML = f(`00100
01010
10001
01010
00100`,z.value)
h.innerHTML = G()
<input id=z oninput="G()" value="PPCG"></input>

Old code before I knew that string matrices are a valid input format:
(a,b)=>a.map(c=>c.map(d=>d?b[i++%b.length]:' ').join``,i=0).join`
`

f=
(a,b)=>a.map(c=>c.map(d=>d?b[i++%b.length]:' ').join``,i=0).join`
`

G=_=>h.innerHTML = f([[0,0,1,0,0],[0,1,0,1,0],[1,0,0,0,1],[0,1,0,1,0],[0,0,1,0,0]],z.value)
h.innerHTML = G()
<input id=z oninput="G()" value="PPCG"></input>

I'd suggest c=>' '[c]||b[i++%b.length], but sadly it's a byte longer...

However, there's another way to save 3 bytes: (a,b,i)=>a.replace(/\d/g,c=>+c?b[++i]||b[i=0]:' ')

I think that will start at the second character of the string. A snippet update would be nice.

@Titus At first, i is undefined, so ++i returns NaN. Since b has no NaN property, b[++i] returns undefined, and the || operator runs its right-side argument, setting i to 0 and returning the first char in b.

@ETHproductions Now that´s index magic. I keep forgetting about NaN. Thanks.

Why are you testing for \d? Surely . suffices, since you only have to deal with 0s and 1s (. doesn't match newlines).

Retina, 41 33 bytes
0

+1`(.)(.*)(\D+)1
$2$1$3$1
A1`

Try it online!
The input string is given on the first row of the input, followed by the matrix. Since Retina has no concept of lists (or really anything except strings), there are no separators in the binary matrix except for linefeeds to separate rows.
Explanation
0

Turns zeros into spaces.
+1`(.)(.*)(\D+)1
$2$1$3$1

Repeatedly replace the first 1 with the first character of the input string while also rotating that character to the end of the input string. This takes care cases where there are more 1s than characters in the input string.
A1`

Discard the first line, i.e. the input string.

(.)(.*) - Teehee...

Perl, 40 bytes
36 bytes of code + -i -p flags.
@F=$^I=~/./g;s/1/$F[$i++%@F]/g;y;0;

(note the final space and the lack of final newline).
To run it, write the input string after -i flag, and supply the matrix in the input :
perl -iPPCGPPCG -pe '@F=$^I=~/./g;s/1/$F[$i++%@F]/g;y;0; ' <<< "00100
01010
10001
01010
00100"

If your Perl is a bit old, you might need to add a final semicolon (after the space).

Python 2, 114 71 bytes
Turns out I was re-inventing the wheel, a simple double replace on a multiline string works quite well.  The string has the additional benefit of being able to count zeros directly rather than having to do the really ugly s*len(L)*len(L[0]) for a nested list
lambda S,s:S.replace("0"," ").replace("1","{}").format(*s*S.count('0'))

Old solution:
lambda s,L:"\n".join(["".join(map(lambda n:chr(n+32),l)).replace("!","{}")for l in L]).format(*s*len(L)*len(L[0]))

First we convert everything + 32 with chr (all zeros become spaces), then we replace all of the ! with {} to allow using the format function.
If NULL can be counted as a space If I decide to cheat and use NULL instead of space, I can skip the addition of 32 to save 12 bytes. (print displays '\x00' as a space)
lambda s,L:"\n".join(["".join(map(chr,l)).replace('\x01','{}')for l in L]).format(*s*len(L)*len(L[0]))

Wouldn't it be shorter to use the NULLs, and replace them with space at the end?

@nedla2004, How do you suggest I do that? Just adding a .replace('\x00',' ') on the end adds 20 bytes

But then I think you could get rid of this: map(lambda n:chr(n+32),l)

The second solution works with NULLs the whole time, which saves me 12 bytes, swapping to spaces at the end will cost me more than that

I thought you could remove more than you actually can.

PHP, 110 91 97 88 82 81 80 75 bytes
saved 6 bytes thanks to @user59178
while(""<$c=$argv[1][$i++])echo$c<1?$c?:" ":($s=$argv[2])[$k++%strlen($s)];

Run with -r. Expects matrix as multiline string in first argument, string in second argument.

An 80 byte version based on your 82 bytes version: foreach(str_split($argv[1])as$c)echo$c<1?$c?:" ":($s=$argv[2])[$k++%strlen($s)]; I swapped the order of the two ternaries and thus dropped the brackets from the second by using <1 rather than >0

you could save 4 bytes by using for(;""!=$c=$argv[1][$i++];) instead of the foreach(...)

APL, 18 bytes
{(⍴⍺)⍴X\⍵⍴⍨+/X←,⍺}

This is a function that takes a boolean matrix as its left argument and a string as its right argument.
      (↑(1 0 0)(0 1 0)(1 0 1)) {(⍴⍺)⍴X\⍵⍴⍨+/X←,⍺}'lambda'
l
 a
m b

Explanation:
APL has a built-in that does something like this, \ (expand). However, it only works on vectors, and it requires each character to be actually used.

X←,⍺: flatten the matrix and store the result in X.
⍵⍴⍨+/X: reshape the character vector so that it has the required amount of elements (this also takes care of lengthening the string by repeating characters if necessary).
X\: take one of the characters for each 1 and a space for each 0 in X.
(⍴⍺)⍴: reshape the result so that it has the shape of the original matrix.

PowerShell v2+, 70 bytes
param($a,$b)$b|%{-join($_|%{if($_){$a[$n++];$n%=$a.length}else{' '}})}

Takes input word as $a and the matrix as an array-of-arrays as $b (see examples below). Loops through $b, then loops through the elements of each row $_|%{...}. Inner loop is an if/else condition, where we either output $a[$n++] and take mod-equal to the length of the string, or output a space ' '. Those are -joined together back into a string. Each of the strings is left on the pipeline, and implicit output with newlines between happens via Write-Output at program completion.
PS C:\Tools\Scripts\golfing> .\the-art-of-word-shaping.ps1 'PPCGPPCG' @(@(0,0,1,0,0),@(0,1,0,1,0),@(1,0,0,0,1),@(0,1,0,1,0),@(0,0,1,0,0))
  P
 P C
G   P
 P C
  G

PS C:\Tools\Scripts\golfing> .\the-art-of-word-shaping.ps1 'lambda' @(@(1,0,0),@(0,1,0),@(1,0,1))
l
 a
m b

PS C:\Tools\Scripts\golfing> .\the-art-of-word-shaping.ps1 'PPCG' @(@(1,1,1),@(1,0,1),@(1,1,1))
PPC
G P
PCG

Python 3, 104 (or 83) Bytes
import itertools as i
def f(s,L):s=i.cycle(s);return'\n'.join(' '.join(next(s)*e for e in l)for l in L)

There is shorter option (83 Bytes), but it will fail if string is more than 999 times shorter than needed:
def f(s,L):s=list(s)*999;return'\n'.join(' '.join(s.pop(0)*e for e in l)for l in L)

Second solution doesn't work for me, because you can't call next on a list. If you do s=iter(list(s)*999) it does (89 bytes)

@L3viathan sorry, I meant it to be s.pop(0). Seems that I copied wrong version, fixed that.

s[i++%s.length()] is a good methodology, though I don't know python.

It would be cool, but there is no such thing as i++ in Python

Groovy, 63
{a,b->i=0;a.replaceAll("1",{b[i++%b.size()]}).replace("0"," ")}

Japt -R, 10 11 bytes
+1 byte to work around a weird bug with Japt's -map flag that I've never come across before.
®®?VgT°:SÃq

Try it
®®?VgT°:SÃq     :Implicit input of 2D boolean array U & string V
®               :Map
 ®              :  Map
  ?             :    If truthy (i.e., 1)
   Vg           :      Get the character in V at index
     T°         :      T (initially 0) postfix incremented
       :        :    Else
        S       :      Space
         Ã      :  End map
          q     :  Join
                :Implicit output joined with newlines

For Test Case 3 the last line should be "PCG" not "PPC". After some debugging, my best guess is that Japt is caching the output of individual lines, so when it sees line three is [1,1,1] it reuses the line 1 output even though the state has changed.

Woah, @KamilDrakari, you're right! I've never come across that before, have you? I've tested it in all 3 versions available in my interpreter and on TIO and the results are the same across the board. Will need to dive into the Japt source code to figure out why but, in the meantime, the easy fix is to ditch the -m flag and add another ® at the start of the programme.

Pyth, 12 bytes
jms?R@z~hZ\

Try it online: Demonstration
Explanation:
jms?R@z~hZ\ dQ   implicit d and Q at the end
                 I use the variable Z, which is initialized with 0 by default
 m           Q   map each line d of the Q (input matrix) to:
   ?R       d       map each number d of the line either to
     @z~hZ             input[Z++] (increase Z, but lookup in input string with old value)
          \            or space
  s                 join chars to a string
j                print each string on a separate line

Common Lisp, 152 bytes
(defun m(g w)(let((a 0))(loop for r in g do(loop for e in r do(format t"~[ ~;~c~]"e(char w a))(if(= e 1)(setf a(mod(1+ a)(length w)))))(format t"~%"))))

Usage:
* (m (list (list 1 0 1)
           (list 0 1 0)
           (list 1 0 1)) "ppcg")
p p
 c
g p

This function loops through each element of each row of the grid. The format control string either prints a space if the element is a 0 or consumes the character argument if the element is 1. A newline gets printed after every row of the grid. If the string is too short, it repeats from the beginning; if it's too long, only the appropriate part gets outputted.

ES6, 78 bytes
  (a,b,x=0)=>(b.map(r=>r.map(i=>i?a[x++%a.length]:' ')+'\n')+'').replace(/,/g,'')

I tried

Welcome to PPCG!

Java, 237 233 Bytes
Edit: saved 4 Bytes thanks to Mukul Kumar
Golfed:
String T(int[][]m,String b){int l=m.length,a=0;String o="";for(int i=0;i<l;i++){for(int j=0;j<l;j++){if(m[i][j]==1&&a<b.length()){o+=Character.toString(b.toCharArray()[a]);a++;if(a== b.length()-1)a=0;}else o+=" ";}o+="\n";}return o;}

Ungolfed:
public String T(int[][] m, String b) {
    int l = m.length,a=0;
    String o = "";
    for(int i = 0; i < l; i++)
    {
        for(int j = 0; j < l; j++)
        {
            if(m[i][j] == 1 && a < b.length())
            {
                o += Character.toString(b.toCharArray()[a]);
                a++;

                if(a == b.length() - 1)
                    a = 0;
            }
            else
             o += " ";
        }
        o += "\n";
    }
    return o;
}

Testing:
  int[][] matrix = new int[][]
  {{ 0, 0, 1, 0, 0 }, { 0, 1, 0, 1, 0 },
  { 1, 0, 0, 0, 1 },{ 0, 1, 0, 1, 0 },
  { 0, 0, 1, 0, 0 },};
  TheArtOfWordShaping taows = new TheArtOfWordShaping();
  System.out.println(taows.T(matrix, "PPCGPPCG"));

  matrix = new int[][] {{1,0,0}, {0,1,0}, {1,0, 1}};
  taows = new TheArtOfWordShaping();
  System.out.println(taows.T(matrix, "lamda"));

  matrix = new int[][] {{1,1,1},{1,0,1},{1,1, 1}};
  taows = new TheArtOfWordShaping();
  System.out.println(taows.T(matrix, "PPCG"));

  P
 P C
G   P
 P C
  P

l
 a
m d

PPC
P P
CPP

You can declare all int in one line.....

Pip, 18 bytes
17 bytes of code, +1 for -l flag.
Yb{a?y@++vs}MMa^s

Takes the array as the first command-line argument like this: 100 010 101 (needs to be quoted in shells) and the string as the second command-line argument. Try it online!
Explanation
                   a and b are cmdline args, s is space, v is -1
Yb                 Yank b into global variable y
              a^s  Split a on space into list of rows
  {        }MM     Map this function to the items of the items of a (i.e. each character):
   a               Function argument
    ?              Ternary operator (truthy if 1, falsey if 0)
       ++v         If truthy, increment v...
     y@            ... and use it to index into y (cyclically)
                   I.e.: each time we hit a 1, replace it with the next character of y
          s        If falsey, space
                   The result is a list of lists of characters; -l concats sublists and
                   newline-separates the main list

Pyke, 12 bytes
.FdRIKQoQl%@

Try it here!
Outputs a matrix of characters
Or 9 bytes, noncompetitive.
.FdRIKQo@

Try it here!

Add wrapping on indexables where the index asked for is bigger than the length of the indexable.

.F        - deep_for(input)
    I     -  if ^:
      Qo@ -   Q[o++]
  dR      -  else " "

Even more noncompetitive, 8 bytes
.FIQo@(P

Try it here!

print_grid now aligns empty strings properly
deep_for now does type-guessing on falsies of a different type to the truthies

.F    (  -  deep_for(input)
 I       -   if ^:
  Qo@    -    input[o++]
       P - pretty_print(^)

Java,122 bytes
String g(int[][]a,char[]b){String r="";int e=0;for(int[]c:a){for(int d:c){r+=d==0?' ':b[e++%b.length];}r+='\n';}return r;}

05AB1E, 10 bytes
SƶDêþIÞðš‡

Inputs in the order \$matrix, string\$, where the \$matrix\$ is a multi-line string. Outputs the result as a list of characters.
Try it online or verify all test cases.
Explanation:
S          # Split the first (implicit) multi-line string to a list of characters
 ƶ         # Multiply each by its 1-based index (the 0s and "\n" remain unchanged, only
           # the 1s are changed to their 1-based index)
  D        # Duplicate this list
   ê       # Remove all 0s except for a leading one, by using a sorted-uniquify
    þ      # Remove the newline, by only keeping numbers
     I     # Push the second input-string
      Þ    # Cycle its characters indefintely
       ðš  # Prepend a leading space " "
         ‡ # Transliterate the 0s and 1-based indices with these characters
           # (after which the resulting list of characters is output implicitly)

With an actual matrix as I/O, it would have been 13 bytes instead by adding a trailing ¹gä: try it online or verify all test cases (note that the S also implicitly flattens, although an actual flatten ˜ could be used here as well).

Vyxal j, 10 bytes
$¨Svv¨i?ðṠ

Try it Online!
First time I've used ¨S in an answer I think. Takes matrix then string
Explained
$¨Svv¨i?ðṠ
$          # Push matrix then string to the stack
 ¨S        # and set the input source to the characters of the string. This quite literally overrides argv.
   vv      # to each item in the matrix:
     ¨i    #   if the item is 1:
       ?   #     take input (which will be next character of string)
        ð  #   else: space
         Ṡ # sums of items
           # j flag joins on newlines

Vyxal, 8 bytes
‛ %İṠ⁋$%

Try it Online!
   İ     # Index into...
‛ %      # " %"
    Ṡ⁋   # Join each into a string, join by newlines
      $% # Replace %s with corresponding elements of the input

J, 18 bytes
({' '&,)~$$,*+/\@,

Try it online!

,*+/\@, Flatten the matrix, then multiply the flatten by the scan sum of the flatten.
({' '&,)~ Prepend a space to the replacement chars, and the index into that using the result of the previous step.

Mathematica, 76 bytes
""<>(s=#2;f:=(s=RotateLeft[s];Last[s]);Map[If[#1,f," "]&,#,{2}]~Riffle~"\n")&

Unnamed function of two arguments, the first of which (#) is an array of Trues and Falses, and the second of which (s) is a list of characters. The helper function
f:=(s=RotateLeft[s];Last[s])

is defined, which puts the moves the first character of s to the end and then returns that just-moved character. Calling f several times will cyclically return the characters of s in order.
The core function is
Map[If[#1,f," "]&,#,{2}]

which calls f on every True value in the input array and returns a space on every false input. (The {2} tells Map to work on elements of the array's component lists, rather than those lists themselves.)
Those 60 bytes return an array of characters-of-s and spaces. The wrapper
    ""<>(...~Riffle~"\n")&

puts newlines between each of that array's lists and then concatenates everything.

C++, 61 bytes
for(auto&i:m){for(int&j:i)cout<<(j?s[k++%l]:' ');cout<<'\n';}

Ruby, 52 bytes
->a,s{i=-1
a.gsub(/(0)|1/){$1?" ":s[(i+=1)%s.size]}}

Attempt This Online!

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Smallest number of contiguous monotonic subsequences
A monotonic subsequence is a sequence of numbers \$a_1, a_2, ..., a_n\$ such that
$$a_1 \le a_2 \le ... \le a_n \\
\text{or} \\
a_1 \ge a_2 \ge ... \ge a_n$$
[1, 3, 3, 7, 9, 13, 13, 100] is a monotonic (non-decreasing) subsequence, as well as [9, 4, 4, 3, 0, -10, -12] (this one is non-increasing), but [1, 3, 6, 9, 8] is not. Given a list of integers (in any reasonable format), output the smallest number N such that the sequence of these integers can be split into N monotonic sequences.
Examples
[1, 3, 7, 5, 4, 2] -> [[1, 3, 7], [5, 4, 2]] -> 2
[1, 2, 3, 4, 5, 6] -> [1, 2, 3, 4, 5, 6]     -> 1
[3, 1, 5, 5, 6]    -> [[3, 1], [5, 5, 6]]    -> 2
[4, 6, 8, 9, 1, 6] -> [[4, 6, 8, 9], [1, 6]] -> 2
[3, 3, 3, 3]       -> [[3, 3, 3, 3]]         -> 1
[7]                -> [[7]]                  -> 1
[]                 -> []                     -> anything (you don't actually have to handle an empty list case)
[1, 3, 2, -1, 6, 9, 10, 2, 1, -12] -> [[1, 3], [2, -1], [6, 9, 10], [2, 1, -12]] -> 4

To clarify, the subsequences must be contiguous, right?

@Zgarb Yes, they do.

I'd recommend adding a test case where the sequences don't always go in the reverse direction:  [4,4,8,8,1,4,5] -> 2

@NathanMerrill: Good point, added one.

When you write that for an empty string, the result is 0 / undefined, it sounds like it should be either 0 or the representation of undefined in our language, but from your comment on Jonathan Allan's Jelly answer, it looks like undefined means anything... Which one is it? In the second case, I would suggest writing anything instead of undefined

@Dada: I'm never good at getting the niceties of challenges right. It's a valid point though, I'll update the description.

@shooqie Ok it's much clearer now. Don't worry, neither am I, so I won't blame you!

Brachylog, 12 bytes
~c:{<=|>=}al

Try it online!
This returns false. for the empty list [].
Explanation
(?)~c                 Take a list of sublists which when concatenated result in the Input
     :{<=|>=}a        Each sublist must be either increasing or decreasing
              l(.)    Output is the length of that list

This will return the smallest one because ~c will generate choice points from the smallest number of sublists to the biggest.

What is the argument "Z" in the TIO link? (It seems to be part of the program like a command line argument would).

@JonathanAllan This argument is the output. Ideally if we could customize TIO's interface, there would be the Input and the Output and no arguments. The argument is Z because Z is a variable name; so we are saying "call this program with the Output as a variable". You can change Z to any other uppercase letter; it's just a variable name. The reason this argument exists is to allow the possibility of actually setting the output to something, instead of a variable.

(For example if you set the Output to 4 in that example, it will tell you if that is correct or not)

Hmm, rather confusing, are there other languages that do this? Why is it not just the default behaviour to output the result? Also, why does setting this output argument to 5 return "true.", and setting it to 3 cause TIO to hang?

@JonathanAllan Any Prolog like language is like this: predicates can only succeed or fail and do not return any value. So to get an output one has to have a variable argument to the predicate which will get unified to the result.

@JonathanAllan It will eventually fail for 3 because it wont find any list of sublists where all are monotonic and of length 3. It just takes a long time because it will try all possible lists of sublists, even those that are actually longer than 3 elements because the length is checked after finding the list. For 5 it says true because there is indeed at least one list of length 5 with monotonic sublists that works. So this program returns the smallest length when the output is a variable and whether there is any list of that length that works if the output is an integer.

Cool thanks for the in-depth explanation!

Perl, 65 bytes
62 bytes of code + 3 bytes for -n flag.
monot_seq.pl :
#!perl -n
s/\S+ /($_<=>$&)*($&<=>$')-$g>=0?$g=1:$.++;$g--;$_=$&/ge,$_=$.

Give the input without final newline, with the numbers separated by spaces :
$ echo -n "1 3 2 -1 6 9 10 2 1 -12" | perl -M5.010 monot_seq.pl
4

-5 bytes thanks to @Gabriel Benamy.

Save 5 bytes by turning ($&<=>$1)*($1<=>$2)||$1==$2 into ($&<=>$1)*($1<=>$2)>=0

@GabrielBenamy Indeed, thanks.

Perl, 98 97 96 79 bytes
($a,$b)=($a<=>$b)*($b<=>$c)<0?($c,shift,$d++):($b,$c)while$c=shift;say$d+1 if$a

Input is provided as a list of numbers, separated by spaces, provided at runtime, e.g.
perl -M5.010 monotonic.pl 1 3 2 -1 6 9 10 2 1 -12
4

(the 4 is the output)
Readable:
($a,$b)=($a<=>$b)*($b<=>$c)<0
    ?($c,shift,$d++)
    :($b,$c)
  while$c=shift;
say$d+1
  if$a

The 'spaceship operator' <=> returns -1 if LHS < RHS, 0 if LHS = RHS, and +1 if LHS > RHS.  When comparing three sequential elements $a,$b,$c to determine if they're monotonic, it's only necessary to determine that it's not the case that exactly one of $a<=>$b,$b<=>$c is 1 and the other is -1 -- which only happens when their product is -1.  If either $a==$b or $b==$c, then the sequence is monotonic, and the product is 0.  If $a < $b < $c, then both result in -1, and -1 * -1 = 1.  If $a > $b > $c, then they both result in 1, and 1 * 1 = 1.  In either case, the sequence is monotonic, and we wish to continue.
If the product is less than 0, we know that the sequence is not monotonic, and we discard the values of $a,$b we're currently holding, and increment our subsequence counter.  Otherwise, we move forward one number.
Returns nothing if the input is empty, otherwise returns the smallest number of contiguous monotonic subsequences

You don't need a space between 1 and if (or maybe you do on old perls, but on recent ones you don't). Also you can (probably) replace shift by pop. However, there are some test cases on which your code doesn't work : 6 3 6 3 (you print 3 instead of 2), 4 3 2 1 (you print 2 instead of 1). Using pop instead of shift solve those but create new ones (1 2 3 4 prints 3 instead of 1)...

Mathematica, 111 bytes
d=#[[2]]-#[[1]]&;r=Rest;f@{n_}:=1;f@k__:=If[d@k==0,f@r@k,g[k Sign@d@k]];g@{n_}:=1;g@k__:=If[d@k>0,g@r@k,1+f@r@k]

Named function f taking a nonempty list of numbers (integers or even reals). Works from front to back, discarding the first element repeatedly and keeping track of how many subsequences are needed. More verbose:
d = #[[2]] - #[[1]] &;         function: difference of the first two elements
r = Rest;                      function: a list with its first element dropped
f@{n_} := 1;                   f of a length-1 list equals 1
f@k__ := If[d@k == 0, f@r@k,   if the first two elements are equal, drop one
                                 element and call f again ...
            g[k Sign@d@k]];  ... otherwise call the helper function g on the
                                 list, multiplying by -1 if necessary to ensure
                                 that the list starts with an increase
g@{n_} := 1;                   g of a length-1 list equals 1
g@k__ := If[d@k > 0, g@r@k,    if the list starts with an increase, drop one
                                 element and call g again ...
            1 + f@r@k];        ... otherwise drop one element, call f on the
                                 resulting list, and add 1

d=#2-#&@@#&; also, defining either f or g as the unary operator ± will probably save some bytes.

Jelly, 19 bytes
IṠḟ0E
ŒṖÇ€€0e$Ðḟḅ1Ṃ

TryItOnline! or run all tests (empty list results in 1)
How?
IṠḟ0E - Link 1, test for monotonicity: a sublist
I     - incremental differences
 Ṡ    - sign {fall:-1; same:0; rise:1}
  ḟ0  - filter out the zeros
    E - all equal?

ŒṖÇ€€0e$Ðḟḅ1Ṃ - Main link
ŒṖ            - all partitions of the input list
  Ç€€         - call last link (1) as a monad for €ach for €ach
        Ðḟ    - filter out results:
       $      -    last two links as a monad
     0e       -        contains zero?
          ḅ1  - convert from unary (vectorises)
            Ṃ - minimum

(I'm not convinced that this is the most suitable method to minimise byte count though)

@shooqie - May we return any value for the empty list given the "undefined" comment? This returns 1 (which I actually think makes more sense than 0).

I mean, that's what undefined means - the result is irrelevant.

JavaScript (ES6), 69 bytes
f=(d,c,b,...a)=>1/b?(d>c)*(b>c)+(d<c)*(b<c)?1+f(b,...a):f(d,b,...a):1

Takes input as multiple parameters. Works by recursively comparing the first three elements to see whether they are monotonic, if so, removes the middle element as it is useless, if not, removes the first two elements and starts a new sequence.

C#6, 297 209 bytes
using System.Linq;int G(int[] a)=>a.Any()?a.SkipWhile((x,i)=>i<1||x>=a[i-1]).Count()<a.SkipWhile((x,i)=>i<1||x<=a[i-1]).Count()?G(a.Select(x=>-x).ToArray()):G(a.SkipWhile((x,i)=>i<1||x<=a[i-1]).ToArray())+1:0;

Ungolfed with explanations
int G(int[] a)=>
    a.Any()
        ?a.SkipWhile((x,i)=>i<1||x>=a[i-1]).Count()<a.SkipWhile((x,i)=>i<1||x<=a[i-1]).Count()   // If a begins by decreasing (including whole a decreasing)...
            ?G(a.Select(x=>-x).ToArray())   // ... Then flip sign to make a begins by increasing
            :G(a.SkipWhile((x,i)=>i<1||x<=a[i-1]).ToArray())+1   // ... Else skip the increasing part, recursively find the remaining part number, then add 1
        :0;   // Return 0 if a is empty

Clojure, 97 bytes
#((reduce(fn[[C i]s](let[S(conj C s)](if(or(apply <= S)(apply >= S))[S i][[s](inc i)])))[[]1]%)1)

reduce keeps track of the current subsequence and calculates how many times <= and >= conditions fail. Last 1 takes 2nd element from the result (being the counter i).

Jelly, 11 bytes
ŒṖỤ€IṠƑƊƇẈṂ

Try it online!
Empty list yields 1
How it works
ŒṖỤ€IṠƑƊƇẈṂ - Main link. Takes an array A on the left
ŒṖ          - Yield all partitions of A
       ƊƇ   - Keep those partitions for which the following is true:
   €        -   Over each sublist in the partition:
  Ụ         -     Grade up; Sort its indices by its values
    I       -   Increments
      Ƒ     -   Is this invariant under:
     Ṡ      -     Convert to sign

                This (ṠƑ) is a trick that returns 1 if the list contains only
                -1, 1 and 0s. As we're working with the indices, not the values,
                we will never have duplicate elements, and so no 0. The increments
                will either be all 1 or -1 iff the ordered indices are in directly
                ascending or descending order, i.e. the values are sorted in
                either ascending or descending order

         Ẉ  - Get the lengths of each kept partition
          Ṃ - Get the minimum

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Do n and n^3 have the same set of digits?
Given a number n (0 <= n <= 2642245), check if n and n3 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, so the code with the fewest bytes wins.
OEIS A029795

Proposed test case: 106239

Test case: 2103869 -> True. This (or a larger one) is necessary to test a language with a long datatype.

Too bad the max is too big for language without a 64 bit integer type.

I think you should be explicit about the base... in binary it's kinda half the fun :-D

@TheVee Decimal is the default base for challenges involving digits in numbers.

@Dennis why so many "upvotes"? I may have missed the point, but I'm interested.

@ZoltánSchmidt 106239 is the smallest positive integer n such that n³ – 1199090390129919 – does not contain all digits of n. Some answers were only checking if n contained all digits of n³ and thus got the wrong result for 106239.

@Dennis ooooh, clever! Thanks!

@edc65 - Too bad the max is so small that 64-bit integers are sufficient.

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.

@Emigna No, you wouldn't be able to add a string and an integer.

@daHugLenny You can't use the set(...) function, though.

In python 2 you can use backtics as a shortcut for repr(), saving 6 bytes. set(\x`)`

@DenDenDo Any input larger than 2097152 (sys.maxint**(1/3.)) and less than sys.maxint+1 will return False if you use repr(). https://repl.it/EXs2/1. Longs have an L at the end.

Untested, but you can probably do lambda x:{*str(x)}=={*str(x**3)} in Python 3.5+.

@Copper You can do that? I never realised! Thanks!

The {*...} trick is cool! But why does the code need to be prefixed with lambda x:? Is making it a function part of the question?

@BenHoyt It's more concise than using print(...) and input(). Making it a function is shorter than making a full program.

Because the question says returning a truthy or falsy value is enough, you can replace == by ^. Two equal sets lead to {} which is falsy.

@RemcoGerlich Wouldn't I then have to switch truthy and falsy around?

@J843136028: yes, of course, sigh. Never mind.

I suppose you could bitflip the falsy to make it truthy and vice versa... but then it would be the same number of characters.

I would specify that this works in python 3. 5 and after...

@Bakuriu I never realised. Thanks!

05AB1E, 6 bytes
05AB1E uses CP-1252 encoding.
3mê¹êQ

Try it online!
Explanation
3m       # input^3
  ê      # sorted with duplicates removed
     Q   # is equal to
   ¹ê    # input sorted with duplicates removed

@PuzomorCroatia: 05AB1E uses the CP-1252 encoding, so all these characters are 1 byte each. It is quite common for golfing languages to either use code pages with more printable characters than UTF-8 or alternatively create their own code page.

Thanks for the answer. Unfortunately, while trying to edit my comment, I deleted it. Just to make things clear to everyone, I asked about encoding of characters in code golfing languages

@Emigna 05AB1E technically uses its own code page, even though it's pretty much identical to CP-1252.

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);
}

The ungolfed code is missing 1 << when setting the bits with k |= 1 << i % 10. Great solution!

I used this bitmap idea to make a 39 byte x86-64 machine code function :)

Are we allowed to consider 0 as truthy?  I guess strcmp works that way, so it seems reasonable in C.

This only works for the entire range of inputs required by the question if int larger than 64-bit.  (Even signed 64-bit is not enough, but unsigned 64-bit is).  So there are no real implementations of C that I know of where this satisfies the question's requirements.  (It does work correctly with unsigned long long, or just unsigned long in implementations where that's a 64-bit type).  GNU C defines __int128_t on 64-bit machines (without any headers)...

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.

Nice answer! You can still save a few (3) bytes : perl -pe '$_=$_**3!~/[^$_]/'

@Zaid Thanx. Fixed.

Now it outputs false for 10 :(

@Zaid Yep. -l flag needed.

Change the && to a * to save a byte

Mathematica, 34 bytes
f=Union@*IntegerDigits;f@#==f[#^3]&

Direct implementation (unnamed function of one integer argument).

Jelly, 8 bytes
,3*\D‘ṬE

Try it online! or verify all test cases.
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.

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.

it's terrible that there isn't a nicer way to compare sets for equivalence

@njzk2 Well, I'd say the greater tragedy is that == doesn't work even on arrays.

You can save a byte by changing n*n*n to n**3, but I guess that might be ES7 and not ES6.

Perhaps use \${[...new Set( ... ).sort()}`` if that saves bytes

@Downgoat Thanks, that inspired me to save some more bytes!

The last parenthesis is too many, isn't it?

@Huntro Indeed it is. I copied that from my testing environment, which surrounds the expression in parens.

This fails for 2103869, and the problem explicitly requires solutions to work up to 2642245.

@user5090812 Shouldn't this because of the precision in JS cannot handle number of that size? Say 2103869**3 = 9.30E+18 > 2**53

Does n=>(f=s=>[...new Set(s+[])].sort()+9)(n)==f(n*n*n) work as we don't require the compared string be pure?

CJam, 8 bytes
l_~3#s^!

Test suite.
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.

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+""));};

Can you check p<0 instead of p==1?

@TuukkaX Would've done that, but the way I'm determining the sets now is using the same array of integers, incrementing the appropriate index for both strings, so a value of 0 or 2 is okay, but if any are 1, it should return false.

Save very little by extracting the creation and filling of the arrays into a separate lambda: n=>{Func<string,int[]>x=s=>{var a=new int[10];foreach(var c in s)a[int.Parse(c+"")]++;return a;};var i=x(n);var j=x((long)Math.Pow(int.Parse(n),3)+"");for(var k=0;k<10;)if(i[k]>0^j[k++]>0)return 0>1;return 1>0;};

You can replace int.Parse(c+"") with c-'0'

Fails test case 2103869. I ran into the same issue. (Nevermind, I found out why. I'd used a long instead of ulong and this test case uses the MSB.)

@SaxxonPike So it turns out if I take the input as a ulong instead of a string, it works.  The problem is with Math.Pow() returning a double, so if I just do I*I*I it works as long as I is a ulong.  It actually saves bytes doing it this way too because no more Math.Pow() call ^.^

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).

That static Y y thing is a weird initialisation syntax, does it autoassign to y.n because the interface has exactly one member?

I believe so, yes. To be honest I'm newish to Java 8 since my workplace is still on 7, but that's how I perceive it to work.

The compiler automatically adds the @FunctionalInterface annotation (interface with only one method, see javadoc) which makes lambdas work instead of the usual anonymous type instantiation.

This is essentially equal to Y y = new Y() { @Override public boolean n(int x) { return Arrays.equals((a+"").chars().distinct().sorted().toArray(),(new BigInteger(a+"").pow(3)+"").chars().distinct().sorted().toArray()); } } and the staticmodifier is only there to allow calling y.n(int) from the static main method.

Why not a*a*a instead of .pow()?

Oh, just realized signed 64-bit isn't enough :(

Nice answer! +1 Btw, imports/usings are unfortunately also part of the byte-count, so it should be a->java.util.Arrays.equals((a+"").chars().distinct().sorted().toArray(),(new java.math.BigInteger(a+"").pow(3)+"").chars().distinct().sorted().toArray());

@KevinCruijssen I was under the impression that that would only be necessary for full programs?

Nevermind, just read the meta post about this and it seems the community agrees. I suppose I can see why. I will update.

Nice solution! You can use Try it online! to share your answer. It even counts your answer as 1 Byte shorter.

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.

Does Haskell not have set literals, or a function which returns the unique elements from a list?

@cat No. Haskell has nub (get unique elements) and sort, but both require the lengthy import import Data.List. Even so, it comes very close at 48 bytes: import Data.List;q=sort.nub.show;f n=q n==q(n^3).

Why the need to sort...?

@cat nub preserves order by first appearance, i.e. nub [3,1,3,2,1,2] == [3,1,2]. It doesn't convert to a set type (there is none), but gives a list.

Oh, I never realised Haskell doesn't have a primitive unordered collection type, that makes sense

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)

I'm afraid the base theory is completely wrong here. Try T <<< 11. Will say the digit sets are the same just because 11**3 == 1331 contains the digits not present in the original number twice.

Yep, you are correct, fixed ! Thank you !

Ok, but now some extra spaces left in the code. Not sure why you added the -w explicitly to fold. If uniq is used without options, sort -u can replace it. And feed the 2nd S call with here-string. And I think there is no need to quote the formula passed to bc.

@manatwork, thx, I've fixed the fold argument, removed spaces, and made the second diff argument use a here-doc.
I now also pipe the first argument into diff, and have removed the superfluous quotes around the bc expression.

uniq is used without options, sort -u can replace it.
That's just a remnants of previous version (was uniq -u)).

Thank you !

@zeppelin: you can use cmp instead of diff and save 1 byte.

@Ipor - that's a nice idea, I will look into this, thx !

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.
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.

Code golf in machine code? That's true mastery!

@chx: It's really in assembly language, optimizing for code size.  I don't write the hex bytes directly, I just know (or check on) what size each instruction is.  (What I posted is from assembling with yasm and then running objdump -drwC -Mintel on the object file, and copying comments).  It's a language where optimizing for code size is actually useful in real life.  (But even then, only in rare cases like bootloaders or demos.  Usually it's only worth saving code size when it doesn't hurt performance in the already-cached case, but then it is useful avoid decode bottlenecks + cache misses)

@chx: but yes, golfing in asm does make me feel like a badass, thanks for noticing :)  See my other answers, here and on SO :)

I am a very old hat in assembly (1987, Z80 was the first) but I would've never thought to enter into code golf with that. I would've thought impossible.

@chx: I only golf occasionally, usually only when I see one in Hot Network Questions that looks reasonable for asm.  Usually stuff with numbers, not strings.  A few other people do golf in asm, though.  I hadn't thought of doing so myself until I saw someone else's machine-code golf answer.  Might have been this one that clued me in to the fact that you can count machine code bytes instead of asm source characters for asm answers.  anatolyg has posted some, including on this question.

Nice work, that BTS instruction really saves the day!

@KarlNapf: yeah, IDK why compilers don't use it more often.  It's fast on Intel CPUs with a register destination.  (1 uop, 1c latency, can run on multiple ALU execution ports on Intel SnB-family (source).  It's 2 m-ops on AMD Bulldozer-family, but that's still cheap.  The funny thing about it is how slow it is with a memory destination: cheaper to load / bts / store separately, because of its crazy-CISC bitstring behaviour with a memory operand: the address read/written  depends on the source operand!

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

Declaring a%b=all(elema)b as a function and then calling with b%a&&a%b should save two bytes.

Dyalog APL, 10 bytes
⍕≡⍕∪(⍕*∘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!
Note: For large numbers, set ⎕PP←34 ⋄ ⎕FR←1287 (34 significant digits, 128 bit floats)

You're assuming that the unique digits in n^3 can't be fewer than those in n?

Can you prove the existence of a counter-example?

106239, see comments at the top

Clojure, 35 bytes
#(=(set(str %))(set(str(* % % %))))

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.)

Imports/usings are indeed part of the byte-count. You can remove the static  though.

Okay thanks. Removed static.

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))

Sadly this wont work (for large n) unless you use some kind of BigInt package. See ?.Machine for details on the biggest integer and float etc. To see this compare e.g. 2600001^3 in R to wolframalpha

I've never had to use it myself but it seems like the gmp package could solve this problem.

Ah, good catch! I've updated the answer, it now uses gmp::as.bigz() to handle large integers.

you could make use of the fact substring converts to a character to split the number, eg s=substring;setequal(s(n<-gmp::as.bigz(scan()),p<-1:1e4,p),s(n^3,p,p))

@MickyT Fantastic suggestion! I didn't know substring could be used that way (I've only ever used substr). Answer has been edited to incorporate your suggestion now.

Given the range of possible inputs, p<-1:99 (or even p<-1:20) is sufficient, yielding -1 byte.

Jelly, 8 bytes
*3ṢQ⁼ṢQ$

Try it online!
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'

This doesn't work with input 100.

I understand why it doesn't, but why doesn't this work?

Because Jelly is strictly parsed left to right, without operator precedence. *3ṢQ⁼ṢQ$ works as intended, since the quick $ groups the two atoms to its left into a monadic chain.

Perl 6, 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 returns an empty 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.

You can replace the $_ with just .

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;
}

You need to include #include<set> and using namespace std; in the golfed code and byte count

@cat #include<set> instead of algorithm

@KarlNapf oh, I thought all the stdlib containers were acessible through algorithm -- shows what I know about C++ :)

It seems to me the variable local to the function "c"  is not initialized but used c|=1 ...

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, works for big numbers (call with L suffix).

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.
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.

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()

main() using first program argument: 88 bytes
fun main(a:Array<String>){val i=a[0].toLong();println("$i".toSet()=="${i*i*i}".toSet())}

main() using standard input: 96 bytes
fun main(a:Array<String>){val i=readLine()!!.toLong();println("$i".toSet()=="${i*i*i}".toSet())}

Welcome to PPCG! The input/output is implicitly specified because of the [tag:code-golf]. You can see the community-consensus standards here. Your function count should be sufficient.

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.

Ruby, 48 bytes
->n{(f=->x{x.to_s.chars.uniq.sort})[n]==f[n**3]}

Shaved 6 bytes: ->n{(f=->x{x.digits.sort|[]})[n]==f[n**3]}

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 -equal 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

you can use "$n"[0..99] instead of [char[]]"$n" to save one byte, since the biggest number you'll need to deal with is only about 20 chars in length.

@ConnorLSW There's that indexing trick again. I'm going to need to remember that.

as long as you're guaranteed to be using less than 100 characters it's an easy enough save over the normal char[] conversion, the rest of your code is as good as I could get it, if there was a shorthand way to compare arrays, you could use something like ("$n"[0..99]|group).Name to save loads but compare isn't exactly quick and easy to golf.

That's what I get for solving it without looking at the answers ... Pretty much the same answer ;-). But you missed a few very obvious optimizations ;-)

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.

Can't you save a byte here using s$n^3?

@ais523: No, because it translates to (s n==s) (n^3) which gives a type error.

Brachylog, 11 bytes
doI,?:3^doI

Try it online!
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

I like the cat smiley in this :3

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!

Hello Rado, and Welcome to PPCG! This is a great first answer, +1!

I managed to squeeze it even further to 47 chars/bytes by using a closure, but can't edit my previous answer due to being new here, so here it is:
def c={"$it".toSet()=="${it.power(3)}".toSet()}

Anonymous functions are acceptable. And use the ** operator for exponentiation.

Thanks @NoOneIsHere! Also, calling the closure for test cases would involve replacing x(107624) with c.call(107624)

Thank you @manatwork! Using an anonymous closure and ** brings it down to beautiful 35 chars/bytes: {"$it".toSet()=="${it**3}".toSet()}

C#, 86 characters
using System.Linq;i=>(i*i*i+"").All((i+"").Contains)&&(i+"").All((i*i*i+"").Contains);

Because it is a lambda, in practical use, you will need to assign it to type Func<decimal, bool>. This should, according to MSDN, be useful until you go beyond 28 digits on the i*i*i calculation. If you use the BigInteger package, you can theoretically go to however many digits you have memory for. Just substitute BigInteger for decimal. The function itself does not change.
nUnit Test:
using System;
using System.Linq;
using NUnit.Framework;

namespace CodeGolf
{
    [TestFixture]
    public class CodeGolfTestFixture
    {
        [TestCase(0, true)]
        [TestCase(1, true)]
        [TestCase(10, true)]
        [TestCase(107624, true)]
        [TestCase(251894, true)]
        [TestCase(251895, false)]
        [TestCase(102343, false)]
        [TestCase(106239, false)]
        [TestCase(2103869, true)]
        public void Test(int inp, bool expectedResult)
        {
            Func<decimal, bool> subject = i =>
                (i*i*i + "").All((i + "").Contains) &&
                (i + "").All((i*i*i + "").Contains);
            var observedResult = subject(inp);
            Assert.AreEqual(expectedResult, observedResult);
        }
    }
}

Some other C# golfing exercises do not have using System.Linq. I'd like to discuss its requirement. For example: http://codegolf.stackexchange.com/a/84789/62301

Lua, 55 bytes
Takes input on the command line.
Makes n into a character class and tests the string n ^ 3 against it.
a=arg[1]print(not("%u"):format(a^3):find("[^"..a.."]"))

Factor, 37 bytes
[ dup 3 ^ [ 10 >base unique ] bi@ = ]

(passing) Tests:
: func ( x -- ? ) dup 3 ^ [ number>string unique ] bi@ = ;
{ t } [ 0 func ] unit-test
{ t } [ 1 func ] unit-test
{ t } [ 10 func ] unit-test
{ t } [ 107624 func ] unit-test
{ t } [ 251894 func ] unit-test
{ f } [ 251895 func ] unit-test
{ f } [ 102343 func ] unit-test

Factor, 32 bytes
[ dup 3 ^ [ present ] bi@ set= ]

Try it online!

dup Make a copy of the input.
Stack (e.g.): 100 100

3 ^ Cube.
Stack: 100 1000000

[ present ] bi@ Convert them both to strings.
Stack: "100" "1000000"

set= Are they equal when viewed as sets?
Stack: t

Vyxal, 3 bytes
3e⊍

Try it Online!
An empty set is truthy and a set with items is falsey. If that ain't an acceptable format for output:
4 bytes
3e⊍¬

Try it Online!
Explained
3e⊍
3e  # input ^ 3
  ⊍ # symmetric set difference between the above and input
    # ¬ will negate that result, making it either `0` or `1`

Pyke, 10 bytes
3^`}SR`}Sq

Try it here!

Pyth, 11 10 bytes
It was difficult for me to find a function to convert to a string while searching the online tutorial. I just guessed ` and was right. I suppose this site is better for searching.
q.{`^Q3.{`

Try it online
Explanation
     Q          evaluated input (implicit Q at the end as well)
    ^  3        cubed
   `      `     str() - it's actually repr, but doesn't have an 'L' at the end of longs
 .{     .{      convert each string to set()
q               check if equal
                implicit print

vz is Q and you can remove the last z

srry you need a ` instead of the z

still get 10 tho

also the tutorial is super out of date, I would recommend using the table at https://pyth.herokuapp.com/ which is always current.

to the third power, you can overflow the repr

@Maltysen I already linked that in my answer.

@njzk2 This works differently than Python's. There is still no L, even if the result is a long. Try it yourself with input of 2103869.

dc, 69 bytes
This takes input from top of stack, and leaves a result on top of stack.  The result is the count of symmetric difference between the digit sets, so zero indicates true, and other numbers indicate false.
d[O~1r:ad0<f]dsfx+3^[O~1r:bd0<f]dsfxsaO[1-ddd;ar;b-d*la+sad0<m]dsmxla

Explanation
Expanded version as commented full program with I/O to standard streams:
#!/usr/bin/dc

# read input
?

# store 1 in a[i] for each digit i
d[O~
  1r:a
  d0<f]dsfx
# cube the original number
+3^
# record its digits in b[]
[O~
 1r:b
 d0<f]dsfx

# 0 left on stack used to initialize accumulator
sa
# for i in 9..0, add (b[i]-a[i])^2
# accumulate in register 'a'
O[1-d
  dd;ar;b-d*
  la+sa
  d0<m]dsmx

# load result from accumulator
la

# print output
p

I hoped I could re-use the first function to store to both a[] and b[] but I couldn't find an easy way to do it.  Arrays can't be pushed or popped, and it was too hard to add an indirection to the function.
Test results
Here's the test cases from the question, plus those suggested in comments:
0 -> 0
1 -> 0
10 -> 0
107624 -> 0
251894 -> 0
251895 -> 4
102343 -> 6
106239 -> 1
2103869 -> 0

And here's the first 50 terms of A029795, of 536 that I identified with this program by testing the numbers up to ten million:
0
1
10
100
1000
10000
100000
107624
109573
132485
138624
159406
165640
192574
205738
215806
251894
281536
318725
419375
427863
568314
642510
713960
953867
954086
963218
965760
1000000
1008529
1023479
1023674
1026258
1028537
1028565
1028756
1032284
1035743
1037689
1039725
1045573
1046783
1062851
1062854
1063279
1063724
1066254
1072399
1073824
1076240

C#, 87 bytes
Inspired by @Yodle, but I can't put a comment on his answer because I lack the reputation, I just parsed the string in a separate variable, this saves 5 characters:
var n=long.Parse(i);return new HashSet<char>(i).SetEquals(new HashSet<char>(n*n*n+""));

Can you strip the spaces around =?

thanks @Oliver, how do I count the bytes?

I used this site.

Are you missing an using to generic namespace?

@LinkNg what exactly are the requirements, I tried to find it on the website but couldn't.

From this meta and the links therein, the program/function should be compilable. In C# you need to add using System.Collections.Generic;, or qualify both HashSet<char> to be System.Collections.Generic.HashSet<char>, or put your program/function in this namespace, or use using alias. TBH I found it challenging to golf in C# while considering namespaces.

CJam, 15 bytes
I know it's not the best answer, but it is my first one:
l:Fi3#s$L|FL|$=

Explanation:
l            Read input
 :F          Put it in the var F
  i          Convert to int
   3#        Raise to the 3rd power
    s        Back to a string
     $       Sort
      L|     Remove dupes
       FL|   Remove dupes from the original input
        $    Sort
         =   Check if they are equal

Welcome to PPCG!

MKSH (BASH) ,3̶9̶ 4̶1̶ 3̶6̶ 5̶2̶  46 bytes
(38 bytes without printing return value)
3g.sh:
c=`bc<<<$1^3`;[ ${c//[$1]}${1//[$c]} ];echo $?

Usage from file:
$ mksh 3g.sh 100
1
$ mksh 3g.sh 11
0
$ mksh 3g.sh 251894
1

Or from command line displaying return value outside (38 bytes):
$ mksh -c 'c=`bc<<<$0^3`;[ ${c//[$0]}${0//[$c]} ]' 2103869;echo $?
1
$ mksh -c 'c=`bc<<<$0^3`;[ ${c//[$0]}${0//[$c]} ]' 102343;echo $?
0
$ mksh -c 'c=`bc<<<$0^3`;[ ${c//[$0]}${0//[$c]} ]' 106239;echo $?
0

My question: is my 2nd oneliner a valid solution? The result should be printed on terminal or is it enough in an invisible return value? ( I'm new to codegolf. )

Welcome to PPCG! You don't get to define what is true and false. Generally, 1 is true, and 0 is false. http://meta.codegolf.stackexchange.com/questions/2190/interpretation-of-truthy-falsey

So, then i have to add 2 more bytes. :-/

@mbomb007 But this is Bash. Bash defines 0 as truthy and everything else as falsy. And the meta question you link seems to agree with me: truthy and falsy should be understood relative to the language.

Then perhaps the answer body should be edited to clarify that.

does not work for 106239

@zeppelin: corrected

@Ipor 106239 still returns 1, 106239^3=
1199090390129919 (note the lack of "6")

@zeppelin: auch, thx! I misunderstood the task a bit.

Batch, 202
@set/an=%1,c=n*n*n,e=1
@for /l %%a in (0,1,9)do @call:l %%a
@exit/b%e%
:l
@set f=1
@call set s=%%n:%1=%%
@if "%s%"=="%n%" set/af=1-f
@call set s=%%c:%1=%%
@if "%s%"=="%c%" set/af=1-f
@set/ae*=f

Note: Only works up to 1290 due to the limited range of Batch's data type. Takes input on the command line and returns an error level of 1 if the cube uses the same set of digits, 0 otherwise. Works by looping through each digit, checking to see whether an even number of the two strings contains the digit.

DASH, 33 bytes
@=(f\ss[sort I;unq;str])#0f ^#0 3

Usage:
(@=(f\ss[sort I;unq;str])#0f ^#0 3)500

Explanation
@
  =                       #. check if the following are equal
    (f\                   #. store the following to f:
      ss[sort I;unq;str]  #. composition of to string, unique, sort
    )
      #0                  #. apply f to the arg
    f ^ #0 3              #. apply f to arg cubed

ES6 (Javascript), 32, 58 bytes
Golfed
n=>(x=(a,b)=>!RegExp(`[^${a}]`).test(b))(m=n*n*n,n)&x(n,m)

Test
N=n=>(x=(a,b)=>!RegExp(`[^${a}]`).test(b))(m=n*n*n,n)&x(n,m)

N(0)
1 (true)

N(1)
1 (true)

N(10)
1 (true)

N(107624)
1 (true)

N(251894)
1 (true)

N(251895)
0 (false)

N(102343)
0 (false)

N(106239)
0 (false)

You need to check set equality, not just subset - see Dennis' comment on the main post for the test case 106239.

That is true, will fix it now, thanks !

n*n*n can be written n**3

@hoosierEE, no, not in ES6, unfortunately

Scala, 57 chars
def n(x:BigInt)=x.toString.toSet==(x*x*x).toString.toSet

I'm not fluent in Scala, but shouldn't it be possible to remove the whitespace around the various =s?

yes I'm new to code golf

PowerShell 3+, 72
filter f{"$("$_"[0..99]|sort -u)"}(($a=[long]$args[0])|f)-eq($a*$a*$a|f)

Pretty much the same solution idea as TimmyD had, just a lot shorter (and arrived at independently). I also think there aren't that many more obvious PowerShell solutions to this.

You should specify that this is v3+ for the -Unique parameter on the Sort-Object. Otherwise, nice tricks.

Convex, 6 bytes
3#sê^!

Try it online!
Well, I guess major bugs in some operators can help in golfing sometimes...

Python 2,  36 33 bytes
lambda x:set(`x`)==set(str(x**3))

Can't use backticks (repr) on large numbers because it includes the 'L'.

Python 3, 61 Bytes
n=input()
print([i for i in str(int(n)**3)if i not in n]==[])

Or in python 2 (60 Bytes):
n=input()
print[i for i in str(n**3) if i not in str(n)]==[]

This would be shorter as a lambda: lambda n:[i for i in str(n**3) if i not in str(n)]==[]

@Oliver I haven't used lambda much before, so I don't know much about how to use it. However, I will bear this in mind if I need it for a future challenge.

Pushy, 13 10 bytes
V3esuFsux#

Try it online!
Like most other answers here, it just generates sets for both numbers and checks for equality:
     \ Implicit: Input on stack 1
V    \ Copy into stack 2
3e   \ Cube (stack 1)
su   \ Split into digits and create sorted set
Fsu  \ ^ Do the same to the second stack (not cubed)
x#   \ Check cross-stack equality and output (0 or 1)

Mathematica 31 Bytes
(f=Sign@*DigitCount)@#==f[#^3]&

because Sign<Union and DigitCount<IntegerDigits

Pyt, 8 bytes
Đ³ąỤ⇹ąỤ\

Try it online!
Outputs an empty list if true

Đ³ąỤ⇹ąỤ\
            Implicit input
Đ           Duplicate input
 ³          Cube
  ą         Make array of digits
   Ụ        Filter so you have no duplicates
    ⇹       swap
     ąỤ     make array of digits and filter duplicates
       \    set difference

This fails for 106239.

Brachylog, 9 7 bytes
d.&^₃dp

Try it online!
-2 bytes thanks to Fatalize for fixing the interaction between zero and p.
The predicate succeeds if the input has the same set of digits as its cube, and fails otherwise. If run as a standalone program, success prints true. and failure prints false.
d          The input with duplicates removed
 .         is the output variable
  &^₃      and the input cubed
     d     with duplicates removed
      p    is a permutation of the output variable.

The interaction between 0 and p has been fixed in the latest commit. The 7 bytes d.&^₃dp should now work properly (once the commit is pulled on TIO).

MathGolf, 9 7 bytes
ⁿαÉ▒▀z=

Try it online!
-2 bytes thanks to KevinCruijssen. By changing the map to a for loop, we save one byte from not having to do a map (m), and another byte from not having to dump the array onto the stack (~).
Explanation
ⁿ         pop a : push(a*a*a)
 α        wrap last two elements in array
  É       start block of length 3
   ▒      split to list of chars/digits
    ▀     unique elements of string/list
     z    reverse sort(array)
      =   pop(a, b), push(a==b)

Ah, hadn't noticed there was already a MathGolf answer. I've deleted mine again. You can golf 2 bytes with ⁿαÉ▒▀z=.

@KevinCruijssen Even I had forgotten about this answer, good catch!

Pari/GP, 35 bytes
n->(d=i->Set(digits(i)))(n)==d(n^3)

Try it online!

Husk, 9 bytes
¤=ȯOud¹^3

Try it online!

Japt -!, 4 bytes
³skU

Try it here
³skU     :Implicit input of integer U
³        :Cubed
 s       :Convert to string
  kU     :Remove all digits that appear in U
         :Convert to integer, resulting in NaN if all digits were removed
         :Implicit output of negation of result

What does the ! Flag do?

Negates the output, @Razetime.

This fails for 106239.

GolfScript, 6 bytes
.~3?^!

Try it online!
.        # Copy the input                "102343" "102343"
 ~       # Parse it to an integer        "102343" 102343
  3?     # Cube it                       "102343" 1071949756947607
    ^    # Get the different digits      "237956"
     !   # Is it an empty string?        0

Thunno 2, 2 bytes
³ḍ

Try it online!
Output with inverted booleans - add the ! flag to take the logical NOT of the result.
Explanation
    # Implicit input
³   # Cube it
 ḍ  # Symmetric set difference
    # Implicit output

Julia 40 bytes
 h(x)= ==(Set.(digits.([x,big(x)^3]))...)

Test:
h.([0,1,10,107624,251894,251895,102343,106239,2103869])
9-element Array{Bool,1}:
  true
  true
  true
  true
  true
 false
 false
 false
  true

big(x) requires few bytes than Int128(x)

thanks, i forgot big was availble as a function (rather than just as a string macro)

Julia, 34 bytes
!n=symdiff("$n",dec(big(n)^3))==[]

How does it work? Well, strings act like arrays in many ways, so we can apply the symdiff (symmetric difference) function to a pair of strings to get an array of all characters found in only one of the two strings. If that is an empty array ([]), then the set of digits is the same.
big is used to make sure it handles larger values of n^3 (anything that would overflow in 64 bit), although it will still be limited in terms of n itself (but easily covers the range required).

Pyth - 9 bytes
Hopefully can take another char off.
@I.{`^Q3`

Test Suite.
!          Negation, tells if set is empty
 -         Setwise subtraction
  `^Q3     String repr of input^3
  `        String repr of implicit input

This fails for input 106239.

C#6, 117 118 115 bytes
using System.Linq;bool A(ulong n){string s=n+"",t=n*n*n+"";return s.All(x=>t.Contains(x))&t.All(x=>s.Contains(x));}

Praise System.Linq.Enumerable
+1 byte due to long range problem
-3 bytes by storing strings to variable
Ungolfed + explanations
bool A(ulong n)
{
    // Convert n and n^3 to strings
    string s=n+"",t=n*n*n+"";
    // Two sets are equal iff:
    // Foreach element in one set, it is also present in another set
    return s.All(x=>t.Contains(x))&t.All(x=>s.Contains(x));
}

PHP, 48 bytes
<?=($f=count_chars)($a=$argv[1],3)==$f($a**3,3);

It's the first time I've assigned a function to a variable like this and I'm honestly quite surprised that it works.

It works in PHP 7, yes, not in PHP 5. Also, this throws a notice because count_chars should be in apostrophes or double quotes. https://3v4l.org/UsWn4

@chx I know, what I was really surprised about was being able to do it in line. As for the notice, ignoring notices is standard practise in PPCG and learning what strings you can use without the quotes is a decent start for golfing PHP.

45 +1 bytes with -F flag and $argn instead of $argv[1]

Actually, 12 bytes
3ßⁿk`$╔S`Mi=

Try it online!
Explanation:
3ßⁿk`$╔S`Mi=
3ßⁿ           copy of input, cubed
   k          [input, input**3]
    `$╔S`M    for each:
     $          stringify
      ╔         remove duplicate elements
       S        sort
          i=  flatten and compare equality

J, 18 bytes
-:&(/:~)&~.&":^&3x

I think this is the most&s I've used in an answer to date. This is a fork:
-:&(/:~)&~.&": ^&3x

The verb on the right, ^&3x, raises the argument to the 3rd power, converting to an extended number if necessary. Then, the verb on the left takes right arg (cubed arg) and left arg (arg). & applies the verb following to each argument, then passes each argument to the preceding function. So, this is:
-:&(/:~)&~.&":
            ":  string representation
         ~.     unique elements
   (/:~)        sorted
-:              are the same

Test cases
   f=:-:&(/:~)&~.&":^&3x
   (,. f"0) 0 1 10 107624 251894 251895 102343
     0 1
     1 1
    10 1
107624 1
251894 1
251895 0
102343 0
   f 251894
1
   f 251895
0

Holy... this was the best I could do: (]([=(~.@,)&.":)[:x:3^~]) (25 bytes, or 23 if you don't count the parens)

Swift 3, 75 bytes
func a(n:UInt64){print(Set("\(n)".characters)==Set("\(n*n*n)".characters))}

C#
Without any 32 or 64 bit limits...
Func<BigInteger,bool> x = n => !(n * n * n + "").Except(n + "").Any();

You can drop the function name and type signature - unnamed lambdas are acceptable. Additionally, you have a lot of whitespace that can be removed. Remember, in code golf, you're trying to make your code as short as possible.

Thanks @Mego, I saw this question at Hot Network Questions But I think I have to read some docs before posting next answer...

Actually, 10 bytes
This answer uses the direct approach, using str(), sort(), uniq() on n then n**3 directly. Golfing suggestions welcome! Try it online!
$S╔3ßⁿ$S╔=

Ungolfing
      Implicit input n.
$S╔   str(), sort(), uniq() on n.
3ßⁿ   Push n**3.
$S╔   str(), sort(), uniq() on n**3.
=     Check if the results are equal.
      Implicit return.

bash, 42
[[ $1 = +([$((a=$1**3))])&&$a = +([$1]) ]]

test with 2103869

@IporSircer plenty of other answers are limited by the language's limits

Scala, 34 bytes
i=>s"$i".toSet==(""+(i*i*i)).toSet

Usage:
val f:(BigInt=>Boolean)=...
print(f(2103869))

Explanation:
i=>            //define an anonymous function with a parameter i
    s"$i"        //use string interpolation to convert i to a string
    .toSet       //convert the string to a set of chars
  ==           //is it equal to...
    (
    ""+(i*i*i)   //i*i*i as a string
    ).toSet      //as a set of chars

Matlab/Octave, 39 bytes
a=@(x)(unique(num2str(x)));min(a(x)==a(x^3))

== will give an error if the numbers of unique digits are different  (maybe use isequal). Also, this would require x to be of type uint64 in order to work across the specified input range; you should indicate it in your answer. You can remove the parentheses around unique. In addition, the general rule is that your code should be a full program or a function (i.e. define the second part as an anonymous function or use input()).

Axiom, 92 76 bytes
g(y:String):String==removeDuplicates(sort(y));f(x)==(g(x)=g((x^3)))::Boolean

results
->[i,f(i)] for i in [0,1,10,107624,251894,251895,102343,106239]

  [[0,true], [1,true], [10,true], [107624,true], [251894,true],
   [251895,false], [102343,false], [106239,false]]

This produces a false positive for 106239 (the Dennis test case).

@zeppelin ok i wrote a new version... thank you

Python, 88 bytes
lambda n:reduce(lambda x,y:x*y,map(lambda x:x[0]in str(x[1]),[(i,n)for i in str(n**3)]))

Worked in version 2.7.9.
This lambda lambda x:x[0]in str(x[1]) receives a tuple, which first element is an char and the second element is a integer. This function checks if the char is in the string correspondent to the integer.
This [(i,n)for i in str(n**3)] creates a set of arguments, for each character of the string of n³, and function  map evaluates the lambda function for each argument of the set. Then, the result is a list of booleans that tell if each character of the string of n³ is in the string of n. The reduce and the lambda reduce(lambda x,y:x*y,...) multiplies all the elements of the list, returning 1 if all the characters of the string of n³ are in the string of n and 0 otherwise.
A 89 bytes solution with a similar idea but with different implementation is:
lambda n:len(filter(lambda x:x[0]in str(x[1]),[(i,n)for i in str(n**3)]))==len(str(n**3))

Here, filter literally filter the elements of the set of arguments that leads the internal lambda function to returns True. The resulting list has its length compared to the length of the string of n³ to check if all the characters of the string of n³ are in the string of n.

Clojure, 109 bytes
(use '[clojure.string :only(split)])#(if(= (into #{}(split(str %)#""))(into #{}(split(str(* % % %))#"")))1 0)

Use the function like this:
...(#(...) 106239)

Yikes, that is a long one-liner.
Ungolfed:
(use '[clojure.string :only (split)])
(defn cube [n]
  (if (= (into #{} (split (str n) #""))
         (into #{} (split (str(* n n n)) #"")))
    1 0))

APL NARS 29 chars
{(⍵>2e6)∨⍵<0:¯1⋄''≡(⍕⍵)§⍕⍵*3}

f has meaningful result only if 0<=arg<=2000000 else if arg>=2098567 (so i wrote 2000000 for round)
it miss digits as float with result can not be meaningful...So if arg of f is out 0<=arg<=2000000
it return the error number ¯1
  f←{(⍵>2e6)∨⍵<0:¯1⋄''≡(⍕⍵)§⍕⍵*3}
  f¨ 0 1 10 107624 251894 251895 102343
1 1 1 1 1 0 0
  f 2000000
0
  f 2000001
¯1
  f ¯9
¯1

Clojure 35 bytes
#(every?(set(str %))(str(* % % %)))

Same byte count as an earlier answer, but slightly different approach.
More obscure but unfortunately longer:
#(apply =(map(comp set str)[%(* % % %)]))

Alice, 15 bytes
/D.n~@
\iXDo/3E

Try it online!
Prints Jabberwocky as a truthy result and nothing as a falsy result (Alice's canonical truthy and falsy values in Ordinal mode).
Explanation
/   Switch to Ordinal mode.
i   Read all input as a string.
.D  Duplicate the string and then deduplicate the characters of the copy,
    turning it into the set of digits.
~   Swap with the other copy.
/   Switch to Cardinal mode.
3E  Implicitly convert the string to the represented integer value N and raise
    it to the third power.
\   Switch to Ordinal mode.
D   Implicitly convert N^3 to a string and deduplicate its characters as well.
X   Symmetric multiset difference. Gives an empty string iff both strings
    are permutations of each other. The fact that Alice only has multiset
    oprations is the reason why we needed to use D on both strings.
n   Logical NOT. Turns the empty string into the (truthy) "Jabberwocky"
    and everything else into the (falsy) empty string.
o   Output the result.
@   Terminate the program.

Add++, 12 bytes
L,d3^BD€q=

Try it online!
How it works
L,		; Define a lambda function
		; Example argument:         [106239]
	d3^	; Push n³;          STACK = [106239 1199090390129919]
	BD	; Get the digits;   STACK = [[1 0 6 2 3 9] [1 1 9 9 0 9 0 3 9 0 1 2 9 9 1 9]]
	€q	; Deduplicate €ach; STACK = [{0 1 2 3 6 9} {0 1 2 3 9}]
	=	; Equal?	    STACK = [0]

Stax, 9 bytes
à±▒!⌂▼▒RÜ

Run and debug online!
Explanation
Uses the unpacked version to explain.
cJ*EuxEu|n!
cJ*            Raise to 3rd power (can also be `3|*`)
   Eu          Discrete digits
     xEu       Discrete digits of input
        |n!    Array xnor

JavaScript ES7, 48 bytes from Downgoat 's

F=
n=>(f=s=>[...new Set(s+f)].sort()+f)(n)==f(n**3)

console.log([0,1,10,107624,251894,251895,102343].map(F))

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/