Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
One liner (awful) solution in Creative category for Counting Tiles by CDG.Axel
from itertools import product
from functools import reduce
# if you want 'true' one-liner you may use 'checkio = lambda radius: ...' and __immport__()
def checkio(radius):
return reduce(
lambda res, e: [
res[0] + 4 * all(t := [abs(e[0] + x + (e[1] + y) * 1j) < radius for x, y in ((0, 0), (1, 1))]),
res[1] + 4 * (sum(t) == 1)], product(range(4), repeat=2), [0, 0])
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(2) == [4, 12], "N=2"
assert checkio(3) == [16, 20], "N=3"
assert checkio(2.1) == [4, 20], "N=2.1"
assert checkio(2.5) == [12, 20], "N=2.5"
Nov. 14, 2021
Comments: