↧
Answer by alephalpha for Golfing: How many unit-length squares in a list of...
Mathematica, 56 charactersf=Count[#-#[[1]]&/@Subsets[{}⋃#.{1,I},{4}],{0,I,1,1+I}]&
View ArticleAnswer by Daniel Lubarov for Golfing: How many unit-length squares in a list...
Python, 61 charsf=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),...
View ArticleAnswer by TwiNight for Golfing: How many unit-length squares in a list of 2d...
APL(Dyalog), 30+/{(2-/⍵)≡2-/,⍳2 2}¨,∘.,⍨⍣2⊂¨⎕Well, in most cases, readability and char count is proportional.Sample Output⎕: (0 0)(0 1)(1 0)(1 1)(0 2)(1 2)(2 2)(2 1)(2 0)4ExplainationSo, 4 points forms...
View ArticleAnswer by DavidC for Golfing: How many unit-length squares in a list of 2d...
Mathematica 65 charsf@d_ := Length@Select[Subsets[d, {4}], Sort[g@#] == {1, 1, 1, 1, √2, √2} &]Testsf[{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 2}, {1, 2}}]2f[{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 2},...
View ArticleAnswer by Doorknob for Golfing: How many unit-length squares in a list of 2d...
Ruby, 164161153 147 charactersf=->a{a.combination(4).map(&:sort).uniq.count{|x|[x[1][0]==l=x[0][0],x[3][0]==m=x[2][0],x[2][1]==n=x[0][1],x[3][1]==o=x[1][1],m-l==1,o-n==1].all?}}It's actually...
View ArticleGolfing: How many unit-length squares in a list of 2d coordinates?
Given a list of 2d (x, y) coordinates, determine how many unit squares (edge length 1 unit) can be formed using the coordinates.Input will be an array of 0 or more pairs of coordinates: e.g. in...
View Article
More Pages to Explore .....