Skip to content

Instantly share code, notes, and snippets.

@KeyLD
Last active May 19, 2017 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KeyLD/331c81bac99122d2f3e4e236efee576c to your computer and use it in GitHub Desktop.
Save KeyLD/331c81bac99122d2f3e4e236efee576c to your computer and use it in GitHub Desktop.
v2ex
#!/usr/bin/env ruby
# encoding: utf-8
# https://www.v2ex.com/t/342485
dp = [1,1,0]
p = [1,0,0]
key = gets.to_i
(key-1).times do | i |
p[0],p[1],p[2] = p[0]+p[1]+p[2]+dp[0]+dp[1]+dp[2],p[0],p[1]
dp[0],dp[1],dp[2] = dp[0]+dp[1]+dp[2],dp[0],dp[1]
end
puts dp[0]+dp[1]+dp[2] + p[0]+p[1]+p[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment