Python Forum
Help with a query - to show possible formulas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with a query - to show possible formulas
#1
Hi, thank you in advance for taking the time to read this query and help me.

I am very stuck with this problem!!!

I am trying to produce a query in Python3. Which will show all the possible calculations to a specific value using a restricted range of numbers.

So if the number i input ( N= 4 )

if my options are 1,3,4 the result would show:

1+1+1+1
3+1
1+3
4


Currently i have been able to find code to tell me the number of possibilities but not show me what they are; my code so far is:
def Sums134(n):

    DP = [0 for i in range(0, n + 1)]


    DP[0] = DP[1] = DP[2] = 1
    DP[3] = 2


    for i in range(4, n + 1):
        DP[i] = DP[i - 1] + DP[i - 3] + DP[i - 4]

    return DP[n]



n = 10
print (Sums134(n))
Larz60+ write Nov-01-2020, 11:50 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

I fixed this for you this time. Please use bbcode tags on future posts.
Reply
#2
With a generalized solution, since you don't know if one of the numbers is 1, you need to find all of the permutations of the numbers, allowing repeats, of n numbers. Once you have the permutations, see how many add up to n.

Potential is a lot of permutations. If you have 3 numbers as in your example, and n=4 as in the example, you will have 3 1 digit options, 3 squared 2 digit options, 3 cubed 3 digit options, and 3 to the 4th power 4 digit options. Total is 3+9+27+81=120 combinations. Most will not add up to 4.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating formulas in Excel - best solution MasterOfDestr 4 672 Mar-11-2024, 01:02 PM
Last Post: MasterOfDestr
  plotting based on the results of mathematical formulas Timur 1 348 Feb-08-2024, 07:22 PM
Last Post: Gribouillis
  PIL Image im.show() no show! Pedroski55 2 969 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
  PIL Image im.show() no show! Pedroski55 6 4,931 Feb-08-2022, 06:32 AM
Last Post: Pedroski55
  openpyxl insert list with formulas Irv1n 1 1,558 Sep-16-2021, 08:10 AM
Last Post: Irv1n
  Show graphs in matplotlib from a sql query? ScaleMan 1 1,864 Feb-06-2020, 05:47 PM
Last Post: ScaleMan
  How to ignore formulas when reading excel file SriMekala 3 6,525 Aug-16-2019, 04:04 PM
Last Post: buran
  python 3 math formulas where to use () Python101 1 2,310 Jun-09-2019, 09:54 PM
Last Post: micseydel
  Business formulas more help needed!! jy0013 4 3,440 Aug-29-2017, 12:21 AM
Last Post: jy0013

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020