Ejemplo n.º 1
0
def check_case(l):
    max_num = 0
    for case in pd(nums, repeat=l):
        num = int(''.join(map(str, case)))
        if num <= N:
            max_num = max(max_num, num)
    return max_num
Ejemplo n.º 2
0
 def __edges_coordinates_gen(self, mult, i):
     n = self.dimension - 1
     coords = [
         # YB_edges
         ((n, n, n), (-n, -n, -n), (n - i * mult, -n + i * mult, -n + i * mult)),
         # WB_edges
         ((n, n, n), (n, n, n), (n - i * mult, -n + i * mult, -n + i * mult)),
         # YG_edges
         ((-n, -n, -n), (-n, -n, -n), (n - i * mult, -n + i * mult, -n + i * mult)),
         # WG_edges
         ((-n, -n, -n), (n, n, n), (n - i * mult, -n + i * mult, -n + i * mult)),
         # GO_edges
         ((-n, -n, -n), (n - i * mult, -n + i * mult, -n + i * mult), (-n, -n, -n)),
         # OB_edges
         ((n, n, n), (n - i * mult, -n + i * mult, -n + i * mult), (-n, -n, -n)),
         # BR_edges
         ((-n, -n, -n), (n - i * mult, -n + i * mult, -n + i * mult), (n, n, n)),
         # RG_edges
         ((n, n, n), (n - i * mult, -n + i * mult, -n + i * mult), (n, n, n)),
         # WO_edges
         ((n - i * mult, -n + i * mult, -n + i * mult), (n, n, n), (-n, -n, -n)),
         # WR_edges
         ((n - i * mult, -n + i * mult, -n + i * mult), (n, n, n), (n, n, n)),
         # YR_edges
         ((n - i * mult, -n + i * mult, -n + i * mult), (-n, -n, -n), (n, n, n)),
         # YO_edges
         ((n - i * mult, -n + i * mult, -n + i * mult), (-n, -n, -n), (-n, -n, -n))
     ]
     return [tuple(set(pd(*coords[j]))) for j in range(len(self.__edges))]
Ejemplo n.º 3
0
def get_pins(observed):
    NUMPAD_NABR = ('08', '124', '2135', '326', '4157', '52468', '6359', '748',
                   '85790', '968')
    adjoiners = [NUMPAD_NABR[int(n)] for n in observed]
    adjointed_lst = list(pd(*adjoiners))
    pers_id_num_comb = [''.join(r) for r in adjointed_lst]
    return (pers_id_num_comb)
Ejemplo n.º 4
0
def getMoneySpent(keyboards, drives, b):
    if min(keyboards) + min(drives) > b: return -1
    arr = list(pd(keyboards, drives))
    price = set()
    for i in arr:
        if sum(i) <= b:
            price.add(sum(i))
    return max(price)
Ejemplo n.º 5
0
 def __init__(self, mat_cls, mesh_cls, prob_dict):
     # equation name
     self._name = 'nda'
     # mesh data
     self._mesh = mesh_cls
     self._cell_length = mesh_cls.cell_length()
     # quantities of interest
     self._keff = 1.0
     self._keff_prev = 1.0
     # preassembly-interpolation data
     self._elem = Elem(self._cell_length)
     # material ids and group info
     self._mids = mat_cls.get('ids')
     self._n_grp = mat_cls.get('n_grps')
     self._g_thr = mat_cls.get('g_thermal')
     # mesh
     self._mesh = msh_cls
     # problem type
     self._is_eigen = prob_dict['is_eigen_problem']
     self._do_ua = prob_dict['do_ua']
     # linear algebra objects
     self._sys_mats = {}
     self._sys_rhses = {
         k: np.ones(self._n_dof)
         for k in xrange(self._n_tot)
     }
     self._fixed_rhses = {
         k: np.zeros(self._n_dof)
         for k in xrange(self._n_tot)
     }
     self._sflxes = {k: np.ones(self._n_dof) for k in xrange(self._n_grp)}
     # linear solver objects
     self._lu = {}
     # total number of components: keep consistency with HO
     self._n_tot = self._n_grp
     # all material
     self._dcoefs = mat_cls.get('diff_coef')
     self._sigts = mat_cls.get('sig_t')
     self._sigses = mat_cls.get('sig_s')
     self._sigrs = mat_cls.get('sig_r')
     self._fiss_xsecs = mat_cls.get('chi_nu_sig_f')
     # derived material properties
     self._sigrs_ua = mat_cls.get('sig_r_ua')
     self._dcoefs_ua = mat_cls.get('diff_coef_ua')
     # fission source
     self._global_fiss_src = self._calculate_fiss_src()
     self._global_fiss_src_prev = self._global_fiss_src
     # assistance object
     self._local_dof_pairs = pd(xrange(4), xrange(4))
Ejemplo n.º 6
0
 def __centers_coordinates_gen(self, mult, i, j):
     n = self.dimension - 1
     coords = [
         # B_center
         ((n, n, n), (n - j * mult, -n + j * mult, n - j * mult), (n - i * mult, -n + i * mult, n - i * mult)),
         # G_center
         ((-n, -n, -n), (n - j * mult, -n + j * mult, n - j * mult), (n - i * mult, -n + i * mult, n - i * mult)),
         # W_center
         ((n - j * mult, -n + j * mult, n - j * mult), (n, n, n), (n - i * mult, -n + i * mult, n - i * mult)),
         # Y_center
         ((n - j * mult, -n + j * mult, n - j * mult), (-n, -n, -n), (n - i * mult, -n + i * mult, n - i * mult)),
         # R_center
         ((n - j * mult, -n + j * mult, n - j * mult), (n - i * mult, -n + i * mult, n - i * mult), (n, n, n)),
         # O_center
         ((n - j * mult, -n + j * mult, n - j * mult), (n - i * mult, -n + i * mult, n - i * mult), (-n, -n, -n))
     ]
     return [tuple(set(pd(*coords[k]))) for k in range(len(self.__centers))]
Ejemplo n.º 7
0
def solution(board):
    answer = 0

    rock = len(board)
    n = [i for i in range(rock)]
    s = list(cb(list(pd(n, repeat=2)), rock))

    test = []
    for c in s:
        x = list(set([i[0] for i in c]))
        y = list(set([j[1] for j in c]))
        if len(x) == rock and len(y) == rock:
            test.append(c)

    for t in test:
        temp = 0
        for x, y in t:
            temp += board[x][y]
        answer = max(answer, temp)
    return answer

def backtrack(depth):
    if depth == M:
        print(*arr)
        return
    for i in range(N):
        arr.append(numbers[i])
        backtrack(depth + 1)
        arr.pop()


backtrack(0)

# 방법 2 (짧은 시간 - 500ms)
from itertools import product

n, m = list(map(int, input().split()))

li = list(map(str, range(1, n + 1)))
per = product(li, repeat=m)

print('\n'.join(list(map(' '.join, sorted(per)))))

#방법 3 (더 짧은 시간 - 244ms)
from itertools import product as pd

N, M = map(int, input().split())
a = map(str, range(1, N + 1))
print('\n'.join(list(map(' '.join, pd(a, repeat=M)))))
Ejemplo n.º 9
0
        push(board)
        add(board)
        board = rotate(board)
    elif S == 3:
        board = rotate(board)
        board = rotate(board)
        push(board)
        add(board)
        board = rotate(board)
        board = rotate(board)
    else:
        push(board)
        add(board)
    return board​


# 1,u 2,d,3,l
N = int(input())
board = []
tmp = []
S = 1
for i in range(N):
    board.append(list(map(int, input().split())))
original = deepcopy(board)
for i in list(pd([1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4])):
    new_board = original
    for j in range(5):
        new_board = solve(i[j],new_board)
    tmp.append(mymax(new_board))

print(max(tmp))
Output a single integer denoting the value Smax.

Sample Input:
3 1000
2 5 4
3 7 8 9
5 5 7 8 9 10

Sample Output:
206

Explanation:
Picking 5 from the 1st list,9  from the 2nd list and 10 from the 3rd list gives the maximum s value equal to
(5² + 9² + 10²) % 1000 = 206
"""

from itertools import product as pd

k, m = [int(x) for x in input().split()]
arr = []
for _ in range(k):
    arr.append([int(x) for x in input().split()][1:])
comb = list(pd(*arr))


def summ(nums):
    return sum(x * x for x in nums) % m


print(max(list(map(summ, comb))))
Ejemplo n.º 11
0
# N 과 M

"""
2021-05-11 오후 4:32
안영준

문제 : https://www.acmicpc.net/problem/15651
"""
import sys

from itertools import product as pd

input = lambda: sys.stdin.readline().rstrip()

N, M = map(int, input().split())

number = [i for i in range(1, N + 1)]

for num in pd(number, repeat=M):
    for i in num:
        print(i, end=' ')
    print()
Ejemplo n.º 12
0
        for di,dj in d:
            nx = i+di
            ny = j+dj

            if not (0<=nx<N and 0<=ny<N):
                continue
            if visited[nx][ny] == False and [nx,ny] not in q and new_area[nx][ny] == num:
                q.append([nx,ny])
    return total



N = int(input())
area = [list(map(int,input().split())) for i in range(N)]

all_list = list(pd(range(1,N), repeat=4))

#조건에 맞는 경우의 수
test = []
for x,y,d1,d2 in all_list:
    if 1<=x+d1<=N and 1<=y-d1<=N and 1<=(x+d1+d2)<=N and 1<=(y+d2-d1)<=N and 1<=x+d2<=N and 1<=y+d2<=N:
        if 1<=x<=N-1 and 2<=y<=N:
            test.append([x-1,y-1,d1,d2])

#가장 많은 인구수 - 가장 적은 인구수 : 결과 저장 리스트
gap_pop = []

#구획 나누기
for x,y,d1,d2 in test:
    new_area = [[0]*N for _ in range(N)]
Ejemplo n.º 13
0
 def __init__(self, mat_cls, mesh_cls, prob_dict):
     # name of the Equation
     self._name = 'saaf'
     # mesh data
     self._mesh = mesh_cls
     self._cell_length = mesh_cls.cell_length()
     # quantities of interest
     self._keff = 1.0
     self._keff_prev = 1.0
     # preassembly-interpolation data
     self._elem = Elem(self._cell_length)
     # material data
     self._n_grp = mat_cls.get('n_grps')
     self._g_thr = mat_cls.get('g_thermal')
     self._sigts = mat_cls.get('sig_t')
     self._isigts = mat_cls.get('inv_sig_t')
     self._fiss_xsecs = mat_cls.get_per_str('chi_nu_sig_f')
     self._nu_sigfs = mat_cls.get('nu_sig_f')
     self._sigses = mat_cls.get_per_str('sig_s')
     self._dcoefs = mat_cls.get('diff_coef')
     self._mids = mat_cls.ids()
     # derived material data
     self._ksi_ua = mat_cls.get('ksi_ua')
     # problem type: is problem eigenvalue problem
     # aq data in forms of dictionary
     self._aq = AQ(prob_dict['sn_order']).get_aq_data()
     self._n_dir = self._aq['n_dir']
     # total number of components in HO
     self._n_tot = self._n_grp * self._n_dir
     # get a component indexing mapping
     self._comp = dict()
     # component to group map
     self._comp_grp = dict()
     # component to direction map
     self._comp_dir = dict()
     self._generate_component_map()
     # local vectors
     self._rhs_mats = dict()
     self._preassembly_rhs()
     # related to global matrices and vectors
     self._n_dof = mesh_cls.n_node()
     self._sys_mats = {}
     # be very careful about the following
     self._sys_rhses = {
         k: np.ones(self._n_dof)
         for k in xrange(self._n_tot)
     }
     self._fixed_rhses = {
         k: np.zeros(self._n_dof)
         for k in xrange(self._n_tot)
     }
     self._aflxes = {k: np.ones(self._n_dof) for k in xrange(self._n_tot)}
     # scalar flux for current calculation
     self._sflxes = {k: np.ones(self._n_dof) for k in xrange(self._n_grp)}
     # linear solver objects
     self._lu = {}
     # source iteration tol
     self._tol = 1.0e-7
     # fission source
     self._global_fiss_src = self._calculate_fiss_src()
     self._global_fiss_src_prev = self._global_fiss_src
     # assistance:
     self._local_dof_pairs = pd(xrange(4), xrange(4))
Ejemplo n.º 14
0
def _corners_coordinates_gen(self):
    n = self.dimension - 1
    coords = (-n, n), (-n, n), (-n, n)
    return [tuple(pd(*coords))[i] for i in range(len(self.__corners))]
Ejemplo n.º 15
0
    elif S == 3:
        board = rotate(board)
        board = rotate(board)
        push(board)
        add(board)
        board = rotate(board)
        board = rotate(board)
    else:
        push(board)
        add(board)
    return board


# 1,u 2,d,3,l
N = int(input())
board = []
tmp = []
for i in range(N):
    board.append(list(map(int, input().split())))
# pprint(new_board,width=100)
for i in list(
        pd([1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4],
           [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4],
           [1, 2, 3, 4], [1, 2, 3, 4])):
    new_board = deepcopy(board)
    for j in range(10):
        new_board = solve(i[j], new_board)
    tmp.append(mymax(new_board))

print(max(tmp))
Ejemplo n.º 16
0
from itertools import product as pd

n = int(input())
x, y = zip(*(tuple(map(int, input().split())) for _ in range(n)))
u, v = zip(*((i + j, i - j) for i, j in zip(x, y)))
d = max(max(u) - min(u), max(v) - min(v))

for i, j in pd((max(u) - d // 2, min(u) + d // 2),
               (max(v) - d // 2, min(v) + d // 2)):
    k, l = (i + j) // 2, (i - j) // 2
    s = set()
    for px, py in zip(x, y):
        s.add(abs(k - px) + abs(l - py))
        if len(s) > 1: break
    else:
        print(k, l)
        break
Ejemplo n.º 17
0
    #구역 5를 따로 계산하면 중복계산 할 수 있기 때문에
    #(전체 - 나머지) 로 구하기
    people[4] = total - sum(people)

    return max(people) - min(people)


N = int(input())
area = [list(map(int, input().split())) for _ in range(N)]

total = 0
for i in area:
    total += sum(i)

#중복가능한 순열사용 > 케이스 만들기
all_case = list(pd(range(1, N + 1), repeat=4))
case = []
for x, y, d1, d2 in all_case:
    #if 1<= x+d1+d2 <= N and 1<= y-d1+d2 <=N : #범위 오류가 생김
    # 각 따로 해주는 것이 좋음
    if x + d1 + d2 > N:
        continue
    if y - d1 < 1:
        continue
    if y + d2 > N:
        continue

    case.append([x, y, d1, d2])

answer = math.inf
for x, y, d1, d2 in case:
Ejemplo n.º 18
0
# Please write a program to generate all sentences where subject is in ["I", "You"] and verb is in ["Play", "Love"] and the object is in ["Hockey","Football"].
#
from itertools import product as pd
subject = ["I", "You"]
verbs = ["Play", "Love"]
object = ["Hockey", "Football"]
sol = pd(subject, verbs, object)
for i in sol:
    print(i[0] + ' ' + i[1] + ' ' + i[2])
Ejemplo n.º 19
0
def campaign(ctx, outdir):
    '''
    Generate into outdir files to run a campaign.
    '''
    multis = (1, 2, 3, 10)
    dtypes = ("float16", "float32", "float64")

    # Do more counts of the smaller array shapes to approximately use
    # similar time for each shape.
    shapes = ("100,100", "1000,1000", "10000,1000")
    counts = (10000, 1000, 100)

    tests = ("copy", "rand", "fft")

    outdir = os.path.realpath(outdir)
    if not os.path.exists(outdir):
        os.makedirs(outdir)

    sm_fname = f'{outdir}/shoreman.sh'
    smurl = 'https://raw.githubusercontent.com/brettviren/shoreman/master/shoreman.sh'
    if not os.path.exists(sm_fname):
        from urllib.request import urlretrieve
        urlretrieve(smurl, sm_fname)
        os.chmod(sm_fname, 0o755)

    module = ctx.obj.name

    main_log = f'{module}-campaign.log'
    main_fname = f'{outdir}/{module}-campaign.sh'
    main = open(main_fname, 'w')
    main.write(f"""#!/bin/sh
set -e
echo "logging to {main_log}"
date > {main_log}
hostname >> {main_log}
lscpu >> {main_log}
nvidia-smi --query >> {main_log}

set +x
    """)

    test_cli = "ffs -m {module} {test} --shape {shape} --count {count} --dtype {dtype}"

    from itertools import product as pd
    outer = pd(multis, dtypes, zip(shapes, counts), tests)
    for multi, dtype, (shape, count), test in outer:
        shape_name = shape.replace(",", "x")

        name = f'{module}-{test}-{shape_name}-{dtype}'
        pf = f'{name}.procfile'
        gf = f'{name}-gpu.log'
        cf = f'{name}-cpu.log'
        jf = f'{name}-job.log'
        main.write(f'./shoreman.sh {pf} "" {cf} {gf}  >> {main_log} 2>&1\n')
        with open(f'{outdir}/{pf}', 'w') as procfile:
            cli = test_cli.format(**locals())
            for num in range(multi):
                procfile.write(f'{name}-{num}: {cli}\n')
    main.close()
    os.chmod(main_fname, 0o755)
    print(f'cd {outdir} && ./{module}-campaign.sh')