Skip to content

Instantly share code, notes, and snippets.

@samklr samklr/extreme_st.rb
Created Sep 27, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.