Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ADD10 = / # A + B = C
(?<B0> (?= (?<BC0Rec> [0-9] \g<BC0Rec> [0-9] | \+ .*? 0 ) \= )){0}
(?<B1> (?= (?<BC1Rec> [0-9] \g<BC1Rec> [0-9] | \+ .*? 1 ) \= )){0}
(?<B2> (?= (?<BC2Rec> [0-9] \g<BC2Rec> [0-9] | \+ .*? 2 ) \= )){0}
(?<B3> (?= (?<BC3Rec> [0-9] \g<BC3Rec> [0-9] | \+ .*? 3 ) \= )){0}
(?<B4> (?= (?<BC4Rec> [0-9] \g<BC4Rec> [0-9] | \+ .*? 4 ) \= )){0}
(?<B5> (?= (?<BC5Rec> [0-9] \g<BC5Rec> [0-9] | \+ .*? 5 ) \= )){0}
(?<B6> (?= (?<BC6Rec> [0-9] \g<BC6Rec> [0-9] | \+ .*? 6 ) \= )){0}
(?<B7> (?= (?<BC7Rec> [0-9] \g<BC7Rec> [0-9] | \+ .*? 7 ) \= )){0}
(?<B8> (?= (?<BC8Rec> [0-9] \g<BC8Rec> [0-9] | \+ .*? 8 ) \= )){0}
(?<B9> (?= (?<BC9Rec> [0-9] \g<BC9Rec> [0-9] | \+ .*? 9 ) \= )){0}
(?<C0> (?= \g<BC0Rec> $ )){0}
(?<C1> (?= \g<BC1Rec> $ )){0}
(?<C2> (?= \g<BC2Rec> $ )){0}
(?<C3> (?= \g<BC3Rec> $ )){0}
(?<C4> (?= \g<BC4Rec> $ )){0}
(?<C5> (?= \g<BC5Rec> $ )){0}
(?<C6> (?= \g<BC6Rec> $ )){0}
(?<C7> (?= \g<BC7Rec> $ )){0}
(?<C8> (?= \g<BC8Rec> $ )){0}
(?<C9> (?= \g<BC9Rec> $ )){0}
(?<S0> 0 \g<B0>){0}
(?<S1> 0 \g<B1> | 1 \g<B0>){0}
(?<S2> 0 \g<B2> | 1 \g<B1> | 2 \g<B0>){0}
(?<S3> 0 \g<B3> | 1 \g<B2> | 2 \g<B1> | 3 \g<B0>){0}
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 \g<B9>){0}
(?<Carry0> (?= \g<S9>*+ (?: \g<S0> | \g<S1> | \g<S2> | \g<S3> | \g<S4> | \g<S5> | \g<S6> | \g<S7> | \g<S8> | \+ ))){0}
(?<Carry1> (?= \g<S9>*+ (?: \g<S10> | \g<S11> | \g<S12> | \g<S13> | \g<S14> | \g<S15> | \g<S16> | \g<S17> | \g<S18> ))){0}
^
\g<Carry0>
(?:
(?: \g<S0> | \g<S10>) \g<Carry0> \g<C0>
| (?: \g<S0> | \g<S10>) \g<Carry1> \g<C1>
| (?: \g<S1> | \g<S11>) \g<Carry0> \g<C1>
| (?: \g<S1> | \g<S11>) \g<Carry1> \g<C2>
| (?: \g<S2> | \g<S12>) \g<Carry0> \g<C2>
| (?: \g<S2> | \g<S12>) \g<Carry1> \g<C3>
| (?: \g<S3> | \g<S13>) \g<Carry0> \g<C3>
| (?: \g<S3> | \g<S13>) \g<Carry1> \g<C4>
| (?: \g<S4> | \g<S14>) \g<Carry0> \g<C4>
| (?: \g<S4> | \g<S14>) \g<Carry1> \g<C5>
| (?: \g<S5> | \g<S15>) \g<Carry0> \g<C5>
| (?: \g<S5> | \g<S15>) \g<Carry1> \g<C6>
| (?: \g<S6> | \g<S16>) \g<Carry0> \g<C6>
| (?: \g<S6> | \g<S16>) \g<Carry1> \g<C7>
| (?: \g<S7> | \g<S17>) \g<Carry0> \g<C7>
| (?: \g<S7> | \g<S17>) \g<Carry1> \g<C8>
| (?: \g<S8> | \g<S18>) \g<Carry0> \g<C8>
| (?: \g<S8> | \g<S18>) \g<Carry1> \g<C9>
| (?: \g<S9> ) \g<Carry0> \g<C9>
| (?: \g<S9> ) \g<Carry1> \g<C0>
)++
\+ [0-9]++ \= [0-9]++ $
/x
ADD2 = / # A + B = C
(?<B0> (?= (?<B0Rec> [01] \g<B0Rec> [01] | \+ .*? 0 ) \= )){0}
(?<B1> (?= (?<B1Rec> [01] \g<B1Rec> [01] | \+ .*? 1 ) \= )){0}
(?<C0> (?= (?<C0Rec> [01] \g<C0Rec> [01] | \+ .*? 0 ) $ )){0}
(?<C1> (?= (?<C1Rec> [01] \g<C1Rec> [01] | \+ .*? 1 ) $ )){0}
(?<Carry0> (?= (?: 1 \g<B0> | 0 \g<B1> )*+ (?: 0 \g<B0> | \+ ))){0}
(?<Carry1> (?= (?: 1 \g<B0> | 0 \g<B1> )*+ 1 \g<B1> )){0}
^
\g<Carry0>
(?:
0 \g<B0> \g<Carry0> \g<C0>
| 0 \g<B0> \g<Carry1> \g<C1>
| 0 \g<B1> \g<Carry0> \g<C1>
| 0 \g<B1> \g<Carry1> \g<C0>
| 1 \g<B0> \g<Carry0> \g<C1>
| 1 \g<B0> \g<Carry1> \g<C0>
| 1 \g<B1> \g<Carry0> \g<C0>
| 1 \g<B1> \g<Carry1> \g<C1>
)++
\+ [01]++ \= [01]++ $
/x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.