4 kyu

Explosive Sum

3,081 of 9,135surtich

Description:

How many ways can you make the sum of a number?

From wikipedia: https://en.wikipedia.org/wiki/Partition_(number_theory)

In number theory and combinatorics, a partition of a positive integer n, also called an integer partition, is a way of writing n as a sum of positive integers. Two sums that differ only in the order of their summands are considered the same partition. If order matters, the sum becomes a composition. For example, 4 can be partitioned in five distinct ways:

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

Examples

Basic

sum(1) // 1
sum(2) // 2  -> 1+1 , 2
sum(3) // 3 -> 1+1+1, 1+2, 3
sum(4) // 5 -> 1+1+1+1, 1+1+2, 1+3, 2+2, 4
sum(5) // 7 -> 1+1+1+1+1, 1+1+1+2, 1+1+3, 1+2+2, 1+4, 5, 2+3

sum(10) // 42
explosiveSum  1   -- 1
explosiveSum 2   -- 2 -> 1+1 , 2
explosiveSum 3   -- 3 -> 1+1+1, 1+2, 3
explosiveSum 4   -- 5 -> 1+1+1+1, 1+1+2, 1+3, 2+2, 4
explosiveSum 5   -- 7 -> 1+1+1+1+1, 1+1+1+2, 1+1+3, 1+2+2, 1+4, 5, 2+3

explosiveSum 10  -- 42
exp_sum(1) # 1
exp_sum(2) # 2  -> 1+1 , 2
exp_sum(3) # 3 -> 1+1+1, 1+2, 3
exp_sum(4) # 5 -> 1+1+1+1, 1+1+2, 1+3, 2+2, 4
exp_sum(5) # 7 -> 1+1+1+1+1, 1+1+1+2, 1+1+3, 1+2+2, 1+4, 5, 2+3

exp_sum(10) # 42
exp_sum(1) # 1
exp_sum(2) # 2  -> 1+1 , 2
exp_sum(3) # 3 -> 1+1+1, 1+2, 3
exp_sum(4) # 5 -> 1+1+1+1, 1+1+2, 1+3, 2+2, 4
exp_sum(5) # 7 -> 1+1+1+1+1, 1+1+1+2, 1+1+3, 1+2+2, 1+4, 5, 2+3

exp_sum(10) # 42
exp_sum(1) // 1
exp_sum(2) // 2  -> 1+1 , 2
exp_sum(3) // 3 -> 1+1+1, 1+2, 3
exp_sum(4) // 5 -> 1+1+1+1, 1+1+2, 1+3, 2+2, 4
exp_sum(5) // 7 -> 1+1+1+1+1, 1+1+1+2, 1+1+3, 1+2+2, 1+4, 5, 2+3

exp_sum(10) // 42
ExpSum(1) // 1
ExpSum(2) // 2 -> 1+1 , 2
ExpSum(3) // 3 -> 1+1+1, 1+2, 3
ExpSum(4) // 5 -> 1+1+1+1, 1+1+2, 1+3, 2+2, 4
ExpSum(5) // 7 -> 1+1+1+1+1, 1+1+1+2, 1+1+3, 1+2+2, 1+4, 5, 2+3

ExpSum(10) // 42
exp_sum(1) // 1
exp_sum(2) // 2  -> 1+1 , 2
exp_sum(3) // 3 -> 1+1+1, 1+2, 3
exp_sum(4) // 5 -> 1+1+1+1, 1+1+2, 1+3, 2+2, 4
exp_sum(5) // 7 -> 1+1+1+1+1, 1+1+1+2, 1+1+3, 1+2+2, 1+4, 5, 2+3

exp_sum(10) // 42

Explosive

sum(50) // 204226
sum(80) // 15796476
sum(100) // 190569292
explosiveSum  50 --    204226
explosiveSum  80 --  15796476
explosiveSum 100 -- 190569292
exp_sum(50) # 204226
exp_sum(80) # 15796476
exp_sum(100) # 190569292
exp_sum(50) # 204226
exp_sum(80) # 15796476
exp_sum(100) # 190569292
exp_sum(50) // 204226
exp_sum(80) // 15796476
exp_sum(100) // 190569292
ExpSum(50) // 204226
ExpSum(80) // 15796476
ExpSum(100) // 190569292
exp_sum(50) // 204226
exp_sum(80) // 15796476
exp_sum(100) // 190569292

See here for more examples.

Algorithms
Mathematics
Fundamentals

More By Author:

Check out these other kata created by surtich

Stats:

CreatedJan 31, 2014
PublishedJan 31, 2014
Warriors Trained46282
Total Skips14984
Total Code Submissions43277
Total Times Completed9135
JavaScript Completions3081
Haskell Completions221
Ruby Completions301
Python Completions4430
C++ Completions1007
Go Completions175
Rust Completions140
C Completions4
Total Stars1716
% of votes with a positive feedback rating90% of 950
Total "Very Satisfied" Votes787
Total "Somewhat Satisfied" Votes131
Total "Not Satisfied" Votes32
Ad
Contributors
  • surtich Avatar
  • jhoffner Avatar
  • xcthulhu Avatar
  • bkaes Avatar
  • Unnamed Avatar
  • GiacomoSorbi Avatar
  • jcsahnwaldt Avatar
  • JohanWiltink Avatar
  • Voile Avatar
  • rowcased Avatar
  • FArekkusu Avatar
  • Awesome A.D. Avatar
  • Kacarott Avatar
  • dfhwze Avatar
  • sid114 Avatar
  • guuzaa Avatar
Ad