SHENZHEN I/O

SHENZHEN I/O

DIVISIBILITY BY THREE
23 Comments
praneeth.kolichala 23 May, 2024 @ 12:59am 
Low power version: 11 / 420 / 7
Idea: this relies on a lot of random coincidences that work out. The idea is, if the input is 10a+b (ignore 100 for now), then compute 15a+b by using `dgt 1` and `mul 5` to get `5a` and adding the original input again. Use 15a+b as the address inside a ROM.

If we reduce this mod 14, we get a+b. Thus, the data of the ROM can tell is if a+b is a multiple of 3. Unfortunately, sums in the range 0-4 could correspond to 0-4 or 14-18.

The way we can fix this is as follows: if the sum mod 14 is 0-4, then we should add 14 if and only if the original input was >= 50. If the input is < 50, then the max digit sum is 4 + 9 = 13, so there will never be overflow. If it is >= 50, then the digit sum is at least 5, so a result of 0-4 indicates overflow mod 14. Since the threshold (50) is exactly the threshold that the logic gates use to distinguish 0 and 1, we can fix the 14-18 issue using only logic gates (in particular, zero lines of code and zero extra power!).
Verdammte Heinz 28 Jul, 2023 @ 2:04pm 
Alternative high power version in 3 / 3651 / 7
Verdammte Heinz 28 Jul, 2023 @ 1:57pm 
First attempt 7 / 737 / 14
s7eph4n 6 Apr, 2023 @ 6:28am 
I had another go on this problem, optimizing for power. Building on Z903 idea of a 0-39 lookup table, but removed the loop and got it down to a 7/ 451 /10. Unfortunately the code didn't fit into a MC4000 anymore, so I had to use the more expensive MC6000.
FoxClass 29 Mar, 2023 @ 4:06pm 
?
Cocoa 30 Aug, 2022 @ 11:12pm 
Firstly I calculated the sum of every digit, using too many dgt and dst instructions, and got 7/634/11.

Then I realized a + b = 10a + b - 9a , finally solved in 5/498/9.
s7eph4n 19 Oct, 2021 @ 9:49am 
Got a 3/3756/7 ... I guess I'm not a power guy ¯\_(ツ)_/¯
Dan 18 Nov, 2019 @ 9:21am 
My best so far is 5 / 498 / 9.
Digital root calculation similar to @ebik's approach + lookup table

https://i.imgur.com/BdbYVmf.png
ebik 2 Oct, 2018 @ 11:26am 
@Z903 you can reduce inputs to 0, 10, 20, ... 180 instead by multiplying last digit by 9 (= 10 - 1) and adding input then you get 5/480/9 https://imgur.com/MBGL6w3
Z903 18 Jul, 2018 @ 10:16pm 
5/540/9 https://i.imgur.com/Yv0ZmMZ.png Reduced inputs down to 0-39 then modular arithmic on LUT comparing value to reduced value.
ipg 10 Jan, 2018 @ 4:53am 
Did manage to reduce the power slightly at more cost and lines to 9/480/11 but just a cheap trick (well, expensive trick) on top of @AJMansfield's idea
ipg 9 Jan, 2018 @ 2:38am 
@AJMansfield Brilliant wish I'd thought of your approach. Did implement it and match your results but can't take any credit. I am more proud of my alternative which just uses one component with only 683 cost, 5/683/14.
AJMansfield 2 Dec, 2017 @ 11:30am 
Been doing some more reading, and there should be a way to do this with the Chinese Remainder Theorem and similar math as well, I think.
AJMansfield 11 Nov, 2017 @ 5:07pm 
@flarn2006 yes that's the whole reason I had to map it to 0-14, so I could use it as the address for a ROM without any collisions.
Sparkette 24 Oct, 2017 @ 6:09pm 
@AJMansfield: Nice, did you use the ROM chip for the lookup table? Cause if not you could probably save some cost by doing that.
AJMansfield 14 Oct, 2017 @ 4:37pm 
This is a very fun puzzle though, since there are several possible approaches to this problem beyond just a subtraction spin-loop. Probably the coolest one is computing the digital root or decomposing in base 3. I think there might also be another method related to discrete logarithms although I'm not sure.
AJMansfield 14 Oct, 2017 @ 3:54pm 
7 / 506 / 10. How I did it:

I used repeated conditional subtraction with an optimized gap sequence to get the input in the range 0-13, then used that as an address in a lookup table.
slow down cadet 9 Oct, 2017 @ 1:57pm 
You can get a very easy solution (lowest cost and lowest lines) by simply implementing basic division, but getting lowest power solution is quite difficult. It's a fun challenge! I can't get better than 1.1K power right now..
censorship = death :( 8 Oct, 2017 @ 8:18pm 
zero is divisable by anything because there will never be a remainder. it will always be zero unless it's 0/0 and then that's not allowed.
patrickfeltes 19 Aug, 2017 @ 4:30pm 
0 is divisible by 3. By the definition of divisibilty, a number x is divisible by y if x = y*z for some integer z. In the case of 0 and 3, 0 = 3 * 0. Thus, 0 is divisible by 3.
Gkatsos 20 Jul, 2017 @ 11:19am 
Really fun, but 0 is not devisible by 3 :/
xot 12 Jul, 2017 @ 6:23pm 
Nice. This uses simple I/O but the information panel says XBus.
bremdob 9 Jul, 2017 @ 5:55am 
A fun problem that has a very easy solution if you break down division, but otherwise, could be quite complicated and inefficient