# Cubic Concatenation

## Challenge

Given three non-negative integers $$\a, b\$$ and $$\c\$$, decide if the sum of their cubes is equal to the concatenation of those numbers, aka: $$a^{3}+b^{3}+c^{3} = a^\frown b ^\frown c$$

## Test cases

Truthy

(1,5,3) // 1^3 + 5^3 + 3^3 = 153
(2,2,13)
(4,0,7)
(10,0,0)
(10,0,1)
(22,18,59)
(98,28,27)
(166,500,333)
(828,538,472)


Falsy

(1,2,3) // 1^3 + 2^3 + 3^3 = 32 != 123
(4,5,6)
(6,0,0)
(166,500,334)
(200,0,200)


You can assume there are no leading zeroes.

This is , so the shortest code wins.

• Could you define concentration in the question please
– Simd
Commented Aug 5 at 11:03
• @Simd Sorry, did you make a typo?
– Blue
Commented Aug 5 at 11:08
• From your test cases I assume leading zeroes don't count? Commented Aug 5 at 11:37
• @Jitse well, I didn't include any test cases with leading zeroes because it may cause issues with, for example, "001" being different from "1" and I just wanted people to focus on writing shortest code without getting into edge cases too much.
– Blue
Commented Aug 5 at 11:51
• Yes, I meant concatenation.
– Simd
Commented Aug 5 at 12:36

# Python 3, 36 bytes

lambda*I:eval(3*"%d"%I+3*"-%d**3"%I)


Try it online!

eval golf of @Jitse's answer who generously declined to include it in their post. Returns zero for True and nonzero integer for False.

# R, 30 29 bytes

Edit: -1 byte thanks to @Kirill L..

\(x)x^2%*%x==Reduce(paste0,x)


Attempt This Online!

• Save a byte with dot product Commented Aug 5 at 18:59

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

• *3S -> ḋ² for 4 Commented Aug 5 at 14:04
• Very nice golf @UnrelatedString, I often use the dot-product too so should really have thought of this one. Thank you! Commented Aug 5 at 16:54

# Python 3, 44 bytes

lambda x:sum(map(pow,x,[3]*3))-int(3*'%d'%x)


Try it online!

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


Try it online!

• You can flip truthy and falsey with == -> -. Commented Aug 5 at 12:03
• Commented Aug 5 at 12:41
• @Albert.Lang amazing! I'll leave it to you to submit it as a separate answer Commented Aug 5 at 12:46
• @david With the space there, the dot is parsed as an attribute accessor instead of a decimal separator. More here. Commented Aug 7 at 8:10
• Shorter to do map(pow,x,[3]*3) in the second answer
– xnor
Commented Aug 10 at 10:01

# Uiua, 1714 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⟜⍜°⋕/⍚⊂


• 14 without the function pack: =/+××..⟜⍜°⋕/⍚⊂ Commented Aug 5 at 13:07
• I think ××.. is just ⁿ3
– ovs
Commented Aug 5 at 13:20
• This =/+ⁿ3⟜⍜°⋕/◇⊂ is what I had came up with when this was first posted to the Sandbox but I didn't see the challenge is already posted... I'm too slow and I had prep time! Commented Aug 8 at 17:59
• @noodleperson Nice! I needed a lot of help to get to the same result Commented Aug 8 at 20:34

(==).show.sum.map(^3)<*>(>>=show)


Try it online!

• sum.map(^3) is the sum of the cubes
• show.sum.map(^3) is stringifies the sum
• (>>=show) is concatMap show, i.e. concatenetes the numbers
• <*> feeds the input to both arguments
• I tried non-pointfree and it also came to 33 bytes: Try it online!
– xnor
Commented Aug 6 at 5:54

# Vyxal, 6 bytes

ṅ?3e∑=


Try it Online!

    ∑  # Sum
3e   # of cubes
?     # of input
= # Is equal to
ṅ      # Concatenation of input?


# APL (Dyalog Unicode), 16 bytes

+.*∘3=∘⍎∘∊⍕¨


Try it online!

+.*∘3 sum of cubes

=∘⍎∘∊ equal to the execution of the enlisted (flattened)

⍕¨ stringification of each

# JavaScript (Node.js), 32 bytes

(a,b,c)=>a**3+b**3+c**3==[a]+b+c


Try it online!

Nothing to say.

• Concatenating a number to a list coerces them to string? Obvious in hindsight :) Commented Aug 6 at 6:44

# Julia, 2624 23 bytes

-n="$(n'n.^2)"==join(n)  Attempt This Online! Thanks to ovs for -2 and further -1 by Ashlin Harris. • Your TIO link for the 0.6 version doesn't actually test that function and I can't get it to work? Anyway, I think n'*n.^2 should work in both julia versions if you pass input as arrays instead of tuples – ovs Commented Aug 5 at 19:48 • @ovs Oops, my bad. Anyway, the older version is no longer needed as it becomes the same length. Thanks! Commented Aug 5 at 20:18 • Julia supports implicit multiplication, so you don't need the * operator. Commented Aug 5 at 21:53 # K (ngn/k), 17 bytes {(,/$x)~$+/x*x*x}  Try it online! # Google Sheets, 31 bytes =SUMPRODUCT(A:A^3)=--JOIN(,A:A)  # Brachylog, 7 bytes ^₃ᵐ+~c?  Try it online! ### Explanation ^₃ᵐ Map cube on the input list + The sum of these cubes… ~c? …can be deconcatenated into the original input list  # 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. Try it online! 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. Try it online! # 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. Try It On Desmos! Try It On Desmos! - Prettified • 60: c(x,y)=x*10^{ceil(log y)}+y[NEWLINE]f(x,y,z)=c(x,c(y,z))-x^3-y^3-z^3 (I'm not that experienced with Desmos golf, this can probably be a little less) Commented Aug 7 at 11:17 • Actually disregard that it doesn't play nice with zeros, there's probably a trick somewhere though Commented Aug 7 at 11:20 • c(x,y)=x*10^{floor(log(y+0^y))+1}+y[NEWLINE]f(x,y,z)=c(c(x,y),z)-x^3-y^3-z^3 seems to work for 68, since leading zeros won't happen Commented Aug 7 at 11:24 • @emanresuA Wait what??? You can assume there's only three numbers inputted????? Commented Aug 7 at 22:40 • Man they gotta make three bolded, I just skipped right over that word. Commented Aug 7 at 23:00 # 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 # Perl 5-MList::Util=sum -ap, 27 bytes $_=y/ //dr==sum map$_**3,@F  Try it online! # Red, 41 bytes func[a][(sum a * a * a)= do rejoin to[]a]  Try it online! 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  # 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  ## 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. Try it online! ## 33 bytes Thanks @Neil and @tsh for the shorter version! a=>a.map(x=>s-=x**3,s=a.join)|s  • I think a.join works. – Neil Commented Aug 9 at 7:44 • By default, decision-problem on this site allow truthy vs falsy output, and swap meaning of true and false is allowed. So you could use - to replace your ==. Combine with Neil's idea. It could be stripped into 35 bytes: a=>a.reduce((x,y)=>x-y**3,a.join) – tsh Commented Aug 9 at 9:24 • And switch to map could save two more bytes: a=>a.map(x=>s-=x**3,s=a.join)|s – tsh Commented Aug 9 at 9:26 • @tsh I forgot that arrow functions do not have their own scope. That's clever! Commented Aug 10 at 10:07 # MathGolf, 5 bytes ‼yⁿΣ=  Try it online. 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)  # Japt, 5 bytes x³¥U¬  Try it here x³¥U¬ :Implicit input of array U x :Sum of ³ : Cubes ¥ :Loosely equal to U¬ : U joined to a string  # ARBLE, 21 bytes a^3+b^3+c^3-(a..b..c)  0 for truthy, non-zero for falsey. Try it online! Run all tests! # APL+WIN, 17 bytes Prompts for integers. (⍎∊⍕¨s)=+/(s←⎕)*3  Try it online! Thanks to Dyalog Classic # Arturo, 31 bytes $->a->=do join a∑map a=>[&^3]


Try it!

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


# Setanta, 84 66 bytes

gniomh(a,b,c){toradh a*a*a+b*b*b+c*c*c==go_uimh(nasc@[a,b,c](""))}


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

Try it online

# C++, 186165 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)

Try it online!

• that's fair, didn't see that. give me a second
– Redz
Commented Aug 5 at 11:15
• @emanresuA fixed
– Redz
Commented Aug 5 at 11:19
• You can save 16 bytes with cout<<(d==stoi(x)); Commented Aug 5 at 11:41
• You can get rid of d altogether! cout<<(a*a*a+b*b*b+c*c*c==stoi(x));
– Blue
Commented Aug 5 at 12:06
• @Blue thanks! good point :P
– Redz
Commented Aug 5 at 22:12

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

# Ruby, 30 bytes

->a{a.sum{|x|x**3}.to_s==a*''}


Try it online!

• I have almost the same, but two bytes can be golfed by replacing |x|x with _1 Attempt This Online! Commented Aug 6 at 7:33