Skip to content

Instantly share code, notes, and snippets.

@samklr
Created September 27, 2012 10:26
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 samklr/3793341 to your computer and use it in GitHub Desktop.
Save samklr/3793341 to your computer and use it in GitHub Desktop.
Extr Startup
require 'sinatra'
require 'logger'
log = Logger.new(STDOUT)
log.level = Logger::DEBUG
get '/' do
if params[:q]
log.debug(params[:q])
sz_q = params[:q].split(": ")[1]
if sz_q =~ /anagram/
sz_word = sz_q.split(" ")[-1].gsub('"','')
sum = 0
sz_word.each_byte { |c| sum+=c }
words = params[:q].split(": ")[2].split(", ")
theWord = ""
words.each do |word|
sum_word = 0
word.each_byte { |c| sum_word+=c }
if sum == sum_word
theWord = word
break
end
end
return theWord
elsif sz_q =~ /^what is (\d+) plus (\d+) plus (\d+)$/
return ($1.to_i + $2.to_i + $3.to_i).to_s
elsif sz_q =~ /^what is (\d+) multiplied by (\d+) plus (\d+)$/
return ($1.to_i * $2.to_i + $3.to_i).to_s
elsif sz_q =~ /^what is (\d+) plus (\d+) multiplied by (\d+)$/
return (($1.to_i + $2.to_i) * $3.to_i).to_s
elsif sz_q =~ /^what is (\d+) plus (\d+)$/
return ($1.to_i + $2.to_i).to_s
elsif sz_q =~ /^what is the english scrabble score of (\s+)$/
return $1
end
end
"lwy08"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment