GOLF CPU - Implement Arbitrary Precision Integer Division

17

2

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.

Maltysen

Posted 2015-09-01T07:32:54.830

Reputation: 25 023

Question was closed 2017-03-22T20:18:12.203

6Can we choose which way to round negative numbers? – Lynn – 2015-09-01T09:00:37.130

3Can we get examples with one or more negative inputs? – 2012rcampion – 2016-05-05T01:57:15.140

Temporarily putting this on hold until the rules for negative inputs are clarified. – Martin Ender – 2017-03-22T20:18:31.840

No answers