Created
August 14, 2012 21:11
-
-
Save torbjon/3353078 to your computer and use it in GitHub Desktop.
extream startup
This file contains hidden or 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
| def index | |
| q = params[:q] | |
| if q == "what is the sum of 8 and 22" | |
| rezult = "30" | |
| elsif q.include? "what is your name" | |
| rezult = "torbjon" | |
| elsif q.include? "I was here before. what is my name" | |
| rezult = Stuff.first.name | |
| elsif q.include? "want to shop. What products do you have for sale (comma separated)" | |
| rezult = "banana, apple" | |
| elsif q.include? "how many dollars does one apple cost" | |
| rezult = "10" | |
| elsif q.include? "how many dollars does one banana cost" | |
| rezult = "10" | |
| elsif q.include? "what is my name" | |
| rezult = q.split("my name is ")[1].split(".")[0] | |
| Stuff.first.update_attributes(name: rezult) | |
| elsif q.include? "plus" | |
| rez = q.split("what is ")[1] | |
| rezult = rez.split(" plus ")[0].to_i + rez.split(" plus ")[1].to_i | |
| elsif q.include? "minus" | |
| rez = q.split("what is ")[1] | |
| rezult = rez.split(" minus ")[0].to_i + rez.split(" minus ")[1].to_i | |
| elsif q.include? "divided by" | |
| rez = q.split("what is ")[1] | |
| rezult = rez.split(" divided by ")[0].to_i / rez.split(" divided by ")[1].to_i | |
| elsif q.include? "multiplied by" | |
| rez = q.split("what is ")[1] | |
| rezult = rez.split(" multiplied by ")[0].to_i * rez.split(" multiplied by ")[1].to_i | |
| elsif q.include? "what colour is banana" | |
| rezult = "yellow" | |
| elsif q.include? "which city is the Eiffel tower in" | |
| rezult = "Paris" | |
| elsif q.include? "are primes:" | |
| arr = q.split(" are primes: ")[1].split(",") | |
| b = [] | |
| c = [] | |
| arr.each {|a| b << a.to_i} | |
| b.each {|b1| c << b1 if isPrime(b1.to_i) } | |
| rezult = c.join(", ") | |
| elsif q.include? "largest" | |
| arr = q.split(" largest: ")[1].split(",") | |
| b = [] | |
| arr.each {|a| b << a.to_i} | |
| rezult = b.max | |
| elsif q.include? "who played James Bond in the film Dr No" | |
| rezult = "Sean Connery" | |
| elsif q.include? "what currency did Spain use before the Euro" | |
| rezult = "peseta" | |
| elsif q.include? "who wrote 'Specification by Example' book" | |
| rezult = "Gojko Adzic" | |
| elsif q.include? "what is the twitter id of the organizer of this dojo" | |
| rezult = "aleksejstruhans" | |
| else | |
| rezult = "error" | |
| end | |
| render :text => rezult | |
| end | |
| def isPrime number | |
| return false if number == 0 or number == 1 | |
| i = 2 | |
| limit = number / i | |
| while i < limit | |
| return false if number % i == 0 | |
| i += 1 | |
| limit = number / i | |
| end | |
| return true | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment