17
\$\begingroup\$

This question was inspired this question and @orlp's comment and a lot of the explanation was copied from there.

Write a GOLF assembly program that given two arbitrary size decimal integers a, and b from stdin outputs two decimal integers to stdout, Q and R such that b * Q + R = a. In other words write divmod with arbitrary precision integers.

Clarifications

  • abs(R) must be less than abs(b)
  • You do not need to deal with b = 0
  • a and b are decimal string representing integers in (-inf, inf), space separated.
  • Output is also space separated in order Q R.
  • Your score is the sum of # of cycles * (513 - test case size) for each test-case where the size is listed next to each test-case.
  • This is a challenge so lowest score wins!
  • Your GOLF binary (after assembling) must fit in 4096 bytes.

Test Cases

(8 bit) 236 7 -> 33 5
(32 bit) 2262058702 39731 -> 56934 13948
(128 bit) 189707885178966019419378653875602882632 15832119745771654346 -> 11982469070803487349 12121955145791013878
(512 bit) 6848768796889169874108860690670901859917183532000531459773526799605706568321891381716802882255375829882573819813967571454358738985835234480369798040222267 75399690492001753368449636746168689222978555913165373855679892539145717693223 -> 90832850270329337927688719359412349209720255337814924816375492347922352354493 57944926054000242856787627886619378599467822371491887441227330826275320521328

You should read the GOLF specification with all instructions and cycle costs. In the Github repository example programs can be found.

\$\endgroup\$

closed as unclear what you're asking by Martin Ender Mar 22 '17 at 20:18

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 6
    \$\begingroup\$ Can we choose which way to round negative numbers? \$\endgroup\$ – Lynn Sep 1 '15 at 9:00
  • 3
    \$\begingroup\$ Can we get examples with one or more negative inputs? \$\endgroup\$ – 2012rcampion May 5 '16 at 1:57
  • \$\begingroup\$ Temporarily putting this on hold until the rules for negative inputs are clarified. \$\endgroup\$ – Martin Ender Mar 22 '17 at 20:18