-3

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?

E_net4
  • 27,810
  • 13
  • 101
  • 139

3 Answers3

2

NOT HELPFUL

Just a guess: wrong types of the return values of the functions? str vs. int?

Improved Answer

First a more detailed explanation for the 'type of values' thing:

In python, values are typed also if you do not have to declare a type. E.g.:

>>> i = 7
>>> s = '7'
>>> print(i, s, type(i), type(s), i == s)
7 7 <class 'int'> <class 'str'> False

I do not know the exact tests that are applied to the code, but typically those involve some equality test with ==. If the type of the expected value and those value returned does not match, the equality fails. Perhaps Elegant ways to support equivalence ("equality") in Python classes might help.

The instruction to the challenge (see pastebin) also explicitly mentions the expected return types: the returned values must be string (see line 41 / 47).

In addtion, the instruction also states that one should 'write a function answer(w, h, s)' (line 6). The posted solution implements a function solution.

1

I was also stuck on this problem. The error is because of data type mismatch i.e your function returns an integer but the question specifically asked for a string.

Wrapping the return statement in str() will solve the problem.

0

Your return type is an integer. Convert it to a string, and it will work.

return str(grid//(factorial(w)*factorial(h)))
monkrus
  • 1,470
  • 24
  • 23