I'm trying to make a simple arithmetic exercise table (addition only, substration only or both)
my problems:
- some generated exercises are not well mixed (they only contain additions or too few substrations)
- generating a table that only contains subtraction exercises is also difficult.
I think I'm doing it the wrong way.
Maybe someone else can do a better job.
Thank you for your help.
Here is my attempt:
Code: Select all
;============================================ settings ===============================================
nlines:=4 ; number of lines you want
nlength:=5 ; length of a line (amount of numbers per line) note the last entry (maxindex) represents the sum of the previous entries
mindigits:=2 ; min length for a number
maxdigits:=3 ; max length for a number
type:=0 ; -1=only substraction, 1=only addition, 0=mixed between positive and negative numbers
;=====================================================================================================
gui, font, s12
gui, add, text, , How to make a table of arithmetic exercises ?`n`nnote: the last entry (maxindex) represents `nthe sum of the previous entries`n
gui, add, button, gok, generate
gui, font, s10
gui, add, edit, w500 h750 vtext,
gui, show
return
ok:
my_table:=arithmeticTable(nlines, nlength, mindigits, maxdigits, type)
guicontrol,,text, % st_printarr(my_table)
return
guiclose:
exitapp
return
;========================= aritmetic exercise generator function =====================================
ArithmeticTable(nlines:=4,nlength:=3,mindigits:=2,maxdigits:=3, type:=0) {
oTable:=[], tot:=0
loop, % nlines {
loop, % nlength {
loop, % rand(mindigits,maxdigits)
(a_index=1) ? (out .= rand(9)) : (out .= rand(0,9))
out .= "`n"
}
map:=strsplit(out, "`n")
oTable.push(map)
out:=""
}
for i, r in oTable {
for j, c in r {
((type=0) && rand(2)=1 && (j>1) && sum>oTable[i][j] && j<oTable[i].maxindex()) ? oTable[i,j] *= -1 : ((type<0) && (j>1) ? oTable[i,j] *= -1)
sum += oTable[i,j]
}
sum:=0
}
for i, r in oTable {
for j, c in r
(j<r.maxindex()) ? (tot += c) : (oTable[i,j]:=tot)
tot:=0
}
return oTable
}
;==================================== random number generator ===========================================
; FROM: http://www.autohotkey.com/forum/viewtopic.php?t=54713&postdays=0&postorder=asc&start=0
; EXAMPLES
/*
Rand() ; - A random float between 0.0 and 1.0 (many uses)
Rand(6) ; - A random integer between 1 and 6 (die roll)
Rand("") ; - New random seed (selected randomly)
Rand("", 12345) ; - New random seed (set explicitly)
Rand(50, 100) ; - Random integer between 50 and 100 (typical use)
*/
; RANDOM FUNCTION
Rand( a=0.0, b=1 ) {
IfEqual,a,,Random,,% r := b = 1 ? Rand(0,0xFFFFFFFF) : b
Else Random,r,a,b
Return r
}
;============================================ debugging function =============================================
;String Things by tidbit
;https://autohotkey.com/boards/viewtopic.php?f=6&t=53&sid=5c401643235e7a2e73d769f1e5deac0f
st_printArr(array, depth=5, indentLevel="")
{
for k,v in Array
{
list.= indentLevel "[" k "]"
if (IsObject(v) && depth>1)
list.="`n" st_printArr(v, depth-1, indentLevel . " ")
Else
list.=" => " v
list.="`n"
}
return rtrim(list)
}