6 kyu

(a+b)^n

92 of 433LearningFTW

Description:

Similar but fairly harder version : Linked

Create a function that takes a integer number n and returns the formula for (a+b)n(a+b)^n as a string. (Input --> Output)

0  --> "1"
1  --> "a+b"
2  --> "a^2+2ab+b^2"
-2 --> "1/(a^2+2ab+b^2)"
3  --> "a^3+3a^2b+3ab^2+b^3"
5  --> "a^5+5a^4b+10a^3b^2+10a^2b^3+5ab^4+b^5"

The formula for n=5 is like so :

a5+5a4b+10a3b2+10a2b3+5ab4+b5a^5 + 5a^4b+10a^3b^2+10a^2b^3+5ab^4+b^5

So the answer would look like so : a^5+5a^4b+10a^3b^2+10a^2b^3+5ab^4+b^5

Important notes :

  • Your string may not have spaces so you can't do this : a^5 + 5a^4 b + 10a^3 b^2...
  • You will show raised to power of by ^ and not using **.
  • You need not put * between each multiplication
  • There is no need to show a^1 or b^1 since that is basically a and b
  • a^0 and/or b^0 also don't need be shown instead be a normal person and use 1 since that is what they equate to.
  • You will need to handle both positive and negative numbers + 0
  • Note :
    • an=1an a^{-n} = \frac 1{a^n}
  • You will not be tested for float (only negative integers and whole numbers)
  • input n goes from -200 to 200.

You will need to use BigInt since otherewise it will not work for both JS and Java

Mathematics
Algebra
Strings

Stats:

CreatedSep 15, 2021
PublishedSep 15, 2021
Warriors Trained1973
Total Skips40
Total Code Submissions3417
Total Times Completed433
JavaScript Completions92
Python Completions274
Ruby Completions23
Java Completions55
C Completions25
Total Stars58
% of votes with a positive feedback rating92% of 101
Total "Very Satisfied" Votes85
Total "Somewhat Satisfied" Votes15
Total "Not Satisfied" Votes1
Total Rank Assessments26
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • LearningFTW Avatar
  • trashy_incel Avatar
  • ejini战神 Avatar
  • akar-0 Avatar
Ad