# In the 2022 1024 card event, how do programmers judge whether their cards can form 1024? Then have fun programming it︕

# In the 2022 1024 card event, how do programmers judge whether their cards can form 1024? Then have fun programming!

If you already know this activity, just skip to the code.

Similar to last year, this year’s Likou held the 1024 Programmer’s Day event.

The event address ishttps://leetcode.cn/2022-1024/

The activity guide ishttps://leetcode.cn/circle/discuss/OV9VUd/

Let me explain first, this article**Not an advertisement**, because there are many programmers who are obsessed with it, and there is no need for me, a small blogger with no traffic, to promote it.

Probably the gameplay is to obtain cards through various channels

Cards are divided into*digital card*and*Compliant card*

Through three operations of four numbers, the result is obtained`1024`

, you will get a “1024 coin”

Soon, I will have a lot of cards, so the question is, can I make up 1024 with so many cards?

Then have fun programming!

Just change the “numbers” and “operators” in the Python code below to your own, and then run the script.

The program will automatically calculate whether your card can get 1024 through “four counts and three counts”.

For example, my current cards include:`[2, 13, 4, 26, 2, 2, 14, 18, 2]`

and`[">>", "&", "|", "|", "%"]`

Then the running result is:

`[]`

┭┮﹏┭┮

But if “the first successfully synthesized card of a great god in the entire network”:`[16, 2, 16, 0]`

and`["<<", "*", "+"]`

Then the running result is

`['(((16<<2)*16)+0)', '(((16<<2)+0)*16)', '(((16*16)<<2)+0)', '(((16*16)+0)<<2)', '(((16+0)<<2)*16)', '(((16+0)*16)<<2)', '(((16*16)<<2)+0)', '(((16*16)+0)<<2)', '(((16<<2)*16)+0)', '(((16<<2)+0)*16)', '(((16+0)*16)<<2)', '(((16+0)<<2)*16)', '(((0+16)<<2)*16)', '(((0+16)*16)<<2)', '(((0+16)*16)<<2)', '(((0+16)<<2)*16)']`

There are many ways to form 1024.

Okay, enough nonsense, here’s the code:

## version 1

```
'''
Author: LetMeFly
Date: 2022-10-19 15:41:14
LastEditors: LetMeFly
LastEditTime: 2022-10-19 18:25:27
'''
# Just change the number cards and symbol cards here to your own
numbers = [2, 13, 4, 26, 2, 2, 14, 18, 2]
operators = [">>", "&", "|", "|", "%"]
ok = []
for n1 in range(len(numbers)):
for n2 in range(len(numbers)):
for n3 in range(len(numbers)):
for n4 in range(len(numbers)):
for o1 in range(len(operators)):
for o2 in range(len(operators)):
for o3 in range(len(operators)):
if (n1 == n2 or n1 == n3 or n1 == n4 or n2 == n3 or n2 == n4 or n3 == n4) or (o1 == o2 or o2 == o3 or o1 == o3):
continue
string = f"((({numbers[n1]}{operators[o1]}{numbers[n2]}){operators[o2]}{numbers[n3]}){operators[o3]}{numbers[n4]})"
if eval(string) == 1024:
ok.append(string)
print(ok)
```

## Version 2 (updated on 2022-10-20 10 52)

- Fixed a bug where the dividend may be 0 during modulo or division operations.
- Shows the number of attempts

```
'''
Author: LetMeFly
Date: 2022-10-19 15:41:14
LastEditors: LetMeFly
LastEditTime: 2022-10-20 10:22:52
'''
# numbers = [16, 2, 16, 0]
# operators = ["<<", "*", "+"]
numbers = [0, 12, 5, 2, 3, 19, 2, 18, 2, 13, 4, 26, 2, 2, 14]
operators = ["*", ">>", "&", "|", "|", "%"]
ok = []
print(f"{len(numbers)} ^ 4 * {len(operators)} ^ 3 = {len(numbers) ** 4 * len(operators) ** 3}")
for n1 in range(len(numbers)):
for n2 in range(len(numbers)):
for n3 in range(len(numbers)):
for n4 in range(len(numbers)):
for o1 in range(len(operators)):
for o2 in range(len(operators)):
for o3 in range(len(operators)):
if (n1 == n2 or n1 == n3 or n1 == n4 or n2 == n3 or n2 == n4 or n3 == n4) or (o1 == o2 or o2 == o3 or o1 == o3):
continue
string = f"((({numbers[n1]}{operators[o1]}{numbers[n2]}){operators[o2]}{numbers[n3]}){operators[o3]}{numbers[n4]})"
try:
if eval(string) == 1024:
ok.append(string)
except:
pass
print(ok)
```

I write this article for two purposes, one is to share, and the other is to gain some followers.

**I made a simple little website that can do online calculations**：Count1024.LetMeFly.xyz

**I made another website where you can receive and share cards**： Share1024.LetMeFly.xyz

Posted simultaneously on, originality is not easy, please attach it when reprintingOriginal linkOh~

Tisfy：https://letmefly.blog.csdn.net/article/details/127413787