咕咕鸡鸽鸽 发表于 2019-1-5 09:29:34

kankan

shencong132 发表于 2019-1-5 23:18:40

想看!!?

北城以北灬 发表于 2019-3-15 11:03:12

import itertools


list1 =
count = 1
for i in itertools.permutations(list1, 4):
    list2 = * 9
    list2 = 5

    if len(set() & set(i)) == 0:
      for j in range(4):
            list2 = i
            list2 = 10 - i
      if sum(list2) == 15 and sum(list2) == 15:
            print('NO.', count)
            for num in range(3):
                print(list2)
            print()
            count += 1

克里斯保罗 发表于 2019-9-1 20:08:51

为啥是15啊~想不通 而且504种是包括 {1,2,3}和{1,2,8}这种有重复数字的{:10_285:}

Jung 发表于 2019-11-30 11:17:51

def fun27():
    L = []
    L2 = []
    L3 = []
    for i1 in range(1,10):
      for i2 in range(1,10):
            for i3 in range(1,10):
                if i3!=i2 and i2!=i1 and i3!=i1:
                  L.append(i1)
                  L.append(i2)
                  L.append(i3)
    for k in range(len(L)//3):
      L2.append(L)
    for t in range(len(L2)):
      L2
      for t1 in range(len(L2)):
            L2
            for t2 in range(len(L2)):
                L2
                if (((L2+L2+L2)==15) and ((L2+L2+L2)==15)) and (sum(L2)==15) and (sum(L2)==15) and (sum(L2)==15)and ((L2+L2+L2)==15)and ((L2+L2+L2)==15) and ((L2+L2+L2)==15):
                  L3.append(L2)
                  L3.append(L2)
                  L3.append(L2)
                  print(L3)
                  L3 = []
结果如下:
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
[, , ]
我想问一下,格子里面的数,在三个数组中不能重复出现?
我这个程序的执行效率比较慢
                                       

华一仙 发表于 2020-2-26 10:17:47

"""
1 2 3
\ | /
4'- + -4
/ | \
3' 2' 1'

由题意得 1, 2, 3, 4 四条路和相等
=> 1 + 1' = 2 + 2' = 3 + 3' = 4 + 4'
从 1 ~ 9 中取四对数,使其和相等,只能首尾配对
(1, 9), (2, 8), (3, 7), (4, 6)
=> 中间为 5
=> 每条路的和为 15
=> 九宫图“四条边”每边和也为 15

从上述四对数中在配对前提下取 3 个数作边,仅能凑 4 组
(1, 6, 8)
(2, 4, 9), (2, 6, 7)
(3, 4, 8)
=> 2, 4, 6, 8 均出现两次,故为四角
2 与 4, 6 搭配,故 2 与 4, 6 相邻,8 为 2 的对角
剩下的数按上述新的四对补齐即可

严格来说,九宫图只有一种解,其他解均由此解或旋转,或镜像得到
题目给出 1 解,旋转可再得 3 解,镜像后又有 4 解 => 共 8 解
"""

def printGridView(nums):
    global cnt
    cnt += 1
    print(f"No.{cnt}:")
    for i in range(3):
      for j in range(2):
            print(nums, end=" | ")
      print(nums, "\n-   -   -")
    print('=' * 10)


def mirror(nums):
    for i in range(3):
      nums, nums = nums, nums


def clockWise(nums):
    res = [*3 for _ in range(3)]
    for i in range(3):
      for j in range(3):
            res = nums
    return res


def solve(nums):
    for i in range(2):
      for j in range(4):
            nums = clockWise(nums)
            printGridView(nums)
      mirror(nums)


if __name__ == "__main__":
    nums = [,
            ,
            ]
    cnt = 0
    solve(nums)

杜若左 发表于 2020-3-21 15:54:07

我感觉太难了,看看答案学习一下。

紫烟眷书 发表于 2020-3-21 20:21:44

学习学习

holiday_python 发表于 2020-4-16 09:58:19

d

19971023 发表于 2020-5-31 09:35:03

1

nononoyes 发表于 2020-6-8 14:12:51

666

z2x2c8 发表于 2020-9-11 21:58:14

看看

aironeng 发表于 2020-11-30 09:28:45

学习

sanchuan555 发表于 2021-1-3 00:42:00

list_num=
times=0
list_sum=[]
#横向相加等于15
for a in list_num:
    for b in list_num:
      for c in list_num:
            if a+b+c==15:
                times+=1
                list_3=[]
                list_3.append(a)
                list_3.append(b)
                list_3.append(c)
                list_sum.append(list_3)
                print(a,b,c,times)
print(list_sum)
#纵向第一列相加等于15
list_sum2=[]
for a in list_sum:
    for b in list_sum:
      for c in list_sum:
            list_upright1=[]
            if a+b+c==15:
                list_upright1.append(a)
                list_upright1.append(b)
                list_upright1.append(c)
                list_sum2.append(list_upright1)
print(list_sum2)
#减去重复含有重复数字的数列
count2=0
count3=0
list_sum3=[]
for a in list_sum2:
    count2+=1
    print(a,count2)
    str1=''
    for b in a:
      for c in b:
            if str(c) not in str1:
                str1=str1+str(c)
            else:
                break
    if len(str1)==9:
      count3+=1
      list_sum3.append(a)
print(list_sum3,count3)
#第二列相加等于15 第三列也自然等于15了
list_sum4=[]
count3=0
for a in list_sum3:
    if a+a+a==15:
      list_sum4.append(a)
      count3+=1
    else:
      pass
print(list_sum4,count3)
#斜向相加等于15
list_sum5=[]
count4=0
for a in list_sum4:
    if a+a+a==15:
      list_sum5.append(a)
      count4 += 1
    else:
      pass
print(list_sum5,count4)
list_sum6=[]
count5=0
for a in list_sum5:
    if a+a+a==15:
      list_sum6.append(a)
      count5 += 1
    else:
      pass
print(list_sum6,count5)

wwwwwise 发表于 2021-2-18 15:56:35

1
页: 1 2 [3]
查看完整版本: Python:每日一题 27(答题领鱼币)