#!/usr/bin/python # 2020 京都大学 入学試験 数学(理系)5 # 縦4個,横4個のマス目のそれぞれに 1, 2, 3, 4の数字を入れていく.このマス目の # 横の並びを行といい,縦の並びを列という.どの行にも,どの列にも同じ数字が1回しか # 現れない入れ方は何通りあるか求めよ. from itertools import * r = 0 for a in permutations(range(4)): for b in permutations(range(4)): for c in permutations(range(4)): for d in permutations(range(4)): if (len(set([a[0], b[0], c[0], d[0]])) == 4 and len(set([a[1], b[1], c[1], d[1]])) == 4 and len(set([a[2], b[2], c[2], d[2]])) == 4 and len(set([a[3], b[3], c[3], d[3]])) == 4): r += 1 print(r)