+ 3

[HARD CHALLENGE] Infinadd

Hello everyone ! I am a student in a French informatic school (Epitech), and I wanted to share some exercises I coded during my first month. The first here: Create program that is able to add two numbers of infinite length (add a number with 100 digits and one with 2, for example). Prototype: string infinadd(string str1, string str2) -Types allowed: int, string, char (+pointers) -Only 20 lines by function -System functions are not allowed except what is needed to print output (String functions are allowed).

17th Nov 2017, 8:18 AM
Volts
Volts - avatar
11 Answers
+ 13
https://code.sololearn.com/cTeO3C6896xL/?ref=app https://code.sololearn.com/c0U2BqoJSrO1/?ref=app do you sort of mean like this? I found a worksheet that explains a large integer calculator awhile ago.
17th Nov 2017, 11:57 AM
jay
jay - avatar
17th Nov 2017, 12:08 PM
Louis
Louis - avatar
+ 7
@Volts I concede that I did use python instead of the specified languages, but why cant I use int, how will you ever go from str to a number?
17th Nov 2017, 12:55 PM
Louis
Louis - avatar
+ 1
Example of input: "81763389161628926271936164190165172926" + "7191716515181917101018161619201817" Numbers are in a string type because, obviously, they can't fill in an integer. :) Tip: How do you calculate two big numbers with only a sheet of paper and a pen ?
17th Nov 2017, 8:22 AM
Volts
Volts - avatar
+ 1
@kurwius This is the nearest from what I expected !;) All rules are respected (except function (main) > 20 lines), and it seem to work with the five tests I did ! If someone wants to tests his code: 1+1 (2) 1+10 (11) 999999999999 + 100000000001 (110000000000) 81763389161628926271936164190165172926 + 7191716515181917101018161619201817 (81770580878144108189037182351784374743) and 14159265358979323846264338327950288419716939937510 + 58209749445923078164062862089986280348253421170679 (72369014804902402010327200417936568767970361108189) So @kurwius, you passed all the tests and you are near to respect all the rules, congralutations !
17th Nov 2017, 6:59 PM
Volts
Volts - avatar
0
@Louis Well, in the tags, I precised C#, C++ and Java, because I said on the last line "System functions are not allowed", so: list, map, range and int function are not allowed. But your algorithm is okay, so you partially succeeded the challenge :)
17th Nov 2017, 12:45 PM
Volts
Volts - avatar
0
@jay The only allowed types are int, string and char, so if you use POO, you create another types that aren't allowed !
17th Nov 2017, 12:48 PM
Volts
Volts - avatar
0
@Louis I don't know if char type exists in Python, if it is the case, a number can be converted to str with + '0', and a str can be converted to number with - '0' ;) EDIT: When I did it, it was in C, and the only authorised functions were write, malloc and free :)
17th Nov 2017, 1:07 PM
Volts
Volts - avatar
0
@kurwius That's normal, if you want to try negative numbers, you'll have to do the infinsub !
17th Nov 2017, 7:35 PM
Volts
Volts - avatar