Skip to content
Snippets Groups Projects
Commit 7aa7d1dd authored by François Sarradin's avatar François Sarradin Committed by François Sarradin
Browse files

add geometry questions + regex correction + review point distribution

parent 28f15d77
No related branches found
No related tags found
No related merge requests found
# encoding: utf-8
require 'set'
require 'prime'
......@@ -154,6 +156,90 @@ module ExtremeStartup
end
end
class RectangleIntersectionQuestion < GetQuestion
def initialize(player, *numbers)
if numbers.any?
@x1, @y1, @w1, @h1, @x2, @y2, @w2, @h2 = *numbers
else
@x1, @y1, @w1, @h1 = rand(100), rand(100), rand(100), rand(100)
@x2, @y2, @w2, @h2 = rand(100), rand(100), rand(100), rand(100)
end
end
def as_text
"give the intersection of those rectangles (x0,y0,width,height): (#{@x1},#{@y1},#{@w1},#{@h1}) x (#{@x2},#{@y2},#{@w2},#{@h2})"
end
def answered_correctly?(answer)
correct_answer.to_s.downcase.gsub(/[ \\t\\r\\n]+/, '') == answer.gsub(/[ \\t\\r\\n]+/, '')
end
def points
50
end
private
def correct_answer
_x1 = @x1 + @w1
_y1 = @y1 + @h1
_x2 = @x2 + @w2
_y2 = @y2 + @w2
x = [@x1, @x2].max
y = [@y1, @y2].max
_x = [_x1, _x2].min
_y = [_y1, _y2].min
w = _x - x
h = _y - y
if (w >= 0) and (h >= 0)
"(#{x},#{y},#{w},#{h})"
else
""
end
end
end
class RectangleUnionQuestion < GetQuestion
def initialize(player, *numbers)
if numbers.any?
@x1, @y1, @w1, @h1, @x2, @y2, @w2, @h2 = *numbers
else
@x1, @y1, @w1, @h1 = rand(100), rand(100), rand(100), rand(100)
@x2, @y2, @w2, @h2 = rand(100), rand(100), rand(100), rand(100)
end
end
def as_text
"give the union of those rectangles (x0,y0,width,height): (#{@x1},#{@y1},#{@w1},#{@h1}) + (#{@x2},#{@y2},#{@w2},#{@h2})"
end
def answered_correctly?(answer)
correct_answer.to_s.downcase.gsub(/[ \\t\\r\\n]+/, '') == answer.gsub(/[ \\t\\r\\n]+/, '')
end
def points
50
end
private
def correct_answer
_x1 = @x1 + @w1
_y1 = @y1 + @h1
_x2 = @x2 + @w2
_y2 = @y2 + @w2
x = [@x1, @x2].min
y = [@y1, @y2].min
_x = [_x1, _x2].max
_y = [_y1, _y2].max
w = _x - x
h = _y - y
"(#{x},#{y},#{w},#{h})"
end
end
class ListQuestion < GetQuestion
def random_numbers
randoms = Set.new
......@@ -171,12 +257,8 @@ module ExtremeStartup
random_numbers[0..size].concat(candidate_numbers.shuffle[0..size]).shuffle
end
def answer
@answer && @answer.downcase.strip.gsub(/[ \\t\\r\\n]*,[ \\t\\r\\n]*/, ',')
end
def answered_correctly?(answer)
correct_answer.to_s.downcase.gsub(/[ \\t\\r\\n]*,[ \\t\\r\\n]*/, ',') == answer
correct_answer.to_s.downcase.gsub(/[ \\t\\r\\n]+/, '') == answer.gsub(/[ \\t\\r\\n]+/, '')
end
end
......@@ -212,6 +294,10 @@ module ExtremeStartup
def as_text
"give the sum of elements in: " + @numbers.join(', ')
end
def points
20
end
private
def correct_answer
@numbers.reduce(:+)
......@@ -226,13 +312,17 @@ module ExtremeStartup
else
@n = rand(1000)
size = rand(5)
@numbers = generate_numbers[0..size].concat(candidate_numbers.shuffle[0..size]).shuffle
@numbers = generate_numbers(size).concat(candidate_numbers.shuffle[0..size]).shuffle
end
end
def as_text
"multiply by #{@n} those elements: " + @numbers.join(', ')
end
def points
20
end
private
def correct_answer
@numbers.map { |e| e * @n }.join(',')
......@@ -255,6 +345,10 @@ module ExtremeStartup
end
"what #{count} of the Fibonacci sequence"
end
def points
60
end
private
def fibonacci(n)
a, b = 0, 1
......@@ -453,11 +547,11 @@ module ExtremeStartup
class << self
def question_bank
[
["who is the Prime Minister of Great Britain", "Theresa May"],
["which city is the Eiffel tower in", "Paris"],
["who is the president of France", "François Hollande"],
["which city is the Oriental Pearl Tower in", "Shanghai"],
["what currency did Spain use before the Euro", "peseta"],
["what colour is a banana", "yellow"],
["who played James Bond in the film Dr No", "Sean Connery"]
["where does the killer rabbit comes from", "Caerbannog"]
]
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment