Skip to main content
save 7 bytes thanks to @Lynn
Source Link
Christian Sievers
  • 7.1k
  • 1
  • 19
  • 25

Haskell, 6666 59 bytes

Thanks for allowing to output all solutions, that was fascinating distraction! I was so happy to not need to extract one solution and be able to just give them all that I didn't notice the cost that comes from avoiding permuted solutions. @Lynn's remark explained that to me and let me save 7 bytes.

f n|l<-scanl(+)0[1..n]=[(a,b,c)|a<|c<-l,b<-l,a>=b,c<a<-l,a+b+c==n,b>=c]a+b+c==n]!!0

This binds more than enough triangular numbers to l and checks all combinations.

Haskell, 66 bytes

Thanks for allowing to output all solutions!

f n|l<-scanl(+)0[1..n]=[(a,b,c)|a<-l,b<-l,a>=b,c<-l,a+b+c==n,b>=c]

This binds more than enough triangular numbers to l and checks all combinations.

Haskell, 66 59 bytes

Thanks for allowing to output all solutions, that was fascinating distraction! I was so happy to not need to extract one solution and be able to just give them all that I didn't notice the cost that comes from avoiding permuted solutions. @Lynn's remark explained that to me and let me save 7 bytes.

f n|l<-scanl(+)0[1..n]=[(a,b,c)|c<-l,b<-l,a<-l,a+b+c==n]!!0

This binds more than enough triangular numbers to l and checks all combinations.

Source Link
Christian Sievers
  • 7.1k
  • 1
  • 19
  • 25

Haskell, 66 bytes

Thanks for allowing to output all solutions!

f n|l<-scanl(+)0[1..n]=[(a,b,c)|a<-l,b<-l,a>=b,c<-l,a+b+c==n,b>=c]

This binds more than enough triangular numbers to l and checks all combinations.