Tuesday, June 11, 2019

Multiply two arbitrary precision integers

Increment Arbitrary  precision number

Problem Statement

Write a program that takes two array B1 and B2 and return a new array with value B1 * B2 . 

Problem Solving

  • Straight forward I think this is again a duplicate of high school method simulation. 
  • We need to break down this into manageable chunks or functions.
  • First we will take a two vector of integers and need a function to carry out multiplication of array with an int so we need a function for that.
  • Once we are done with creating individual multiplication chunks. We need to add them with offsets as in school days. 
  • So we need to separate the indexing with offset logic with the function that carries out actual addition. 
  • In all these we need to maintain that all functions return correct values for individual inputs. This helps intensively in debugging. And that all functions return values in correct order, since we are using vectors here. we need to insert new elements at back which causes most computation to return values in reverse order so we need to reverse the final outputs for each function. 
  • Find Code here. 

Learning

  • The most difficult part was the offset addition. This added with complexity of reverse notion of number really hurt my brain. 
  • However whatever doesn't kill you makes you stronger. 
  • Also there were numerous compile time issues, this indicates I need to understand "const" in depth this causes me a lot of pain. 
  • Also C++ compiler errors are extremely verbose or may be the right word is cryptic. May be some time will make me comfortable. 
  • This was a difficult problem no doubt not in terms of problem solving but actual coding. 

 

No comments:

Post a Comment