Quantcast
Channel: Golfing: How many unit-length squares in a list of 2d coordinates? - Code Golf Stack Exchange
Viewing all articles
Browse latest Browse all 6

Answer by Daniel Lubarov for Golfing: How many unit-length squares in a list of 2d coordinates?

$
0
0

Python, 61 chars

f=lambda l:sum(1for x,y in l if{(x+1,y),(x,y+1),(x+1,y+1)}<l)

Sample:

>>> f({(0,0), (0,1), (1,1), (1,0), (0,2), (1,2)})2>>> f({(0,0), (0,1), (1,1), (1,0), (0,2), (1,2), (2,2), (2,1)})3>>> f({(0,0), (0,1), (1,1), (1,0), (0,2), (1,2), (2,2), (2,1), (2,0)})4>>> f({(0,0), (0,1), (1,1), (1,0), (0,2), (1,2), (2,2), (2,1), (2,0), (9,9)})4

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>