-
-
Save lenary/f07721b1d116a3129c9c to your computer and use it in GitHub Desktop.
This file contains 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
require "rubygems" | |
require "bundler" | |
Bundler.setup(:default) | |
require "sinatra" | |
get "/" do | |
@fib = Hash.new do |h, k| | |
h[k-1] + h[k-2] | |
end | |
@fib[1] = 1 | |
@fib[2] = 1 | |
case params[:q] | |
when /who is the Prime Minister of Great Britain$/ | |
"David Cameron" | |
when /what is the twitter id of the organizer of this dojo$/ | |
"jhannes" | |
when /who played James Bond in the film Dr No$/ | |
"Sean Connery" | |
when /what colour is a banana$/ | |
"yellow" | |
when /which city is the Eiffel tower in$/ | |
"Paris" | |
when /what currency did Spain use before the Euro$/ | |
"Peseta" | |
when /which of the following numbers is the largest: (\d+), (\d+), (\d+), (\d+)$/ | |
[$1.to_i, $2.to_i, $3.to_i, $4.to_i].max.to_s | |
when /which of the following numbers is the largest: (\d+), (\d+)$/ | |
[$1.to_i, $2.to_i].max.to_s | |
when /what is (\d+) plus (\d+) multiplied by (\d+)$/ | |
"#{$1.to_i + $2.to_i * $3.to_i}" | |
when /what is (\d+) plus (\d+) plus (\d+)$/ | |
"#{$1.to_i + $2.to_i + $3.to_i}" | |
when /what is (\d+) plus (\d+)$/ | |
"#{$1.to_i + $2.to_i}" | |
when /what is (\d+) multiplied by (\d+) plus (\d+)$/ | |
"#{$1.to_i * $2.to_i + $3.to_i}" | |
when /what is (\d+) multiplied by (\d+)$/ | |
"#{$1.to_i * $2.to_i}" | |
when /what is (\d+) minus (\d+)$/ | |
"#{$1.to_i - $2.to_i}" | |
when /what is (\d+) to the power of (\d+)$/ | |
$1.to_i ** $2.to_i | |
when /which of the following numbers are primes: (\d+), (\d+), (\d+), (\d+)$/ | |
puts "p" | |
nums = [$1.to_i, $2.to_i, $3.to_i, $4.to_i] | |
nums.select {|n| n.odd? }.join(", ") | |
when /which of the following numbers are primes: (\d+), (\d+)$/ | |
puts "p§" | |
nums = [$1.to_i, $2.to_i] | |
nums.select {|n| n.odd? }.join(", ") | |
when /which of the following numbers is both a square and a cube: (\d+), (\d+), (\d+), (\d+)$/ | |
nums = [$1.to_f, $2.to_f, $3.to_f, $4.to_f] | |
nums.find do |n| | |
(n**(1.0/3)).integer? && (n**(1.0/2)).integer? | |
end.to_s | |
when /which of the following numbers is both a square and a cube: (\d+), (\d+)$/ | |
nums = [$1.to_f, $2.to_f] | |
nums.find do |n| | |
(n**(1.0/3)).integer? && (n**(1.0/2)).integer? | |
end.to_s | |
when /what is the (\d+)\w\w number in the Fibonacci sequence$/ | |
"#{@fib[$1.to_i]}" | |
else | |
puts "******************NOT HANDLED******************" | |
puts params.inspect | |
puts "******************NOT HANDLED******************" | |
"" | |
end | |
end |
This file contains 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
source :rubygems | |
gem "sinatra" | |
gem "shotgun" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment