-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmadminute.rb
47 lines (43 loc) · 1.16 KB
/
madminute.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def row(nums)
problems = []
multiplicands, multipliers, products = [], [], []
15.times do
twodigit = "#{nums.sample}#{nums.sample}".to_i
onedigit = nums.sample
multiplicands << twodigit
multipliers << onedigit
products << twodigit*onedigit
end
problems << multiplicands.map{|m| m.to_s.rjust(4)}.join(' ')
problems << multipliers.map{|m| "×#{m}".rjust(4)}.join(' ')
problems << products.map{|p| "----"}.join(' ')
problems_with_answers = problems.dup
problems_with_answers << products.map{|p| p.to_s.rjust(4)}.join(' ')
problems << products.map{|p| ' '}.join(' ')
return [problems.join("\n"), problems_with_answers.join("\n")]
end
text = []
nums = [1,2,3]
text << row(nums)
nums << 4
text << row(nums)
nums << 5
text << row(nums)
nums << 6
text << row(nums)
nums << 7
text << row(nums)
nums << 8
text << row(nums)
nums << 9
text << row(nums)
file = File.open("madminute.txt","w")
file.write("Mad Minute\n\n")
file.write(text.map{|r| r[0]}.join("\n\n"))
file.write("\n")
file.close
file = File.open("madminuteanswers.txt","w")
file.write("Mad Minute answer key\n\n")
file.write(text.map{|r| r[1]}.join("\n\n"))
file.write("\n")
file.close