Am I a Secondary Taxicab?

13

2

Background

Ramanujan's number, 1729, is called a taxi-cab number due to the (possibly apocryphal) tale of Hardy boarding a cab to visit Ramanujan in hospital having this number, which seemed bland to him.

It's since known as the most famous of a class of integers known as "taxicab numbers" which are expressible as the sum of two nth powers (of positive integers) in two (or sometimes 'k') different ways.

1729 is the smallest natural number expressible as the sum of 2 cubes in 2 different ways, making it the first "3,2" taxicab number ("n,k" being general).

Challenge

Given a number, decide whether it is a "3,2" 'secondary taxicab number' - meaning it fulfills the same constraint as 1729 (2 unique sums of cubes), but does not have to be the smallest such integer of the "3,2" class (that being 1729, of course).

Example cases:

1729 = 10^3 + 9^3 = 12^3 + 1^3

4104 = 15^3 + 9^3 = 16^3 + 2^3

13832 = 2^3 + 24^3 = 18^3 + 20^3

As well as 20683, 32832, 39312...

Scoring

This is , so the shortest answer in each language wins.

Rough Matlab code to find other cases by brute force:

for k = 1729:20000
    C = sum(round(mod(real((k-[1:ceil(k^(1/3))].^3).^(1/3)),1)*10000)/10000==1);
    if C > 1
        D = (mod(C,2)==0)*C/2 + (mod(C,2)==1)*((C+1)/2);
        disp([num2str(k),' has ',num2str(D),' solns'])
    end
end

DrQuarius

Posted 2017-06-14T02:56:22.133

Reputation: 562

Welcome to PPCG! I edited your question a bit to make it a bit more clear. Would you be willing to add some test cases? – musicman523 – 2017-06-14T02:59:21.150

Yep, I was struggling because I'm at work and don't have Matlab, but managed to get Octave online to work and found 4104=16^3+4^3=15^3+9^3 – DrQuarius – 2017-06-14T03:11:45.220

1729 sould be true or false? – J42161217 – 2017-06-14T03:33:24.290

True. All non-taxicabs false. – DrQuarius – 2017-06-14T04:02:23.277

If 1729 is true, then can you explain (or alter/remove) but is not the smallest such integer of the "3,2" class (that being 1729, of course)? Thanks! – musicman523 – 2017-06-14T04:59:43.297

Good point, sorry about that! – DrQuarius – 2017-06-14T05:42:40.087

As far as I can tell, the two answers interpreted the spec differently. Should 87539319 = 167³ + 436³ = 228³ + 423³ = 255³ + 414³ return true or false? – Dennis – 2017-06-14T06:05:43.683

Yes, that should be a true, I could have clarified "3,2" as a sum of two cubes in "at least** two ways". – DrQuarius – 2017-06-14T06:58:50.370

2A001235 – Shaggy – 2017-06-14T07:06:37.877

"Both men were mathematicians and liked to think about numbers." - This was the point I got to before I had to check whether I was on Simple English Wikipedia. Anyone else? – user253751 – 2017-06-14T07:17:43.777

1Do there need to be exactly two ways to write the number, or at least two? – John Dvorak – 2017-06-14T08:19:26.347

2

someone should write an answer in Taxi https://bigzaphod.github.io/Taxi/

– SaggingRufus – 2017-06-14T12:54:27.093

Answers

4

05AB1E, 9 bytes

Code (very slow)

L3mãOQO3›


Code (much faster), 12 bytes

tL3mDδ+˜QO3›

Uses the 05AB1E encoding. Try it online!

Explanation

t                # Square root (not necessary but added for speed)
 L               # Create a list [1 .. sqrt(input)]
  3m             # Raise to the power of 3
    D            # Duplicate
     δ+          # 2 dimensional addition
       ˜         # Deep-flatten the entire list
        Q        # Check which are equal to the input
         O       # Sum up to get the number of equalities
          3›     # Checks whether there are 4 or more equalities. In order for a number
                   to be a secondary taxicab number, there are at least two distinct
                   ways to get to that number and 4 ways when you also take reversed
                   arguments in account.

Adnan

Posted 2017-06-14T02:56:22.133

Reputation: 41 965

2Surely you could save a byte by removing the square root. This is code-golf, not fastest-code. – scatter – 2017-06-14T11:19:05.823

@Christian I have added a slow version of the code. – Adnan – 2017-06-15T09:36:32.900

6

Jelly, 9 bytes

Credits to Erik the Outgolfer.

Œċ*3S€ċ>1

Try it online!

This is too slow that it won't even work for 1729 online.

Much faster, 12 bytes

Credits to Dennis.

R*3fRŒċS€ċ>1

Try it online!

Leaky Nun

Posted 2017-06-14T02:56:22.133

Reputation: 45 011

I just tested this with "4104" and it passed. :) Haven't found any beyond this yet, but that was lightning fast! – DrQuarius – 2017-06-14T03:10:29.580

Ðf⁸ can become fR. The second can be removed. – Dennis – 2017-06-14T06:17:17.073

The second ⁸ can be removed indeed, but the fR swap leads to failure. – DrQuarius – 2017-06-14T06:24:55.633

By the way, this is [tag:code-golf] so we don't care about speed ;) but you can still include the fast version in the TIO link. – user41805 – 2017-06-14T08:23:05.150

1You don't need to care about speed, just do Œċ*3S€ċ>1. – Erik the Outgolfer – 2017-06-14T12:47:57.730

@DrQuarius Could you give me an example where fR fails? This keeps all cubes that are not greater than the input, which can't possibly be part of a valid sum. – Dennis – 2017-06-14T16:43:52.630

@Dennis♦ I just find it fails even on 1729 when I replace Ðf⁸ with fR... https://tio.run/##y0rNyan8/z9Iy9gmLejopCPdwY@a1hzpftS4w87w////huZGlgA

– DrQuarius – 2017-06-15T00:46:30.687

PS @Leaky Nun, if you amend your answer to 11 bytes, I'll accept yours as the winner, since my MATL solution is 12 at best (as is the 05AB1E solution). – DrQuarius – 2017-06-15T00:48:04.327

@DrQuarius done – Leaky Nun – 2017-06-15T00:54:21.337

@Dennis it's <Ðf⁸ that can become fR, not just Ðf⁸. – Leaky Nun – 2017-06-15T00:56:11.177

@LeakyNun Right, my bad. – Dennis – 2017-06-15T01:19:02.820

5

Mathematica, 35 bytes

Count[#^3+#2^3&~Array~{#,#},#,2]>2&

Pure function taking a positive integer and returning True or False.

#^3+#2^3&~Array~{#,#} tabulates all sums of cubes of two integers between 1 and the input. (This would be much faster with a sensible bound on the integers to be cubed, like the cube root of the input; but that would take precious bytes. As it is, the code takes about 30 seconds on the input 13832 and scales at least quadratically in the input.) Count[...,#,2] counts how many times the input appears in this list at nest-level 2; if this number is greater than 2, then the input is a semi-taxicab number (greater than 2, rather than greater than 1, since a^3+b^3 and b^3+a^3 are being counted separately).

Greg Martin

Posted 2017-06-14T02:56:22.133

Reputation: 13 940

3

Mathematica, 38 37 bytes

Tr[1^PowersRepresentations[#,2,3]]>1&

-1 byte thanks to @GregMartin

As always, there is a Mathematica builtin to everything.

JungHwan Min

Posted 2017-06-14T02:56:22.133

Reputation: 13 290

1Assuming that the OP is ok with more-than-2-representations, then I believe Tr[1^...] works in place of Length@. – Greg Martin – 2017-06-14T06:23:51.333

2

Mathematica, 48 bytes

Length@Solve[x^3+y^3-#==0<x<y,{x,y},Integers]>1&

input

[4104]

output

True

J42161217

Posted 2017-06-14T02:56:22.133

Reputation: 15 931

Note that #!=1729&& is no longer necessary now that the spec has been clarified. – Greg Martin – 2017-06-14T06:15:56.173

Could you use Solve rather than Reduce? – Ian Miller – 2017-06-14T09:51:37.240

of course...1 byte is 1 byte! – J42161217 – 2017-06-14T10:08:45.370

Can save one more byte with Length@Solve[x^3+y^3-#==0<x<y,{x,y},Integers]>1& which replaces the && with - and a little bit of rearranging. – Ian Miller – 2017-06-14T10:41:53.093

2

JavaScript (ES7), 63 bytes

A relatively fast recursive function which eventually returns a boolean.

f=(n,k,r=0,x=n-k**3)=>x<0?r>3:f(n,-~k,r+=(x**(1/3)+.5|0)**3==x)

Demo

f=(n,k,r=0,x=n-k**3)=>x<0?r>3:f(n,-~k,r+=(x**(1/3)+.5|0)**3==x)

console.log([...Array(40000).keys()].filter(n => f(n)))

Arnauld

Posted 2017-06-14T02:56:22.133

Reputation: 111 334

1

MATL (16 15 bytes) (13 12 ideally)

.4^:3^2XN!sG=sq

Try it online!

Explanation:

Based on the Jelly solution of 'Leaky Nun', just converted to MATL, probably redundant in some parts and can be improved:

.4^  % rough cube root of input, as maximum potential integer N.
:3^   % create array of all cubes from 1^3 up to N^3.
2XN   % do nchoosek on cube array, creating all possible pairs (k=2) to add.
!s    % transpose array and add all pairs to find sums.
G=    % find all pairs that equal the original input.
sq   % if there is more than one solution, then pass the test.

Note: falsy outputs include 0 and -1, while truthy output is 1. Thanks to Luis Mendo for saving an extra byte here replacing "s1>" with "sq".

Ideally (13 12 bytes):

:3^2XN!sG=sq

...is enough, but for larger numbers this crashes on tio.run's page.

DrQuarius

Posted 2017-06-14T02:56:22.133

Reputation: 562

Original: MATL (19 bytes) =============== XH.34^:3^2XN!sH=s1> – DrQuarius – 2017-06-14T07:28:09.860

1If any truthy output is valid, you can replace 1> by q. Also, you have H instead of G in the explanation. The fact that the program crashes for large numbers is usually irrelevant for scoring. If it works given enough time and memory that's acceptable, unless the challenge specifies otherwise – Luis Mendo – 2017-06-14T08:55:25.940

1Thanks Luis! I'm new to "truthy" outputs, but this works nicely now. Edited to amend. Also, thanks for creating such a fun and easy to use esolang! – DrQuarius – 2017-06-15T00:42:51.533

1

Python, 71 bytes

Try it online

lambda x:len([i for i in range(x)for j in range(i,x)if i**3+j**3==x])>1

Dead Possum

Posted 2017-06-14T02:56:22.133

Reputation: 3 256

0

Ruby, 52 bytes

->n{r=*1..n;r.product(r).count{|i,j|i**3+j**3==n}>1}

Try it online!

Since this version creates a massive n2 sized array, it fails on all true testcases higher than 1729, here is a modified version that has a smaller array size of about n2/3, which successfully checks at least up to 31392.

Try it online! (modified)

Value Ink

Posted 2017-06-14T02:56:22.133

Reputation: 10 608

0

PHP, 76 bytes

for(;$i++<$argn**(1/3);)for($n=1;$n<$i;)$n++**3+$i**3!=$argn?:$c++;echo$c>1;

Try it online!

Search till 400000 Try it online!

Jörg Hülsermann

Posted 2017-06-14T02:56:22.133

Reputation: 13 026