9-5 biten Futbol maçı

inits = lambda xs: [] if len(xs) == 0 else [[xs[0]]] + list(map(lambda xt: [xs[0]] + xt, inits(xs[1:])))

print((lambda perms: len(list(filter(lambda x:x, map(lambda sums: any(map(lambda sum_: sum_ < 0, sums)), map(lambda inits_: list(map(sum, inits_)), map(inits, perms)))))) / len(perms)) (list(permutations_with_duplicates([(+1, 9), (-1, 5)]))))

0.5 (1001/2002)

Sunu su sekilde yazarken aklimda (map.map) sum veya filter (any (<0)) diyebildigin Haskell vardi… Python’da boyle oluyor.

Mantik da su:

permutations_with_duplicates([(+1, 9), (-1, 5)]) → 9 gol atilip 5 gol yiyilen butun maclar (2002 tane)

map inits permutasyonlar → maclarin her golden sonraki gol durumu (2002×14 tane)

map sum durumlar = map sum.inits permutasyonlar → durumlardaki gol farki (2002×14 tane)

filter (any (<0)) farklar → gol farkinin herhangi bir durumda negatif oldugu maclar (1001×14 tane)

1 Beğeni