From 339852a435daa00c0f8057edc51ed74fe03824b4 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Wed, 5 Oct 2022 09:15:41 -0700 Subject: [PATCH] Kinda sorta not really working, as in broken. This is getting out of hand. --- bigjoyints/divmod.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/bigjoyints/divmod.py b/bigjoyints/divmod.py index 8231968..f23e3f0 100644 --- a/bigjoyints/divmod.py +++ b/bigjoyints/divmod.py @@ -35,20 +35,20 @@ def div_mod(A, B): # So we have divided a prefix of A by B # resulting in a digit q of the answer Q # and a remainder R that must be extended - # with the rest of the digits of A to make - # a new number N - - N = A + R + # with the more digits of A to make a new + # number N >= B + + Q = [] + N = R + while A and -1 == cmp_digits(N, B): + N.insert(0, A.pop()) + Q.insert(0, 0) + Q.append(q) + if not A: + return Q, N - # which then must either be the remainder of - # the whole thing if N < B... - if -1 == cmp_digits(N, B): - return [q], N - # Otherwise, we find the rest of the digits - # by - Q, R = div_mod(N, B) - Q.append(digit) - return Q, R + Qz, R = div_mod(N, B) + return Qz + Q, R def lil_divmod(A, B): assert -1 < cmp_digits(A, B) @@ -119,6 +119,7 @@ def try_it(a, b): try_it(145, 72) try_it(1450, 72) +try_it(145000, 72) ##print(cmp_digits([], [])) -- 2.11.0