$\textsf{Percentage of votes:}\vphantom{b}$

#4D4D4D

$\text{Check}$

$\text{NEW PROBLEM}$

Fix position and allow selection for all text objects

Empty all input boxes

$\textsf{Number of votes:}\vphantom{b}$

Reset app

\textsf{Remember that you cannot have a partial student. Round down.}

#006758

#B00020

#252525

#757575

#949494

#E44461

#DA2570

#E66B9E

#3A6ED6

#5991FF

#008475

#0F8538

#00a83c

#5145A8

#6557D2

#8575FF

#903D14

#BD6C43

#C75000

#E07415

#eeeeee

#2E006758

#2EB00020

\text{Drag to start}

$\text{SARA}$

$\text{MATT}$

$\text{JOSEPH}$

\textsf{Simplify your answer. }

$\text{Check}$

\text{Simplify your answer.}

allRandoms = RandomUniform(0, 0.99, 200)
showSimplifyMsg = false
currentValueA = NaN
inputSaved: {{}}
currentValueB = NaN
listInput = Flatten({stringA, stringB})
inputCurrent: {listInput}
textAllowed: {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "/", ".", "", " "}
listInput2: Sequence[Element[stringB, n], n, 1, Length[stringB]] \ {" "}
numRandoms: 7
countQuestion = 0
randIndex: (Mod[countQuestion, floor(Length[allRandoms] / numRandoms)] * numRandoms) + 1
currentRandomSeeds = Take(allRandoms, randIndex, randIndex + numRandoms - 1)
randomNum3: 15 + floor((currentRandomSeeds(3) * 85))
randomNum2: 15 + floor((currentRandomSeeds(2) * 85))
randomNum1: 15 + floor((currentRandomSeeds(1) * 85))
input1 = NaN
textInput1: "" + (If[Defined[input1], Text[input1, false] + "", ""]) + ""
input2 = NaN
textInput2: "" + (If[Defined[input2], Text[input2, false] + "", ""]) + ""
randomNumStarts: {randomNum1, randomNum2, randomNum3}
randomTotal: 50 + floor((currentRandomSeeds(5) * 50))
newNums = Zip(floor((randomTotal * n / Sum[randomNumStarts])), n, randomNumStarts)
sortedList = Sort(newNums)
freqNums = Frequency(sortedList)
changeInd = If(2 ∈ freqNums, IndexOf[2, freqNums], 3 ∈ freqNums, 4, 0)
diffs: Flatten[Sequence[Sequence[abs(sortedList(n) - sortedList(k)), n, 1, 3], k, 1, 3]] \ {0}
addChoice = KeepIf(¬(n ∈ diffs), n, Sequence[1, 10])
filtNums = If(changeInd ≟ 0, newNums, changeInd ≟ 4, newNums + {addChoice(1), addChoice(2), 0}, Replace[newNums, newNums(changeInd) + addChoice(1), changeInd])
finalTotal = Sum(filtNums)
randomCandidate: 1 + floor((currentRandomSeeds(7) * 3))
percentage: (100 * filtNums(randomCandidate) / finalTotal)
problemType = If(countQuestion < 3, countQuestion + 1, 1 + floor((currentRandomSeeds(6) * 3)))
textCandidate: "\textsf{" + (LaTeX[Element[{"Sara", "Matt", "Joseph"}, randomCandidate]]) + "}"
hints: {"", "Divide the number of votes " + textCandidate + " got by the total number of votes. Then, multiply by 100.", "Find the percentage of votes that " + textCandidate + " received and multiply by the total number of students\\in the school."}
maxVotes = Max(newNums)
voteChoice = IndexOf(maxVotes, newNums)
studentChoice = 0
randomPop: 300 + floor((currentRandomSeeds(4) * 100))
numVotes: floor((randomPop * filtNums(randomCandidate) / finalTotal))
validInput: listInput2 ⊆ textAllowed
correct3: input1 ≟ numVotes ∧ validInput
correct1: input1 ≟ voteChoice
correct2: abs(input1 - percentage) ≤ 0.5
InputBox1 = Textfield(input1)
textQuestions: {"who will win the\\election?", "what percentage of\\students plan to vote for " + textCandidate + "?", "how many students\\plan to vote for " + textCandidate + "?"}
onboarding: false
validate = false
showanswer = false
showsolution = false
tries = 0
countCorrect = 0
showhint = false
InputBox2 = Textfield(input2)
correct = Element({correct1, correct2, correct3}, problemType)
showbuttons = true
showhinttypicalerror = false
textCountCorrect: "\text{Number correct: " + (LaTeX[countCorrect]) + " }"
labelBtnValidate: "\text{CHECK (" + (LaTeX[3 - tries]) + ")}"
helpTextHint: "\text{" + (LaTeX[Element[hints, problemType]]) + "}"
pixelsRight: 16
pixelsLeft: 16
pixelsBottom: 16
pixelsTop: 24
borderBox = Polygon(Zip[PixelsToPoint[Corner[1], Corner[3], Corner[5], A], A, {(pixelsLeft, pixelsTop), (pixelsLeft, y(Corner[5]) - pixelsBottom), Corner[5] - (pixelsRight, pixelsBottom), (x(Corner[5]) - pixelsRight, pixelsTop)}])
layoutY: 274
layoutX: 311
layoutAppSize = Corner(5)
StartA = (3.4347091871177713, 5.572495645015256)
StartB = (4.1638207264560645, 6.136241785204535)
pulsingSpeed: 8
pulsing = 0.3 (slider from 0 to 1)
haloPixels: (pulsing * 7)
count = 2
onboardingCase: 1
onboardingX: 337
onboardingY: 150
OnboardingTextOffset = onboardingTextOffset(Corner[onboardingText, 1], Corner[onboardingText, 3], onboardingCase, Corner[1], Corner[3], Corner[5])
onboardingDisplayText: "" + (LaTeX[onboardingText]) + ""
useOnboarding: false
layoutCase: 1
layoutHintSolnY: 333
layoutHintSolnX: 11
layoutFeedbackX: layoutX + If[correct ∨ tries ≟ 3 ∨ problemType ≟ 1, -5, 126]
layoutFeedbackY: layoutY + If[problemType ≟ 1, -17, correct ∨ (¬correct) ∧ tries ≟ 3, 6, 1]
textForTable: {{"\textsf{\textbf{Candidate}}", "\textsf{Sara}", "\textsf{Matt}", "\textsf{Joseph}"}, Flatten[{"\textsf{\textbf{Number of Votes}}", Zip["" + (k) + "", k, filtNums]}]}
tableVotes = TableText(textForTable, "|_vc", 20, 46)
CornerInput = Corner(InputBox1, 3)
PixelInput = PointToPixels(Corner[1], Corner[3], Corner[5], CornerInput)
fixNums: true ∈ Zip[n > 1, n, freqNums]
textFootnotes: {"", "Round your answer to the nearest percent.", "Assume there cannot be a partial student."}
correctA: studentChoice
enableBtnValidate: inputSaved ≠ inputCurrent ∧ (Defined[currentValueA] ∨ Defined[currentValueB]) ∧ checkFormat[stringB]
textFeedback: "" + (LaTeX[If[correct, "$\text{✓ Correct}$", "$\text{✕ " + (If[tries < 3 ∧ problemType > 1, "Try again", "Maybe next time"]) + "}$"]]) + ""
textAnswer: "" + (LaTeX[If[problemType ≟ 1, ("\textsf{" * Element[{"Sara", "Matt", "Joseph"}, voteChoice]) + "}", problemType ≟ 2, "" + percentage + "\%", "" + numVotes + "\text{ students}"]]) + ""
solutions: {"\textsf{The student with the most votes in the sample is most likely to win.\\" + textAnswer + " had the most votes.}", "\textsf{Divide the number of votes that " + textCandidate + " received by the total number of votes. Multiply by }100.\\\[\dfrac{" + (filtNums(randomCandidate)) + "}{" + (filtNums(1)) + " + " + (filtNums(2)) + " + " + (filtNums(3)) + "} = \dfrac{" + (filtNums(randomCandidate)) + "}{" + finalTotal + "}=" + (round((percentage) / 100, 2)) + " \rightarrow " + percentage + "\%\]", "\textsf{Multiply the ratio of votes that " + textCandidate + " received to total votes by the students in the school. }\\\[\dfrac{" + (filtNums(randomCandidate)) + "}{" + finalTotal + "} \cdot" + randomPop + "\approx" + (round((randomPop * filtNums(randomCandidate) / finalTotal), 2)) + " \rightarrow " + numVotes + "\]\text{ students}"}
textSolution: "\textsf{\bold{Possible Solution}}\\" + (LaTeX[solutions(problemType)]) + ""
typicalError1: round(input1) ≟ numVotes ∧ input1 ≠ numVotes
typicalError2: input1 ≟ numVotes + 1
isTypicalError: (typicalError1 ∨ typicalError2) ∧ problemType ≟ 3
textQuestion2: "\textsf{Based on the results of the sample, " + (LaTeX[textQuestions(problemType)]) + "}\\
\footnotesize{\textsf{" + (LaTeX[textFootnotes(problemType)]) + "}}"
labelX = If(problemType ≟ 2, 552, 524)
textQuestion: "\textsf{School elections are at the end of next week. There are " + (LaTeX[randomPop]) + " students in the school and the}\\
\textsf{principal decided to take a random sample of " + (LaTeX[finalTotal]) + " students to find out which candidate each}\\
\textsf{student planned to vote for. The table below shows her survey results.}\\\\"
textPercent: "\textsf{" + (LaTeX[If[problemType ≟ 2, "\%", " students"]]) + "}"
isTypicalError2: problemType > 1 ∧ (¬validInput)
showhinttypicalerror2 = false
textHint: "\text{\color{" + (LaTeX[colorOrange]) + "}\bold{Hint}\\" + (LaTeX[If[showhinttypicalerror, helpTextHintTypicalError]]) + "" + (LaTeX[If[showhint ∧ showhinttypicalerror, "\\"]]) + "" + (LaTeX[If[showhint, helpTextHint]]) + "}"
tabOrder: {textQuestion, textQuestion2, tableVotes, btnCSara, btnCMatt, btnCJoseph, InputBox1, InputBox2, btnValidate, textHint, textAnswer, textSolution, btnNew}
inputA: NaN
validA = true
validB = true
btnValidateInactive: btnValidate
listInput1: Sequence[Element[stringA, n], n, 1, Length[stringA]] \ {" "}
a = checkFormat(stringB)
numVotesExact: (randomPop * filtNums(randomCandidate) / finalTotal)
maxTries = If(problemType ≟ 1, 1, 3)
enableInput: tries < maxTries ∧ (¬(validate ∧ correct))

Tool: PixelsToPoint
PixelsToPoint(Corner1,Corner3,Corner5,PixelCoords)
Input: Corner1, Corner3, Corner5, InputPixels
Output: OutputPoint

InputPixels: (100, 200)
xRight: x(Corner3)
xLeft: x(Corner1)
yTop: y(Corner3)
yBottom: y(Corner1)
yCoord: yTop - (y(InputPixels) / y(Corner5) * (yTop - yBottom))
xCoord: (x(InputPixels) / x(Corner5) * (xRight - xLeft)) + xLeft
OutputPoint: (xCoord, yCoord)

Tool: expandSegment
expandSegment(A,B,pixelGap,Corner1,Corner3,Corner5)
Input: A, B, pixelGap, Corner1, Corner3, Corner5
Output: newPoly

distanceX: (pixelGap / x(Corner5) * (x(Corner3) - x(Corner1)))
distanceY: (pixelGap / y(Corner5) * (y(Corner3) - y(Corner1)))
pointGap: distanceX
xyScale: distanceY / distanceX
A: (0, 0)
vecAB: B - A
pVec: (20 * UnitVector[(((-y(vecAB))) / xyScale, (x(vecAB) * xyScale))])
pVecAngle = Angle(xAxis, Line[(0, 0), pVec])
realAngle = If(pVecAngle ≟ pi / 2 ∨ pVecAngle ≟ (3 * pi / 2), pVecAngle, atand(tan(pVecAngle) / xyScale))
curveFunction = CurveCartesian((pointGap * cos(u)), ((pointGap * xyScale) * sin(u)), u, 0, (2 * pi))
K: curveFunction(realAngle)
vSpace = Vector(K)
allPoints: {A + vSpace, A - vSpace, B - vSpace, B + vSpace}
newPoly = Polygon(allPoints)

Tool: onboardingTextOffset
onboardingTextOffset(textCorner1,textCorner3,case,corner1,corner3,corner5)
Input: CornerText1, CornerText3, case, Corner1, Corner3, Corner5
Output: TextOffset

xPixels: ((x(CornerText3) - x(CornerText1)) * x(Corner5) / (x(Corner3) - x(Corner1)))
yPixels: ((y(CornerText3) - y(CornerText1)) * y(Corner5) / (y(Corner3) - y(Corner1)))
xOffset = Element({27, (-xPixels) + 2, 16 - xPixels / 2, 16 - xPixels / 2}, case)
yOffset = Element({-23, -23, yPixels - 27, -49}, case)
TextOffset: (xOffset, yOffset)

Tool: PointToPixels
PointToPixels(Corner1,Corner3,Corner5,InputPoint)
Input: Corner1, Corner3, Corner5, InputPoint
Output: OutputPixels

Corner1: (-5, -5)
Corner3: (16, 6)
Corner5: (300, 200)
xLeft: x(Corner1)
xRight: x(Corner3)
yTop: y(Corner3)
yBottom: y(Corner1)
yPixels: (y(Corner5) * (yTop - y(InputPoint)) / (yTop - yBottom))
xPixels: (x(Corner5) * (x(InputPoint) - xLeft) / (xRight - xLeft))
OutputPixels: (xPixels, yPixels)

Tool: Replace
Replace(list, item, index)
Input: l1, k, n
Output: l3

l1: {4, 5, 6}
n: 2
k: 8
l2 = Insert({k}, l1, n)
l3 = Remove(l2, {Element[l1, n]})

Tool: checkFormat
checkFormat(inputString)
Input: inputString
Output: formatOK

?

compressBlanks = Sequence(If[Element[inputString, A] ≟ " ", If[A ≟ 1 ∨ Element[inputString, A - 1] ≟ " ", "", " "], Element[inputString, A]], A, 1, Length[inputString])
numberString: ("" * Sum[compressBlanks])
numSlash: Length[Split[(("(" * numberString) * ")"), {"/"}]] - 1
noImpliedMultiply: Length[Split[(("A" * numberString) * "A"), {"0(", "1(", "2(", "3(", "4(", "5(", "6(", "7(", "8(", "9(", " 1", " 0", " .", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9", " ("}]] ≟ 1
noSubtract: Length[Split[(("A" * numberString) * "A"), {"0-", "1-", "2-", "3-", "4-", "5-", "6-", "7-", "8-", "9-", ")-", " ((-", " (-", " (((-"}]] ≟ 1
noBadChars: Length[Split[(("(" * numberString) * ")"), {"+", "*", ")(", "/(-", " -"}]] ≟ 1
formatOK: noBadChars ∧ noImpliedMultiply ∧ (numSlash ≟ 0 ∨ numSlash ≟ 1 ∧ Length[Split[(("A" * numberString) * "A"), {"."}]] ≟ 1) ∧ noSubtract