TransWikia.com

Filtering solutions in PowerRepresentations

Mathematica Asked on April 16, 2021

I have the following code:

PowersRepresentations[10400, 7, 2]

This produces Length[PowersRepresentations[10400, 7, 2]]=433789 number of solutions. Now I want to filter in those solutions, the filter must remove the solutions when it does not exist of distinct integers (so for example $left{35, 35, 35, 36, 38, 41, 48right}$ must be removed because the number $35$ is used three times) and all the integers must be bigger than zero (so for example $left{0, 0, 0, 0, 0, 20, 100right}$ must be removed because the number $0$ is used and it is used five times). How do I code that?

2 Answers

Select[PowersRepresentations[10400, 7, 2], 
 DuplicateFreeQ[#] && ! MemberQ[#, 0] &]

Correct answer by flinty on April 16, 2021

You could also use IntegerPartitions, which is faster than PowersRepresentations.

Select[IntegerPartitions[10400, {7}, Range[101]^2], DuplicateFreeQ[#]&]

or

Pick[#, Map[DuplicateFreeQ, #]]&[IntegerPartitions[10400, {7}, Range[101]^2]]

The maximum of the range, 101, is approximately the square root of the input integer 10400.

Answered by KennyColnago on April 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP