Foobar - Test cases not passing - Disorderly escape - 2

会有一股神秘感。 提交于 2020-03-28 06:58:34

问题


0/10 test cases are passing.

Here is the challenge description:

(to keep formatting nice - i put the description in a paste bin) Link to challenge description: https://pastebin.com/UQM4Hip9

Here is my trial code - PYTHON - (0/10 test cases passed)

from math import factorial
from collections import Counter
from fractions import gcd

def cycle_count(c, n):
    cc=factorial(n)
    for a, b in Counter(c).items():
        cc//=(a**b)*factorial(b)
    return cc        

def cycle_partitions(n, i=1):
    yield [n]
    for i in range(i, n//2 + 1):
        for p in cycle_partitions(n-i, i):
            yield [i] + p

def solution(w, h, s):    
    grid=0
    for cpw in cycle_partitions(w):
        for cph in cycle_partitions(h):            
            m=cycle_count(cpw, w)*cycle_count(cph, h)
            grid+=m*(s**sum([sum([gcd(i, j) for i in cpw]) for j in cph]))

    return grid//(factorial(w)*factorial(h))

print(solution(2, 2, 2)) #Outputs 7

This code works in my python compiler on my computer but not on the foobar challenge??

Am I losing accuracy or something?

来源:https://stackoverflow.com/questions/60361984/foobar-test-cases-not-passing-disorderly-escape-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!