Addition Partition - MATLAB Cody - MATLAB Central

Problem 42918. Addition Partition

Difficulty:Rate

You will be given two numbers, N and K. Write a MATLAB function that will determine how many different unique ways you can have K numbers add up to N. The numbers you use can be anything from 0-N, but no negatives and no fractions. For example, five can be the sum of three numbers in five different ways:

  • 5+0+0
  • 4+1+0
  • 3+2+0
  • 3+1+1
  • 2+2+1

Order does not matter, so (5,0,0) is the same as (0,0,5) and (0,5,0). Therefore, the output of your function num_sum(5,3) should be 5. I don't need the different permutations, only how many there are. Good luck!

Solution Stats

64.41% Correct | 35.59% Incorrect
Last Solution submitted on Jun 10, 2024

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
2
4
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Group

Physics Image
Physics
  • 18 Problems
  • 13 Finishers

Problem Recent Solvers24

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page