Last active
December 16, 2015 07:08
-
-
Save michaelfeathers/5395996 to your computer and use it in GitHub Desktop.
Attempt to discern number of spaces used for an indent across a set of source files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def freq_by &block | |
group_by(&block).map {|k,v| [k, v.count] }.sort_by(&:first) | |
end | |
def freq | |
freq_by {|e| e } | |
end | |
end | |
puts ARGF.lines.map {|l| l.split(/\S/).first } | |
.compact | |
.select {|s| s.length > 1 } | |
.select {|s| s.chars.all? {|c| c == ' ' }} | |
.freq | |
.sort_by {|_,c| -c } | |
.take(10) | |
.map {|p,_| p.length } | |
.sort | |
.each_cons(2) | |
.take_while {|l,r| l.gcd(r) > 1 } | |
.map(&:first) | |
.reduce(&:gcd) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment