| Bytes | Lang | Time | Link |
|---|---|---|---|
| 174 | C gcc | 250205T214150Z | ayaan098 |
| 015 | APLNARS | 250205T164422Z | Rosario |
| 004 | Jalapeño | 250204T045214Z | ATaco |
| 066 | Desmos | 250202T201559Z | DesmosEn |
| 024 | AWK | 241118T203645Z | xrs |
| 008 | Husk | 240911T135516Z | int 21h |
| 056 | Clojure | 240903T145603Z | NikoNyrh |
| 023 | Excel | 240902T003953Z | Taylor R |
| 021 | ARBLE | 240902T052222Z | ATaco |
| 045 | PowerShell Core | 240902T014340Z | Julian |
| 067 | Desmos | 240807T110745Z | Aiden Ch |
| 021 | AWK | 240816T165950Z | C K |
| 005 | Japt | 240805T213825Z | Shaggy |
| 030 | Wolfram Language Mathematica | 240816T130445Z | att |
| 108 | Go | 240812T134950Z | bigyihsu |
| 005 | MathGolf | 240812T122351Z | Kevin Cr |
| 006 | 05AB1E | 240812T122020Z | Kevin Cr |
| 044 | Python 3 | 240805T113213Z | Jitse |
| nan | Javascript V8 | 240808T085636Z | Bean Sea |
| 031 | JavaScript Node.js | 240809T093310Z | tsh |
| 038 | Lua | 240808T221837Z | chunes |
| 023 | Julia | 240805T185155Z | Kirill L |
| 120 | Java JDK | 240808T172230Z | David Co |
| 006 | Stack control 1.1 | 240805T134633Z | Швеев Ал |
| 033 | gnuplot | 240807T072811Z | int 21h |
| 015 | J | 240807T003850Z | Jonah |
| 028 | Bash | 240805T233522Z | Digital |
| 033 | Bash | 240806T200247Z | Donat |
| 009 | Charcoal | 240806T184802Z | Neil |
| 054 | Retina | 240806T184613Z | Neil |
| 009 | Pyth | 240806T180054Z | int 21h |
| 041 | MATLAB | 240806T120345Z | rst |
| 007 | Brachylog | 240806T082821Z | Fatalize |
| 030 | Ruby | 240806T070523Z | G B |
| 029 | R | 240805T133004Z | pajonk |
| 043 | Windows Batch | 240806T063618Z | user3141 |
| 146 | C++ | 240805T110722Z | Redz |
| 041 | Red | 240805T215259Z | chunes |
| 052 | Kotlin 52 Bytes | 240805T213724Z | colmmurp |
| 027 | Perl 5 MListUtil=sum ap | 240805T193346Z | Xcali |
| 045 | Factor | 240805T171144Z | chunes |
| 004 | Jelly | 240805T115728Z | Jonathan |
| 066 | Setanta | 240805T152743Z | bb94 |
| 031 | Arturo | 240805T145757Z | chunes |
| 031 | Google Sheets | 240805T145357Z | z.. |
| 033 | Haskell | 240805T142051Z | DPD- |
| 017 | K ngn/k | 240805T135303Z | akamayu |
| nan | Uiua | 240805T125637Z | mousetai |
| 036 | Python 3 | 240805T125107Z | Albert.L |
| 017 | APL+WIN | 240805T122405Z | Graham |
| 032 | JavaScript Node.js | 240805T112622Z | l4m2 |
| 016 | APL Dyalog Unicode | 240805T110728Z | Adá |
| 006 | Vyxal | 240805T110401Z | emanresu |
C (gcc), 174 bytes
char c[99];j;k;
#define F(x)atoi(x)*atoi(x)*atoi(x)
main(int a,char**v){strcpy(c,v[1]);while(k++-2)strcpy(c+(j+=strlen(v[k])),v[k+1]);exit(atoi(c)!=F(v[1])+F(v[2])+F(v[3]));}
APL(NARS), 15 chars
{(∊⍕¨⍵)≡⍕+/⍵*3}
test:
{(∊⍕¨⍵)≡⍕+/⍵*3}10 0 0
1
~
{(∊⍕¨⍵)≡⍕+/⍵*3}10 0 1
1
~
{(∊⍕¨⍵)≡⍕+/⍵*3}¨(1 5 3)(2 2 13)(4 0 7)(828 538 472)
┌4───────┐
│ 1 1 1 1│
└~───────┘
{(∊⍕¨⍵)≡⍕+/⍵*3}¨(1 2 3)(4 5 6)(6 0 0)(166 500 334)
┌4───────┐
│ 0 0 0 0│
└~───────┘
Jalapeño, 4 bytes
J=Σₓ³
Explained
J=Σₓ³
J # Join (implicit input) together
= # Is equal to
Σₓ # The sum of (implicit input) mapped by
³ # Cubed
Hex-Dump of Bytecode
0 1 2 3 4 5 6 7 8 9 A B C D E F
0000: 14 59 ea 62
Desmos, 66 bytes
d(n)=10^{floor(log(n+0^n))+1}
f(a,b,c)=a^3+b^3+c^3-c-d(c)(b+d(b)a)
This solution evolved very close to Aiden Chow's solution, but it does improve it by one byte. 0 represents truthy outputs, any any other integer represents falsey.
AWK, 24 bytes
$0=$1^3+$2^3+$3^3~$1$2$3
awk '$0=$1^3+$2^3+$3^3~$1$2$3' << "1 5 3"
Prints 1 if truthy, or nothing.
Husk, 8 bytes
=dṁd¹ṁ^3
Takes a list of numbers and outputs 1 (truthy) "if the sum of their cubes is equal to the concatenation of those numbers", otherwise 0 (falsy).
Explanation:
ṁ^3 # sum up the cubes
ṁd¹ # split every number into its digits and flatten the list
d # join digits back into a single number
= # check for the equality
Clojure, 56 bytes
#(=(seq(str(apply +(for[i %](* i i i)))))(mapcat str %))
TIO. This was surprisingly painless, thanks to str and mapcat. Takes the input as a list of numbers.
Excel, 23 Bytes
An anonymous workbook function that takes input from a vertical array at A1# and outputs to the calling cell
--(A1&A2&A3)=SUM(A1#^3)
Previous Version, 24 bytes
A slightly more elegant solution that uses the Concat builtin
--CONCAT(A1#)=SUM(A1#^3)
Sample Output
For the input array ={1;5;3} outputs the following
PowerShell Core, 45 bytes
-join$args-(($args|%{"$_*"*3+1})-join'+'|iex)
Takes 3 integers as parameters
Returns \$0\$ for true, otherwise false=
Desmos, 81 67 bytes
-14 bytes thanks to @emanresu A due to the fact that I didn't realize that it was always guaranteed to be exactly 3 numerical inputs. I was originally solving for an arbitrary amount of numerical inputs.
c(x,y)=x10^{floor(log(y+0^y))+1}+y
f(x,y,z)=c(c(x,y),z)-x^3-y^3-z^3
Returns 0 for truthy and a non-zero integer for falsey.
Japt, 5 bytes
x³¥U¬
x³¥U¬ :Implicit input of array U
x :Sum of
³ : Cubes
¥ :Loosely equal to
U¬ : U joined to a string
Go, 108 bytes
import."fmt"
func f(a,b,c int)bool{n:=0
Sscanf(Sprintf("%d%d%d",a,b,c),"%d",&n)
return a*a*a+b*b*b+c*c*c==n}
MathGolf, 5 bytes
‼yⁿΣ=
Explanation:
‼ # Apply the next two operands separately on the (implicit) input-triplet:
y # Join them together
ⁿ # Take the cube of each
Σ # Sum the triplet of cubes
= # Check if the two lists are the same
# (after which the entire stack joined together is output implicitly)
05AB1E, 6 bytes
3mOIJQ
Try it online or verify all test cases.
The 3m could alternatively be ** or n* for the same byte-count; or the order could be swapped to JI3mOQ as well:
Try it online.
Explanation:
3m # Take the cube of each value in the (implicit) input-triplet
O # Sum those together
I # Push the input-triplet again
J # Join them together
Q # Check if the two are the same
# (after which the result is output implicitly)
Python 3, 44 bytes
lambda x:sum(map(pow,x,[3]*3))-int(3*'%d'%x)
-1 byte thanks to Jonathan Allan
-2 bytes thanks to xnor
Returns truthy (nonzero integers) for False cases and falsey (zero integers) for True cases.
Python 3, 45 bytes
lambda a,b,c:a**3+b**3+c**3-int(f'{a}{b}{c}')
Javascript (V8), 40 bytes
a=>a.reduce((x,y)=>x+y**3,0)==a.join('')
where a is number[], so it should work for any number of arguments.
33 bytes
Thanks @Neil and @tsh for the shorter version!
a=>a.map(x=>s-=x**3,s=a.join``)|s
JavaScript (Node.js), 31 bytes
(x,y,z)=>[x]+y+z-x**3-y**3-z**3
A boring trivial solution is short...
Java (JDK), 120 bytes
t->t.stream().mapToInt(x->x*x*x).sum()==Integer.parseInt(t.stream().map(Object::toString).collect(Collectors.joining()))
I'm not sure if the import of java.util.List needs to be counted. The predicate takes a List and some old advice says that all the types for lambdas need to be included, with any imports, but in JShell it is imported by default and in JDK 23 (which is currently only a preview edition) you also get it for free in a Java program that is all in one file (you can even skip declaring a class or having a full public-static-void-main), but TIO doesn't support JShell or recent versions of Java.
Stack control 1.1, 6 characters
:³+⇆◡=
Explanation
: - duplicates original array
³ - cubes every array element
+ - sum of array elements
⇆ - swap to another array
◡ - reversed concatenates values from array
= - check if values are equals
gnuplot, 33 bytes
f(a,b,c)=a**3+b**3+c**3=="".a.b.c
A function that inputs 3 integer values and outputs 1 if their sum of cubes is equal to the concatenation of those numbers, otherwise the output is 0.
Bash, 28
Sometimes the simple solution is best:
(($1**3+$2**3+$3**3^$1$2$3))
This script takes a list as command-line parameters as input. e.g. ./cubeconcat.sh 1 5 3. It returns a shell exit code: 1 for True, 0 for False.
Previous, overcomplicated solution:
Bash, 37
(($(eval printf %s +\$[$1**3] ^ $1)))
This script takes a single quoted brace-enclosed, comma-separated list as input. e.g. ./cubeconcat.sh "{1,5,3}". It returns a shell exit code: 1 for True, 0 for False.
Bash, 33 bytes
[ $1$2$3 = $[$1**3+$2**3+$3**3] ]
The script returns a shell exit code: 1 for True, 0 for False.
Charcoal, 9 bytes
⁼I⪫θωΣXθ³
Try it online! Link is to verbose version of code. Takes input as an array and outputs a Charcoal boolean, i.e. - if the sum of cubes equals the concatenation, nothing if not. Explanation:
θ Input array
⪫ Joined by
ω Predefined variable empty string
I Cast to integer
⁼ Equals
θ Input array
X Vectorised raised to power
³ Literal integer `3`
Σ Take the sum
Implicitly print
Retina, 54 bytes
,(\d+),(\d+)
$1$2,$.(***_$2*$2*$2*_$`*$`*$`*
^(.+),\1$
Try it online! Link includes test cases. Explanation:
,(\d+),(\d+)
Match the first number in $`, the second number in $1 and the third number in $2.
$1$2,$.(***_$2*$2*$2*_$`*$`*$`*
Concatenate the input numbers, then compute the sum of the cube of $1 (implicitly because it's the first number in the match), the cube of $2 and the cube of $`. (Retina 1 will do this calculation using arbitrary-precision integers as it knows it will be converting the result back to decimal.)
^(.+),\1$
Check that the two results are the same.
Pyth, 9 bytes
qsjkQsm**
First time golfing in Pyth, so this might be not optimal.
Explanation:
sm** calculates the sum of the cubes;
jkQ joins the list elements into a string and s converts the result to a number;
q: are the values equal?
MATLAB, 41 bytes
f=@(x)sum(x.^3)==str2num(sprintf('%d',x))
An @-function that accepts input as column vector.
>> f([828;538;472])
ans =
logical
1
>> f([200;0;200])
ans =
logical
0
Brachylog, 7 bytes
^₃ᵐ+~c?
Explanation
^₃ᵐ Map cube on the input list
+ The sum of these cubes…
~c? …can be deconcatenated into the original input list
Windows Batch, 43 bytes
cmd/cset/a%1*%1*%1+%2*%2*%2+%3*%3*%3-%1%2%3
Prints 0 for truthy, <>0 for falsy.
Sorry, no TIO available; save as C:\Temp\cg274690.cmd or whatever.cmd, run from cmd.exe or PowerShell:
C:\Temp\cg274690.cmd 1 5 3
Ungolfed:
cmd.exe /c set /a %1 * %1 * %1 + %2 * %2 * %2 + %3 * %3 * %3 - %1%2%3
This starts another instance of cmd.exe, as using set /a inside a batch script requires an assignment, which would then have to be echoed out, for a total of 49 bytes (using LF as EOL):
set/ax=%1*%1*%1+%2*%2*%2+%3*%3*%3-%1%2%3
echo %x%
set /a used interactively inside a cmd prompt (or passed with /c) prints the result directly.
C++, 186 165 146 bytes
#include<iostream>
using namespace std;int main(){int a,b,c;cin>>a>>b>>c;cout<<(a*a*a+b*b*b+c*c*c==stoi(to_string(a)+to_string(b)+to_string(c)));}
(-16 thanks to Mousetail) (-19 thanks to Blue)
Red, 41 bytes
func[a][(sum a * a * a)= do rejoin to[]a]
Takes input as a vector of three numbers. Vectors support arithmetic with multiple values at once, but not powers.
Explanation
func[a][ ; start function taking argument a
(sum a * a * a) ; sum of cubes
= ; does it equal...
to[]a ; input converted to regular list
rejoin ; concatenated to string
do ; evaluated (converted to integer)
] ; end function
Kotlin 52 Bytes
{it.map{it*it*it}.sum()-it.joinToString("").toInt()}
Accepts a List<Int> and outputs zero for true and a non-zero integer for false.
Factor, 46 45 bytes
[ 4 dupn v* v. swap "%d%d%d"vsprintf dec> = ]
Explanation
[ ! start function
4 dupn ! put 4 total copies of input list on stack
v* ! multiply top two
v. ! dot product w/ third
swap ! put input on top
"%d%d%d"vsprintf ! concat all three to string
dec> ! to number
= ! check equality
] ! end function
Jelly, 5 4 bytes
-1 thanks to Unrelated String! (*3S {cube then sum} -> ḋ² {dot-product with squared values}.)
ḋ²⁼V
A monadic Link that accepts a list of non-negative integers (with or without any leading zeros*) and yields 1 if the list concatenates to the sum of the cubes of its elements or 0 if not.
Try it online! Or see the test-suite.
How?
ḋ²⁼V - Link: list, A = [a, b, c]
² - square {A} -> [a², b², c²]
ḋ - {A} dot-product {that} -> a³+b³+c³
V - evaluate {A} as Jelly code -> concatenated integer *
⁼ - {SumOfCubes} equals {that}?
* Leading zeros produce a side effect of printing zeros before yielding the result.
Setanta, 84 66 bytes
gniomh(a,b,c){toradh a*a*a+b*b*b+c*c*c==go_uimh(nasc@[a,b,c](""))}
Arturo, 31 bytes
$->a->=do join a∑map a=>[&^3]
Explanation
$->a-> ; a function taking a list named a
= ; are the following two values equal?
do join a ; concatenation of input as a number
∑ ; and sum of...
map a=>[&^3] ; inputs cubed
Google Sheets, 31 bytes
=SUMPRODUCT(A:A^3)=--JOIN(,A:A)
Haskell, 33 bytes
(==).show.sum.map(^3)<*>(>>=show)
sum.map(^3)is the sum of the cubesshow.sum.map(^3)is stringifies the sum(>>=show)isconcatMap show, i.e. concatenetes the numbers<*>feeds the input to both arguments
Uiua, 17 14 12 chars
-3 chars thanks to Chunes by replacing fork with on
-2 chars thanks to OVS because I missed the existance of a power operator
=/+ⁿ3⟜⍜°⋕/⍚⊂
Python 3, 36 bytes
lambda*I:eval(3*"%d"%I+3*"-%d**3"%I)
eval golf of @Jitse's answer who generously declined to include it in their post.
Returns zero for True and nonzero integer for False.
APL (Dyalog Unicode), 16 bytes
+.*∘3=∘⍎∘∊⍕¨
+.*∘3 sum of cubes
=∘⍎∘∊ equal to the execution of the enlisted (flattened)
⍕¨ stringification of each
Vyxal, 6 bytes
ṅ?3e∑=
∑ # Sum
3e # of cubes
? # of input
= # Is equal to
ṅ # Concatenation of input?
