Came along an interesting puzzle so wanted to share.
Write a function that adds two numbers. You should not use + or any arithmetic operators.
Lets have two number which are fairly large and try to add those two numbers but try a different approach.
987+789 = 1776
Lets just think backwards
987
+ 789
--------
666
Carry : 1110. This is calculated when the first carry is the first digit and the last carry is the last.
Add 1110 and 666 which gives you the ultimate result.
Now lets implement it in source (I am using python)
>>> def sum_without_arithmetic(a,b):
... if b==0:
... return a
... sum = a^b
... carry = (a&b)<<1
... return sum_without_arithmetic(sum, carry)
...
>>> sum_without_arithmetic(987,789)
1776
1 comment:
⭐ Workday HCM Training Online
Advanced workday hcm training online focuses on real-time HR application development.
The course covers business process configuration and reporting tools.
Hands-on projects enhance practical experience.
Live sessions help clarify technical and functional concepts.
Assignments improve system configuration knowledge.
Expert mentors guide you throughout the training.
This program prepares you for Workday HCM job roles.
⭐ Workday HCM Certification Training
Professional workday hcm certification training helps you prepare for industry-recognized certification.
The course includes detailed coverage of HCM modules and workflows.
Hands-on practice improves configuration skills.
Live sessions provide interactive guidance.
Assignments strengthen your understanding of key concepts.
Expert trainers share certification tips and strategies.
This training increases your chances of career advancement.
Post a Comment