
背景需求:
之前做了三宫格所有可能图片 510小图*12套=6120图,所以3分钟就生成了
【教学类-43-25】20240311 数独3宫格的所有可能(图片版 12套样式,空1格-空8格,每套510张,共6120小图)-优快云博客文章浏览阅读663次,点赞12次,收藏11次。【教学类-43-25】20240311 数独3宫格的所有可能(图片版 12套样式,空1格-空8格,每套510张,共6120小图)
https://blog.youkuaiyun.com/reasonsummer/article/details/146190184?spm=1011.2415.3001.5331
现在我想制作四宫格的所有图片,已知四宫格的数量是三个格的指数倍数。
把3宫格代码修改一下,做 一套4宫格所有可能(图片版)
'''
目的:数独4宫格,所有可能样式,做成图片(调整下划线位置
作者:阿夏
时间:20250311
'''
import math,os,time
from itertools import permutations
import random
from win32com.client import constants, gencache
from win32com.client.gencache import EnsureDispatch
from docx import Document
from docx.shared import Pt, RGBColor
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT, WD_BREAK
from docx.oxml.ns import qn
from docxtpl import DocxTemplate
import pandas as pd
from docx2pdf import convert
from datetime import datetime
from PIL import Image, ImageDraw, ImageFont
import os
import copy
# 开始时间
start_time = datetime.now()
# 制作"单元格"# 几宫格
hs=4
# int(input('4宫格数独=3\n'))
# 内容太多了,容易报错,如果报错,就重新设置起始宫格数字1-8
start=1
# 第几套,第一套
# 新建一个”装N份word和PDF“的临时文件夹
# 创建输出目录
path = r'C:\Users\jg2yXRZ\OneDrive\桌面\20250311 4宫格所有可能(图片版)\01四宫格图片版'
os.makedirs(path, exist_ok=True)
output_dir = path + r'\00全部'
os.makedirs(output_dir, exist_ok=True)
print('------第2步:制作4宫格的12套题的内容-------')
# 制作4宫格的12套题目(没有空格,只有基础模板)
lst=[]
for b in range(1,hs+1):
lst.append(b)
print(lst)
permutations_list = list(permutations(lst))
numbers = [list(permutation) for permutation in permutations_list]
# print(numbers)
# [[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2], [2, 1, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [2, 3, 4, 1], [2, 4, 1, 3], [2, 4, 3, 1], [3, 1, 2, 4], [3, 1, 4, 2], [3, 2, 1, 4], [3, 2, 4, 1], [3, 4, 1, 2], [3, 4, 2, 1], [4, 1, 2, 3], [4, 1, 3, 2], [4, 2, 1, 3], [4, 2, 3, 1], [4, 3, 1, 2], [4, 3, 2, 1]]PS D:\test>
# 6种组合
# 互相组合成3组
import itertools
# 计算排列数量并生成所有可能的排列
combinations2 = list(itertools.permutations(numbers, hs))
# 包含相似的
# 输出排列数量
print(len(combinations2))
# 120
# # 把所有数字都提取成元素
ll=[]
for o1 in combinations2:
for o2 in o1:
for o3 in o2:
ll.append(o3)
print(ll)
print(len(ll))
# 1080
v=hs*hs
# 9个数字抽取一组
f=[]
for i in range(int(len(ll)/v)):
f.append(ll[i*v:i*v+v])
# print(f)
# print(len(f))
#120条
# # # 遍历表格,把0、5、10相同的内容删除,横向的数字1234都正确了,现在只要排除竖向不对的
P=[]
z=[]
for k in f:
if int(k[0])!=int(k[4])and int(k[0])!=int(k[8])and int(k[0])!=int(k[12]) and int(k[4])!=int(k[8]) and int(k[4])!=int(k[12])and int(k[8])!=int(k[12]) and int(k[0])+int(k[4])+int(k[8])+int(k[12])==10 and \
int(k[1])!=int(k[5])and int(k[1])!=int(k[9])and int(k[1])!=int(k[13]) and int(k[5])!=int(k[9]) and int(k[5])!=int(k[13])and int(k[9])!=int(k[13]) and int(k[1])+int(k[5])+int(k[9])+int(k[13])==10 and \
int(k[2])!=int(k[6])and int(k[2])!=int(k[10])and int(k[2])!=int(k[14]) and int(k[6])!=int(k[10]) and int(k[6])!=int(k[14])and int(k[10])!=int(k[14]) and int(k[2])+int(k[6])+int(k[10])+int(k[14])==10 and\
int(k[3])!=int(k[7])and int(k[3])!=int(k[11])and int(k[3])!=int(k[15]) and int(k[7])!=int(k[11]) and int(k[7])!=int(k[15])and int(k[11])!=int(k[15]) and int(k[3])+int(k[7])+int(k[11])+int(k[15])==10:
z.append(k)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