在polog的密码算术难题中C1意味着什么?

时间:2013-05-27 04:04:17

标签: prolog cryptarithmetic-puzzle

这是prolog中的一个密码算术片段

sum1( [D1|N1], [D2|N2], [D|N], C1, C, Digs1, Digs)  :-
  sum1( N1, N2, N, C1, C2, Digs1, Digs2),
  digitsum( D1, D2, C2, D, C, Digs2, Digs).

如下所述

sum1( N1, N2, N, C1, C, Digits1, Digits)
where N1, N2 and N are our three numbers, 
      C1 is carry from the right, and
      C is carry to the left (after the summation).
      Digits1 is the list of available digits for instantiating the
      variables in N1, N2, and N.
      Digits is the list of digits that were not used in the
      instantiation of these variables.

我真的不明白C1在sum1( [D1|N1], [D2|N2], [D|N], C1, C, Digs1, Digs)中意味着什么,因为C2代表进位形式,C代表左侧进位,那么C1代表什么?

1 个答案:

答案 0 :(得分:1)

C,C1,C2只能假设0,1值。算术规则要求C1在第一次调用时为0,在最后一次调用时C为0。 C2在递归调用时变为C,然后在总和之后传播进位。 C1是进位加到N1,N2加到N.