MuPAD 113 - 8 = 105

1

MuPAD 113 - 8 = 105

g:=[0,ithprime(i)$i=1..n]:f:=_for_in:f(l,g,f(d,g,f(b,g,f(a,g,f(c,g,if l+d+b+a+c=n then print(l,d,b,a,c)end)))))

Diese Version druckt auch alle Permutationen jeder Lösung:

0, 0, 0, 0, 7
0, 0, 0, 2, 5
0, 0, 0, 5, 2
0, 0, 0, 7, 0
0, 0, 2, 0, 5
...

Und ja, es erstellt eine viel zu lange Liste g. Wen interessiert das? :-)

Ungolfed-Version:

g:=[0].select([$1..n],isprime):
for l in g do
  for d in g do
    for b in g do
      for a in g do
        for c in g do
          if l+d+b+a+c=n then print(l,d,b,a,c); end;
        end
      end
    end
  end
end
Christopher Creutzig
quelle
Ich habe keinen Zugang zum Mupad - kann jemand überprüfen, ob dies funktioniert?
Stand

Antworten:

1

Jelly , 19 Bytes (aber sehr langsam - Beratung erwünscht)

ÆR;0x5Œ!ḣ€5¹©S€i³ị®

Probieren Sie es online!

ÆR;0x5Œ!ḣ€5¹©€i³ị®     main link, takes one argument N
ÆR                     get all the primes less than N
  ;0x5                 add zero, and then repeat the entire list 5 times
      Œ!               get all the permutations of this huge list (takes a long time!)
        ḣ€5            for each permutation, just take the first 5 numbers
                       (this gives us all possible length-5 combinations of the primes plus zero, with some repeats)
           ¹©          save that list to register
              S€       take the sum of every permutation in the list...
                i³     and find the index of our first argument N in that list of sums
                  ị®   then recall our list of permutations, and get the correct permutation at that index!

Wenn Sie Ideen haben, es schneller und kürzer zu machen, lassen Sie es mich bitte wissen!

Harry
quelle
1
12 Bytes . ṗЀ5Erzeugt alle Kombinationen von Primzahlen mit den Längen eins bis fünf. S=¥prüft, ob die Summe eines der Elemente mit dem Argument der Kette übereinstimmt und Ðfbehält nur diese Elemente bei. gibt es nur, um alle Listen der Primzahlen auf den gleichen Stand in die Liste zu setzen
dylnan
Jetzt 10 Bytes seit und Ƈwurden als Aliase für ЀandÐf
dylnan