Trithagoreische Dreiergruppen


16

Ein pythagoreisches Dreifach ist eine positive ganzzahlige Lösung der Gleichung:

Pythagoreisches Dreifach

Ein Trithagoreisches Tripel ist eine positive ganzzahlige Lösung der Gleichung:

Trithagoreische Gleichung

Wobei Δn die n-te Dreieckszahl findet . Alle trithagoreischen Tripel sind auch Lösungen für die Gleichung:

Bildbeschreibung hier eingeben

Aufgabe

Bei einer positiven Ganzzahl cwerden alle Paare positiver Ganzzahlen a,bso ausgegeben, dass die Summe der ath- und bth-Dreieckszahlen die cth-Dreieckszahl ist. Sie können die Paare auf die am besten geeignete Weise ausgeben. Sie sollten jedes Paar nur einmal ausgeben.

Das ist

Testfälle

2: []
3: [(2, 2)]
21: [(17, 12), (20, 6)]
23: [(18, 14), (20, 11), (21, 9)]
78: [(56, 54), (62, 47), (69, 36), (75, 21), (77, 12)]
153: [(111, 105), (122, 92), (132, 77), (141, 59), (143, 54), (147, 42), (152, 17)]
496: [(377, 322), (397, 297), (405, 286), (427, 252), (458, 190), (469, 161), (472, 152), (476, 139), (484, 108), (493, 54), (495, 31)]
1081: [(783, 745), (814, 711), (836, 685), (865, 648), (931, 549), (954, 508), (979, 458), (989, 436), (998, 415), (1025, 343), (1026, 340), (1053, 244), (1066, 179), (1078, 80), (1080, 46)]
1978: [(1404, 1393), (1462, 1332), (1540, 1241), (1582, 1187), (1651, 1089), (1738, 944), (1745, 931), (1792, 837), (1826, 760), (1862, 667), (1890, 583), (1899, 553), (1917, 487), (1936, 405), (1943, 370), (1957, 287), (1969, 188)]
2628: [(1880, 1836), (1991, 1715), (2033, 1665), (2046, 1649), (2058, 1634), (2102, 1577), (2145, 1518), (2204, 1431), (2300, 1271), (2319, 1236), (2349, 1178), (2352, 1172), (2397, 1077), (2418, 1029), (2426, 1010), (2523, 735), (2547, 647), (2552, 627), (2564, 576), (2585, 473), (2597, 402), (2622, 177), (2627, 72)]
9271: [(6631, 6479), (6713, 6394), (6939, 6148), (7003, 6075), (7137, 5917), (7380, 5611), (7417, 5562), (7612, 5292), (7667, 5212), (7912, 4832), (7987, 4707), (8018, 4654), (8180, 4363), (8207, 4312), (8374, 3978), (8383, 3959), (8424, 3871), (8558, 3565), (8613, 3430), (8656, 3320), (8770, 3006), (8801, 2914), (8900, 2596), (8917, 2537), (9016, 2159), (9062, 1957), (9082, 1862), (9153, 1474), (9162, 1417), (9207, 1087), (9214, 1026), (9229, 881), (9260, 451), (9261, 430), (9265, 333)]

Können wir wiederholte Paare ausgeben? Beispiel für die 21Ausgabe[(17, 12), (20, 6), (12, 17), (6, 20)]
Luis Mendo

7
Ich dachte du bittest uns zu finden a^3+ b^3 = c^3. : D
Beta Decay

@ LuisMendo Nein. Ich werde dies in die Frage aufnehmen.
Weizen-Assistent

3
@BetaDecay MATL, 0 Bytes
Luis Mendo

3
Es a^3+ b^3 = c^3ist bekannt, dass @EriktheOutgolfer keine ganzzahligen Lösungen hat. siehe Fermats letzter Satz
Luis Mendo

Antworten:


7

Mathematica, 53 49 48 Bytes

Solve[{x.(x+1)==#^2+#,a>=b>0},x={a,b},Integers]&

Beispiel:

In[1]:= Solve[{x.(x+1)==#^2+#,a>=b>0},x={a,b},Integers]&[21]

Out[1]= {{a -> 17, b -> 12}, {a -> 20, b -> 6}}

ooohh, nette Vektorisierung, viel besser als das, was ich getan hätte
Greg Martin

6

MATL , 17 13 Bytes

:Ys&+G:s=R&fh

Jedes Paar wird mit der kleineren Nummer zuerst ausgegeben.

Probieren Sie es online!

Erläuterung

Betrachten Sie die Eingabe 3.

:      % Implicitly input n. Push [1 2 ... n]
       % STACK: [1 2 3]
Ys     % Comulative sum
       % STACK: [1 3 6]
&+     % All pairwise sums
       % STACK: [2 4 7; 4 6 9; 7 9 12]
G:s    % Push 1+2+...+n
       % STACK: [2 4 7; 4 6 9; 7 9 12], 6
=      % Is equal?
       % STACK: [0 0 0; 0 1 0; 0 0 0]
R      % Upper triangular part of matrix. This removes duplicate pairs
       % STACK: [0 0 0; 0 1 0; 0 0 0]
&f     % Push row and column indices (1-based) of non-zero entries
       % STACK: 2, 2
h      % Concatenate horizontally. Implicitly display
       % STACK: [2, 2]

Erklärung bitte?
Erik der Outgolfer

@EriktheOutgolfer Sicher, ich werde es später am Tag hinzufügen
Luis Mendo

Stellen Sie nur sicher, dass Sie die eindeutigen Paare ausgeben, weshalb ich Sie hauptsächlich gefragt habe.
Erik der Outgolfer

@EriktheOutgolfer Ja, sie sind einzigartig ( Rkümmert sich darum)
Luis Mendo

1
@EriktheOutgolfer Erläuterung hinzugefügt
Luis Mendo

6

Gelee , 12 Bytes

j‘c2ḅ-
ŒċçÐḟ

Probieren Sie es online!

Wie es funktioniert

ŒċçÐḟ   Main link. Argument: c

Œċ      Yield all 2-combinations w/repetition of elements of [1, ..., c].
  çÐḟ   Filterfalse; keep only 2-combinations for which the helper link returns 0.


j‘c2ḅ-  Helper link. Left argument: [a, b]. Right argument: c

j       Join [a, b] with separator c, yielding [a, c, b].
 ‘      Increment; yield [a+1, c+1, b+1].
  c2    Combination count; compute [C(a+1,c), C(c+1,c), C(b+1,c)], yielding
        [½a(a+1), ½c(c+1), ½b(b+1)].
    ḅ-  Convert from base -1 to integer, yielding
        ½(-1)²a(a+1) + ½(-1)¹c(c+1) + ½(-1)⁰b(b+1) = ½(a(a+1) - c(c+1) + b(b+1)),
        which is 0 if and only if a(a+1) + b(b+1) = c(c+1).


4

Jelly , 16 bis 14 Bytes

RS
ŒċÇ€S$⁼¥ÐfÇ

Probieren Sie es online!

Das ist sicher zu lang ...

Erläuterung:

ŒċÇ€S$⁼¥ÐfÇ (main) Arguments: z
Œċ             Return [[1, 1], [1, 2], ..., [1, z], [2, 2], ..., [z, z]]
          Ç    Return T(z)
  Ç€S$⁼¥Ðf     Only keep the pairs such as ΣT(a, b)=T(z)

RS (helper 1) Arguments: z
R  [1, 2, ..., z]
 S Take the sum

4

AWK , 72 Bytes

{for(n=$1;++i<=n;)for(j=i;j<=n;++j)if(i^2+j^2+i+j==n^2+n)$0=$0" "i":"j}1

Probieren Sie es online!

Ausgabe ist c a1:b1 a2:b2 .... Die TIO-Verbindung verfügt über 4 zusätzliche Bytes i=0;, um eine mehrzeilige Eingabe zu ermöglichen.

Das ist überhaupt nicht effizient, aber es funktioniert. :)



3

Haskell, 50 Bytes

f c=[(a,b)|a<-[1..c],b<-[1..a],a^2+a+b^2+b==c^2+c]

Anwendungsbeispiel: f 21-> [(17,12),(20,6)]. Probieren Sie es online!

Verwendet die 2. Gleichung.



2

Axiom, 281 204 196 191 Bytes

q(b,m)==(r:=1+4*m;v:=4.*b*(b+1);r<v=>0;(sqrt(r-v)-1)/2);g(c:NNI):Any==(r:List List INT:=[];i:=0;repeat(i:=i+1;i>=c=>break;w:=q(i,c^2+c);w>=i and fractionPart(w)=0=>(r:=cons([w::INT,i],r)));r)

Test und ungolf

-- if m=c^2+c than a^2+a+b^2+b-m=0 has the solutions [a,b] with a>0,b>0
-- if it is used a=(-1+sqrt(1+4*m-4*(b)*(b-1)))/2 because the other return a<0
-- o(b,m) return that solution if 1+4*m-4*(b)*(b-1)>0 [so exist in R sqrt] else return 0
o(b,m)==(r:=1+4*m;v:=4.*b*(b+1);r<v=>0;(sqrt(r-v)-1)/2)

--it Gets one not negative integer c; return one list of list(ordered) of 2 integers
--[a,b] with  a^2+a+b^2+b=c^2+c
gg(c:NNI):List List INT==
   r:List List INT:=[]  -- initialize the type make program more fast at last it seems 10x
   i:=0
   repeat
      i:=i+1
      i>=c=>break
      w:=o(i,c^2+c)
      w>=i and fractionPart(w)=0=>(r:=cons([w::INT,i],r))
   r

(6) -> [[i,g(i)]  for i in [2,3,21,23,78,153,496,1081,1978,2628,9271]]
   (6)
   [[2,[]], [3,[[2,2]]], [21,[[17,12],[20,6]]], [23,[[18,14],[20,11],[21,9]]],
    [78,[[56,54],[62,47],[69,36],[75,21],[77,12]]],
    [153,[[111,105],[122,92],[132,77],[141,59],[143,54],[147,42],[152,17]]],

     [496,
       [[377,322], [397,297], [405,286], [427,252], [458,190], [469,161],
        [472,152], [476,139], [484,108], [493,54], [495,31]]
       ]
     ,

     [1081,
       [[783,745], [814,711], [836,685], [865,648], [931,549], [954,508],
        [979,458], [989,436], [998,415], [1025,343], [1026,340], [1053,244],
        [1066,179], [1078,80], [1080,46]]
       ]
     ,

     [1978,
       [[1404,1393], [1462,1332], [1540,1241], [1582,1187], [1651,1089],
        [1738,944], [1745,931], [1792,837], [1826,760], [1862,667], [1890,583],
        [1899,553], [1917,487], [1936,405], [1943,370], [1957,287], [1969,188]]
       ]
     ,

     [2628,
       [[1880,1836], [1991,1715], [2033,1665], [2046,1649], [2058,1634],
        [2102,1577], [2145,1518], [2204,1431], [2300,1271], [2319,1236],
        [2349,1178], [2352,1172], [2397,1077], [2418,1029], [2426,1010],
        [2523,735], [2547,647], [2552,627], [2564,576], [2585,473], [2597,402],
        [2622,177], [2627,72]]
       ]
     ,

     [9271,
       [[6631,6479], [6713,6394], [6939,6148], [7003,6075], [7137,5917],
        [7380,5611], [7417,5562], [7612,5292], [7667,5212], [7912,4832],
        [7987,4707], [8018,4654], [8180,4363], [8207,4312], [8374,3978],
        [8383,3959], [8424,3871], [8558,3565], [8613,3430], [8656,3320],
        [8770,3006], [8801,2914], [8900,2596], [8917,2537], [9016,2159],
        [9062,1957], [9082,1862], [9153,1474], [9162,1417], [9207,1087],
        [9214,1026], [9229,881], [9260,451], [9261,430], [9265,333]]
       ]
     ]
                                                      Type: List List Any

1

CJam , 30 28 Bytes

{_,2m*:$_&f+{{_)*}%~+=},1f>}

Anonymer Block erwartet sein Argument auf dem Stapel und belässt das Ergebnis auf dem Stapel.

Probieren Sie es online!

Erläuterung

Ich werde den Eingang als bezeichnen n

_,     e# Copy n, and get the range from 0 to n-1.
2m*    e# Get the 2nd Cartesian power of this range.
:$_&   e# Sort the pairs and deduplicate, to get all unique pairs.
f+     e# Prepend n to each pair.
{      e# Filter these triplets; keep only those that give a truthy result:
 {     e#  Map this block over the triplet:
  _)*  e#   Multiply x by x+1. (i.e. x^2 + x)
 }%    e#  (end map)
 ~+=   e#  Check if the sum of the second and third is equal to the first.
},     e# (end filter)
1f>    e# Remove the first element from all remaining triplets.

1

Pyth - 23 21 Bytes

L*bhbfqyQ+yhTyeT.CUQ2

Versuch es

L*bhbfqyQ+yhTyeT.CUQ2
L*bhb                     Define y(b)=b*(b+1)
                .CUQ2     All pairs of numbers less than the input
     fqyQ+yhTyeT          Filter based on whether y(input) == y(1st elem. of pair) + y(2nd elem. of pair)

1

JavaScript (ES6), 83 Byte

c=>[...Array(c*c)].map((_,x)=>[x%c,x/c|0]).filter(([a,b])=>a>=b&a++*a+b++*b==c*c+c)

Testfälle

Lassen Sie hier die größten Eingaben weg, die für das Snippet zu viel Zeit in Anspruch nehmen.

Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.