Skip to content

Commit

Permalink
calculate feasible division questions
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyknown committed Dec 18, 2015
1 parent 107fad3 commit 40de00c
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions app/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ export default Ember.Controller.extend({
}
}),

wholeNumberDivisionTuples: Ember.computed(function() {
const tuples = [];
const max = 100;
var numerator = 1;
while (numerator <= max) {
var denominator = 1;
while (denominator <= max) {
let answer = numerator / denominator;
if (answer % denominator === 0) {
tuples.pushObject([numerator, denominator]);
}
denominator += 1;
}
numerator += 1;
}
return tuples;
}),

actions: {
turnOn() {
this.set('isOn', true);
Expand Down Expand Up @@ -81,9 +99,26 @@ export default Ember.Controller.extend({
this.set('isDisplayingAnswer', false);
var problemCount = 0;
const problems = [];
while (problems.length < 3) {
let termOne = Math.floor(Math.random() * 10);
let termTwo = Math.floor(Math.random() * 10);
const uniqueRandomIndexes = [];
const t = this.get('wholeNumberDivisionTuples');
while (uniqueRandomIndexes.length < 4) {
const index = Math.floor(Math.random() * t.length);
if (!uniqueRandomIndexes.contains(index)) {
uniqueRandomIndexes.pushObject(index);
}
}
while (problems.length < 4) {
let termOne;
let termTwo;
switch (this.get('operator')) {
case '/':
termOne = t[uniqueRandomIndexes[problems.length]][0];
termTwo = t[uniqueRandomIndexes[problems.length]][1];
break;
default:
termOne = Math.floor(Math.random() * 10);
termTwo = Math.floor(Math.random() * 10);
}
let problem = this.store.createRecord('problem', {
termOne: termOne,
termTwo: termTwo,
Expand Down

0 comments on commit 40de00c

Please sign in to comment.