4 ms·
Looks like I'd fail your pre-screen test. What's the "mathematical" solution if you're not allowed to convert strings to ints? Ascii math?
by harshalizee 3y ago
Looks like I'd fail your pre-screen test. What's the "mathematical" solution if you're not allowed to convert strings to ints? Ascii math?
- m3047 3y agoNot quite sure, and I'm not quite sure I care either. ;-) However for any multiple of 9, the digits will add up to a multiple of 9. So you're looking for numbers in [ (n+2)*9 + 1 for n in range(9) ]
- monkeyjoe 3y agoI think it just means taking the input as an integer and then separating out the “ones place”and “tens place” using integer division and modulo operator. E.g., ones = number % 10 tens = number // 10 do_print = (ones + tens) == 10
- harshalizee 3y agoThat's what my solution after the parsing would be. OP mentioned reading from a file, which you would only be able to use after string conversion to ints.
- ProZsolt 3y agoMaybe they didin't calculated the digits, like this: if toInt(number) % 10 != 0 print number else print number + "(" + number[0] + "," + number[1] + ")"
- hahamrfunnyguy 3y agoYes. This is the mathematical solution.
- deleted 3y ago[deleted]
- tomjupiter 3y agoI think hahamrfunnyguy must have meant "convert the numbers to strings" - that's the only way I can make sense of it. quiz.txt must contain code, not sample data.
- hahamrfunnyguy 3y agoYes, quiz.txt was the start of a C# program with a main method and a function that was called to do the work asked. The common string based solution was to use a for loop, convert the counter to a string, parse the digits converting each one to a an integer and performing the calculation. The exercise was given in C# so candidates just use string interpolation to output the result