79129010

Date: 2024-10-26 16:46:36
Score: 0.5
Natty:
Report link

I realize I'm a 'little' late, but here goes for future generations:

In order to avoid the exponential expension described in the question we have to introduce new variables and make two expressions 1) make expression that encodes a number 2) make an expression that can compare against the encoding

I'm using binary encoding here so 3 -> 11 and 9 -> 1001, this should be familiar to programmers

Now let's introduce a full adder (google this). This will add three bits returning two new variables 'sum' and 'carry'

Sum is 1 only if an odd number of bits are 1: (Sum & ((a&-b&-c)|(-a&b&-c)|(-a&-b&c)|(a&b&c))) | (-sum & -((a&-b&-c)|(-a&b&-c)|(-a&-b&c)|(a&b&c)))

Carry is 1 if at least 2 bits are 1: (Carry & ((a&b)|(a&c)|(c&b))|( -Carry & -((a&b)|(a&c)|(c&b)))

This now encodes the sum of two variables. This principle can be chained in order to add any number it variables (Google that too)

For comparison e.g. with 3 where ex is the encoded number: -En&...-E2&E1&E0 (because three is ...000011 in binary)

I hope it helps somebody, cheers!

Reasons:
  • Blacklisted phrase (1): cheers
  • Whitelisted phrase (-1): hope it helps
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: jiquera