Ad
  • Custom User Avatar

    It's actually a problem with the design of the tests, already pointed out by ejini just below. See also my answer to Jam14man above. I close this issue because it is a duplicate one.

  • Custom User Avatar

    I believe you are missing one case:

    if 24 == x[0](a, (y[0](b, z[0]c), d)):
        return '{}{}(({}{}{}){}{})'.format(a,x[1],b,y[1],c,z[1],d)
    
  • Custom User Avatar

    This solution is missing the 5th traversal as brendanvos already pointed out. Otherwise, if you would scale up this task to numbers bigger than 13, e.g. equal_to_24(55, 26, 30, 5) would say impossible, however 26-((55+5)/30) = 24.

    For anyone wondering, you would need to add

    elif round(z(c, x(y(d, b), a)), 5) == 24:
        return f"{c} {op[z]} (({d} {op[y]} {b}) {op[x]} {a})"
    

    to the solve24 function.

  • Custom User Avatar

    It is necessary, for example equal_to_24(55, 26, 30, 5) would give with his solution a "It's not possible!", however 26-((55+5)/30) = 24.

  • Custom User Avatar

    equal_to_24(1, 4, 6, 5) gives "It's not possible!", however 4 / (1 - (5 / 6)) = 24. I think the authors solution or rather python has some problems with rounding.

  • Custom User Avatar

    This solution is technically false, here's why:

    equal_to_24(1, 4, 6, 5) gives "It's not possible!", however 4 / (1 - (5 / 6)) = 24. The author of this kata also gives back "It's not possible!" for the test with these numbers, that's why your solution still got accepted, but his solution or rather python apparently has some problems with rounding.

    Edit: I found the problem, your make_string function misses 2 f-strings:
    f"({a} {b} ({c} {d} {e})) {f} {g}" and
    f"{a} {b} ({c} {d} ({e} {f} {g}))"
    By adding these two, your algorithm gives back the technically correct solution 4 / (1 - (5 / 6)).