Showing posts with label A or B algorithm prototype. Show all posts
Showing posts with label A or B algorithm prototype. Show all posts

Monday, June 27, 2016

Hexadecimal OR calculation

June 26, 2017

To work on HackerRank algorithm AoB, Julia found out that it took her more than 10 5+ hours to work on/ debugging/ bug fixing. She needs to work on design carefully, work on small functions first. 

Strategies talk: 
In order to save time and help herself think clearly/ simple, at the very beginning, she should define this small function, play with the code, and make it bug-free first. So, choose an easy battle first, something she can finish in 20 minutes and well-defined, easy to set up test cases and verify, and then, put together a complicate function to complete the task. If there is doubt or unsolvable issues, go back to the easy function, work on it more. 

Problem statement: 
Write a function to do A or B calculation, A and B is bigger than 0, and smaller than 16^(50000)
Analysis:
The size of number is too big, 64 bit integer is only < 2^64, so only work on one char at a time - one Hexadecimal char (0-F) a time. Only convert char and integer between Hexadecimal char(0-F) and integer (0-15). 

Test case:
Hexadecimal: 1000 | 11000 = 11000

 A | B
 For example:
 A = "111A"
 B = "1B"
so, A|B = "111B"
C# practice:  https://gist.github.com/jianminchen/5442cb579b13ffc203ce89b3e54e8a36