You are given as input two strings representing positive integers in base 10, such as "12345"
and "42"
. Your task is to output a string containing their product, "518490"
in this case.
The twist is that you may not use any numerical types in your code. No ints
, float
s, unsigned long
s, etc., no built-in complex number types or arbitrary precision integers, or anything along those lines. You many not use literals of those types, nor any function, method, operator etc. that returns them.
You can use strings, booleans, arrays, or anything else that wouldn't normally be used to represent a number. (But note that neither indexing into an array nor getting its length are likely to be possible without invoking a numeric type.) char
s are permitted, but you may not perform any arithmetic or bitwise operations on them or otherwise treat them as anything else other than a token representing part of a string. (Lexicographical comparison of char
s is allowed.)
You may not work around the restriction. This includes (but is not limited to) using numeric types inside an eval
type function, implicit type conversions into numerical types, using numeric or bitwise operators on non-numeric types that support them, using numerical types stored inside container types, or calling functions or external programs that return numerical results in string form. (I reserve the right to add to this list if other workarounds appear in the answers.) You must implement the multiplication yourself using only non-numeric types.
Input and output may be by any convenient method, as long as the data enters and exits your code in the form of a string. You may assume each of the two input arguments contains only the ASCII characters [0-9]
and will not start with 0
. Your output shouldn't have leading zeroes either.
One more thing: your code must correctly handle inputs up to at least 10 characters in length, and must run in under a minute on a modern computer for all inputs in that range. Before posting, please check that when given inputs 9999999999
and 9999999999
, your program gives an output of 99999999980000000001
, in less than a minute. This restriction exists specifically to prevent answers that work by allocating an array of size a*b
and then iterating over it, so please bear in mind that answers of that form will not be eligible to win.
This is code-golf, so the shortest valid solution (in bytes) wins.