From 980f4a51823bdc7535e04c2f0cc0cce2c7916fd5 Mon Sep 17 00:00:00 2001 From: John Mettraux Date: Wed, 14 Sep 2022 13:32:05 +0900 Subject: [PATCH] Add tst/modulor.rb for gh-76 --- tst/modulo.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tst/modulo.rb diff --git a/tst/modulo.rb b/tst/modulo.rb new file mode 100644 index 0000000..785ee44 --- /dev/null +++ b/tst/modulo.rb @@ -0,0 +1,25 @@ + +def show(mod0, mod1) + + puts "%#{mod0}+#{mod1}" + (mod0 + 1).times do |i| + print "%3d: " % [ + i ] + print "%d %% %d --> %d" % [ + i, mod0, i % mod0 ] + print " | %d %% %d == %d --> %5s" % [ + i, mod0, i % mod0, (i % mod0) == mod1 ] + print " | (%d + %d) %% %d == 0 --> %5s" % [ + i, mod0, mod1, (i + mod1) % mod0 == 0 ] + print " | %d %% %d == %d %% %d --> %5s" % [ + i, mod0, mod1, mod0, i % mod0 == mod1 % mod0 ] + puts + end +end + +puts; show(2, 1) +puts; show(3, 2) +puts; show(2, 2) +puts; show(2, 4) +puts; show(4, 3) +