Skip to content

Instantly share code, notes, and snippets.

@spencerdcarlson
Created May 12, 2012 06:15
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 spencerdcarlson/2664550 to your computer and use it in GitHub Desktop.
Save spencerdcarlson/2664550 to your computer and use it in GitHub Desktop.
First order Recurrence Relations
# PROJECT: First Order Recurrence Relations
$LOAD_PATH << '../lib'
require 'parseFile.rb'
class Forr
def initialize(inputs)
$s1 = ( inputs.has_key?('S(1)') && inputs['S(1)'] )
$c = ( inputs.has_key?('C') && inputs['C'] )
$gn = ( inputs.has_key?('G(N)') && inputs['G(N)'] )
#puts s1,c,gn
print
end
def print
puts "S(n) = #{$c}^(n-1) * #{$s1} + sigma(#{$c}^(n-1) * #{$gn})"
unless $gn == 0
for n in 1..10 do
i = n
sigma = 0
for i in 2..i do
sigma += ( $c**(n-i) ) *$gn
end
puts "S(#{n}) = #{( ( $c**(n-1) ) * $s1 ) + sigma}"
end
else
for n in 1..10
puts "S(#{n}) = #{( ( $c**(n-1) ) * $s1 ) + $gn}"
end
end
end
end #Class
begin
parsed = Master::ParseFile.new(Hash)
if parsed.getFile.instance_of?(Hash) then Forr.new(parsed.getFile) end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment