<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.simia.net/index.php?action=history&amp;feed=atom&amp;title=Unique_digits_addition_-_Markus_v2</id>
	<title>Unique digits addition - Markus v2 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://www.simia.net/index.php?action=history&amp;feed=atom&amp;title=Unique_digits_addition_-_Markus_v2"/>
	<link rel="alternate" type="text/html" href="http://www.simia.net/index.php?title=Unique_digits_addition_-_Markus_v2&amp;action=history"/>
	<updated>2026-05-16T01:36:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>http://www.simia.net/index.php?title=Unique_digits_addition_-_Markus_v2&amp;diff=2691&amp;oldid=prev</id>
		<title>Denny: Created page with &quot;&lt;pre&gt; ## Create valid solutions by composing triples of two-digit additions, ## as they occur vertically in written addition. Distinguish cases by ## whether or not an incomin...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.simia.net/index.php?title=Unique_digits_addition_-_Markus_v2&amp;diff=2691&amp;oldid=prev"/>
		<updated>2025-08-24T14:41:48Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;pre&amp;gt; ## Create valid solutions by composing triples of two-digit additions, ## as they occur vertically in written addition. Distinguish cases by ## whether or not an incomin...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
## Create valid solutions by composing triples of two-digit additions,&lt;br /&gt;
## as they occur vertically in written addition. Distinguish cases by&lt;br /&gt;
## whether or not an incoming carry 1 is added, and whether the output&lt;br /&gt;
## produces such a carry for the next step.&lt;br /&gt;
## &lt;br /&gt;
## To print solutions, activated all commented-out print()'s below.&lt;br /&gt;
&lt;br /&gt;
triples_n_n = [] # no carry in, no carry out&lt;br /&gt;
triples_n_c = [] # no carry in, carry out&lt;br /&gt;
triples_c_n = [] # carry in, no carry out&lt;br /&gt;
triples_c_c = [] # carry in, carry out&lt;br /&gt;
for d1 in range(0,10):&lt;br /&gt;
    for d2 in range(0,10):&lt;br /&gt;
        if d1==d2: continue&lt;br /&gt;
        mask = (1&amp;lt;&amp;lt;d1) | (1&amp;lt;&amp;lt;d2)&lt;br /&gt;
        dsum = d1+d2&lt;br /&gt;
        if dsum &amp;gt;= 10:  # no carry in, carry out&lt;br /&gt;
            triples_n_c.append((mask | (1 &amp;lt;&amp;lt; dsum-10), d1, d2))&lt;br /&gt;
        elif d1 != 0 and d2 != 0:  # no carry in, no carry out&lt;br /&gt;
            triples_n_n.append((mask | (1 &amp;lt;&amp;lt; dsum), d1, d2))&lt;br /&gt;
&lt;br /&gt;
        if dsum &amp;lt;= 8:  # carry in, no carry out&lt;br /&gt;
            triples_c_n.append((mask | (1 &amp;lt;&amp;lt; dsum+1), d1, d2))&lt;br /&gt;
        elif d1 != 9 and d2 != 9: # carry in, carry out&lt;br /&gt;
            triples_c_c.append((mask | (1 &amp;lt;&amp;lt; dsum-9), d1, d2))&lt;br /&gt;
&lt;br /&gt;
# Depth-first search composing triples from right to left.&lt;br /&gt;
# Used-up digits are stored in agg_mask, carry is boolean, factor is a decimal shift factor (1, 10, 100, 1000).&lt;br /&gt;
#&lt;br /&gt;
# As triples are added to both numbers sychronously, they always have the same length. Other results (such as&lt;br /&gt;
# 1965 + 78 = 2043) are created from shorter additions with leading carry (here 65 + 78 = 143) by pre-pending more&lt;br /&gt;
# digits (here 19). This can only work if there is a leading carry, so this case is a bit lengthy.&lt;br /&gt;
def dfs(agg_mask, carry, num1, num2, factor):&lt;br /&gt;
    solutions = 0&lt;br /&gt;
&lt;br /&gt;
    if carry:&lt;br /&gt;
        if factor &amp;gt;= 10: # at least one digit picked&lt;br /&gt;
            if (agg_mask &amp;amp; 2) == 0: # valid result as is (0 not written, carry yields 1)&lt;br /&gt;
                # print(f&amp;quot;{num1} + {num2} = {num1+num2}&amp;quot;)&lt;br /&gt;
                solutions += 1&lt;br /&gt;
            for i in range(1,9):&lt;br /&gt;
                if (agg_mask &amp;amp; (3&amp;lt;&amp;lt;i)) == 0: # add leading digit 1..8 (check that result digit+1 is no dup)&lt;br /&gt;
                    # print(f&amp;quot;{num1+factor*i} + {num2} = {num1+num2+factor*i}&amp;quot;)&lt;br /&gt;
                    # print(f&amp;quot;{num1} + {num2+factor*i} = {num1+num2+factor*i}&amp;quot;)&lt;br /&gt;
                    solutions += 2&lt;br /&gt;
            if (agg_mask &amp;amp; (1|(1&amp;lt;&amp;lt;9))) == 0: # add leading digit 9 or leading x9 (check that 0 is no dup)&lt;br /&gt;
                if (agg_mask &amp;amp; 2)==0: # add leading digit 9 (check that result 1 is no dup)&lt;br /&gt;
                    # print(f&amp;quot;{num1+factor*9} + {num2} = {num1+num2+factor*9}&amp;quot;)&lt;br /&gt;
                    # print(f&amp;quot;{num1} + {num2+factor*9} = {num1+num2+factor*9}&amp;quot;)&lt;br /&gt;
                    solutions += 2&lt;br /&gt;
                for i in range(1,8): # add leading digit i9 (check that i and result i+1 is no dup), leading 8 is excluded since we already have 9&lt;br /&gt;
                    if (agg_mask &amp;amp; (3&amp;lt;&amp;lt;i)) == 0:&lt;br /&gt;
                        # print(f&amp;quot;{num1+factor*9+(factor*10)*i} + {num2} = {num1+num2+factor*9+(factor*10)*i}&amp;quot;)&lt;br /&gt;
                        # print(f&amp;quot;{num1} + {num2+factor*9+(factor*10)*i} = {num1+num2+factor*9+(factor*10)*i}&amp;quot;)&lt;br /&gt;
                        solutions += 2&lt;br /&gt;
                        &lt;br /&gt;
        if factor &amp;gt;= 1000: return solutions # don't explore over 3-digit pairs&lt;br /&gt;
&lt;br /&gt;
        next_factor = factor * 10&lt;br /&gt;
        for rec in triples_c_n:&lt;br /&gt;
            if rec[0] &amp;amp; agg_mask == 0:&lt;br /&gt;
                solutions += dfs(rec[0]|agg_mask, False, num1 + rec[1] * factor, num2 + rec[2] * factor, next_factor)&lt;br /&gt;
        for rec in triples_c_c:&lt;br /&gt;
            if rec[0] &amp;amp; agg_mask == 0:&lt;br /&gt;
                solutions += dfs(rec[0]|agg_mask, True, num1 + rec[1] * factor, num2 + rec[2] * factor, next_factor)&lt;br /&gt;
    else:&lt;br /&gt;
        if factor &amp;gt;= 10 and num1 &amp;gt;= factor//10 and num2 &amp;gt;= factor//10: # at least one digit picke AND there are no leading zeros&lt;br /&gt;
            # print(f&amp;quot;{num1} + {num2} = {num1+num2}&amp;quot;)&lt;br /&gt;
            solutions += 1&lt;br /&gt;
        &lt;br /&gt;
        if factor &amp;gt;= 1000: return solutions # don't explore over 3-digit pairs&lt;br /&gt;
        &lt;br /&gt;
        next_factor = factor * 10&lt;br /&gt;
        for rec in triples_n_n:&lt;br /&gt;
            if rec[0] &amp;amp; agg_mask == 0:&lt;br /&gt;
                solutions += dfs(rec[0]|agg_mask, False, num1 + rec[1] * factor, num2 + rec[2] * factor, next_factor)&lt;br /&gt;
        for rec in triples_n_c:&lt;br /&gt;
            if rec[0] &amp;amp; agg_mask == 0:&lt;br /&gt;
                solutions += dfs(rec[0]|agg_mask, True, num1 + rec[1] * factor, num2 + rec[2] * factor, next_factor)&lt;br /&gt;
    return solutions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print(dfs(0, False, 0, 0, 1))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Denny</name></author>
		
	</entry>
</feed>