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

Esta versión también imprimirá todas las permutaciones de cada solución:

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

Y sí, crea una lista demasiado larga g. ¿A quien le importa? :-)

Versión sin golf:

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
fuente
No tengo acceso a mupad, ¿alguien puede comprobar que esto funciona?
stand

Respuestas:

1

Jelly , 19 bytes (pero muy lento, se necesitan consejos)

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

Pruébalo en línea!

Æ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!

Si tiene alguna idea para hacerlo más rápido y más corto, ¡hágamelo saber!

Harry
fuente
1
12 bytes . ṗЀ5produce todas las combinaciones de primos con longitudes de uno a cinco. S=¥comprueba si la suma de uno de los elementos es igual al argumento de la cadena y Ðfconserva solo esos elementos. solo está ahí para poner todas las listas de números primos al mismo nivel en la lista
dylnan
Ahora 10 bytes desde entonces y Ƈse han agregado como alias para ЀyÐf
dylnan