Skip to content

Instantly share code, notes, and snippets.

@inage
Created December 7, 2013 14:44
Show Gist options
  • Select an option

  • Save inage/7843193 to your computer and use it in GitHub Desktop.

Select an option

Save inage/7843193 to your computer and use it in GitHub Desktop.
Saruman's Army (POJ 3069)
## Saruman's Army (POJ 3069)
## http://rubyfiddle.com/riddles/b5dfa
R=10
x = [1, 7, 15, 20, 30, 50]
N = x.size
ans = []
i = j = 0
while x[1] != nil
if j > x.size-1
ans << x.slice!(0..j-1)
elsif x[j]-x[i] <= R && x[i]-x[0] <= R
i = j
j += 1
else
ans << x.slice!(0..i)
i = j = 0
end
end
if x[0] != nil
ans << x.pop
end
puts ans.size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment