Home python How to solve the task for the bonnetation conjunction

How to solve the task for the bonnetation conjunction

Author

Date

Category

Denote by M & AMP; N Diffex conjunction of non-negative integers m and n.

so, for example, 14 & amp; 5 = 1110 & amp; 0101 = 0100 = 4. For which smallest non-negative integer A formula

x & amp; 29 ≠ 0 → (X & amp; 17 = 0 → X & amp; A ≠ 0)

identically true (i.e. takes value 1 at any non-negative whole value of the variable x)?


wrote the function of this conjunction and implication, then the function of the extinguishing of all x to 100 with any A, which will return False, if at least one value has not passed.

def conc (n, k):
  n = bin (n) [2:]
  k = bin (k) [2:]
  s = ''
  IF Len (n)! = Len (k):
    IF LEN (N) & GT; Len (k):
      k = '0' * (Len (n) - len (k)) + k
    ELSE:
      n = '0' * (len (k) - len (n)) + n
  For i in Range (Len (N)):
    IF N [i] == K [i]:
      S + = '1'
    ELSE:
      S + = '0'
  RETURN INT (S, 2)
Def impl (X, Y): Return Not X OR Y
DEF F (A):
  For X in Range (10,000):
    IF Not impl (CONC (X, 29)! = 0, impl (CONC (X, 17) == 0, CONC (X, A)! = 0)):
      Return False.
  Return A.
For i in Range (100):
  IF F (i)! = False: Print (I)

Conjunction and implication functions like the correct, but when executing the program, it gives all values ​​from 2 to 100. In response to the task number 12. Where I was wrong, I will fight over the challenge, but I can’t understand ??


Answer 1, Authority 100%

if n [i] == k [i]:
    S + = '1'
  ELSE:
    S + = '0'

This is not Bitched and (conjunction), it is necessary that both discharge are not only equal to each other, but also equal to 1 at the same time, so it will be right:

ife n [i] == k [i] == '1':
    S + = '1'
  ELSE:
    S + = '0'

After this correction code output:

12
13
fourteen
15
28.
29.
thirty
31.
44.
45.
46.
47.
60.
61.
62.
63.
76.
77.
78.
79.
92.
93.
94.
95.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions