-
-
Save latentflip/987222 to your computer and use it in GitHub Desktop.
L/SH/ScotRug Code Golf
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
g=Golf=Hash | |
def g.method_missing s, a | |
k=[] | |
case s.to_s[-1] | |
when ?1 | |
a.reduce :* | |
when ?2 | |
a.split.sort_by{|i| i[1] }*' ' | |
when ?3 | |
h1 1..a | |
when ?4 | |
a.map { |i| i. | |
sub(/(man.*)/,'hat(\1)'). | |
sub(/(dog.*)\)/,'\1(bone))'). | |
sub 'cat','dead' | |
} | |
when ?5 | |
a.size.times { |i| k += a.each_cons(i+1).to_a } | |
k | |
when ?6 | |
f="fizz" | |
b="buzz" | |
(1..a).map { |s| s%3 > 0 ? s%5 > 0 ? s : b : s%15>0 ? f : f+b } | |
when ?7 | |
*r=0 | |
l,x=a | |
m=l | |
a.map {|a| | |
x ? x=$_ : (m+=1) == a ? r[-1]=[l,a]*'-' : r<<l=m=a | |
} | |
r | |
when ?8 | |
*i=0,1 | |
a.times { i << i[-1]+i[-2] } | |
i[1..-2] | |
when ?9 | |
b = open(a).map {|e| e.chomp.split ', '} | |
g = z b | |
while (c,d = g.minmax_by {|e,s| s.size})[0][1].size*2 < b.size | |
b.select {|e,| e==c[0]}.map &:shift | |
b -= [k] | |
g = z b | |
end | |
d[0] | |
when ?z | |
a.group_by {|e,| e} | |
end | |
end |
614
- Hole7: We can use
$_ #The last input line of string by gets or readline.
instead of nil
since we aren't using gets/readline.
613
- Pull multiple
<variable>=[]
into a singlek=[]
at top of method.
I updated my rake file to this
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.rspec_opts = ["--fail-fast"]
spec.pattern = 'spec/**/*_spec.rb'
end
So will only show first fail, faster to work through the first build. Relies on RSpec 2.1 though.
612
- Hole7: Since we are just setting x to anything, we don't need the *. - with thanks to @jonmountjoy
606
- Fun with parallel assignments
*e=0 #=> e = [0]
*e=0,1 #=> e = [0,1]
e, = [1,2,3] #=> e = 1
602 is about as good as it gets for this route I think
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
615