/ Here is the software to generate the kid game / Each function is in APPLICATION-SPECIFIC. / To do: determine <, > , =. Fraction multiply. logogif: "\"minisp.gif\"" / minisp.gif or sp.gif basicwidth: 60 tilewidth: basicwidth tileheight: 50 / point size to fit tile 38 according to Justin / BASICS /finds intersection of two lists / fastest of all intersect: {[x;y] x,: () y,: () if[(#x) < (#y) i: x ?/: y j: & i < #x :x[?i[j]] ] i: y ?/: x j: & i < #y :y[?i[j]] } /finds intersection of two lists / fastest of all hasintersect: {[x;y] x,: () y,: () i: x ?/: y : (&/i) < #x } / x is a proper subset of y propersubset:{[x;y] x,: () y,: () if[~ (#x) < (#y); :0] / must be smaller :(#x) = (#intersect[x;y]) } subset:{[x;y] (#x) = (#intersect[x;y])} subset:{[x;y] j: y ?/: x / if any js are as big as #y, then there is a member of x not in y :0 = |/ j = #y } / proportion of x that y covers approxsubset:{[x;y] j: y ?/: x / any equal to #y are in x but not in y :(# & j < (#y)) % (#x) } / finds indexes in x and y that intersect / If x and y are both sets, then the results will be of the same length / fastest of all intersectindexes: {[x;y] i: x ?/: y / where each y hits j: & i < #x / those ys that hit :(i[j];j) } /finds indexes in x that intersect with y intersectleftindexes: {[x;y] i: x ?/: y / where each y hits j: & i < #x / those ys that hit :i[j] } /finds intersection of two lists / and returns index pairs of matches. Assumes no duplicates / in either list intersectbothindexes: {[x;y] x,: () y,: () i: x ?/: y pairs: (i ,' (!#y)) k: & pairs[;0] < #x :pairs[k] } / this is a set intersection so we remove duplicates multiintersect:{[lists] size: #lists if[2 > size; :lists] first: lists[0],() jj: first ?/: (,/ ?:' lists[1+ !(size-1)]) / find indexes in first x: @[(1+#first) # 0; jj; + ; 1] x: (-1) _ x / delete missing entry kk: & x = size - 1 :first[kk] } / A faster difference differ:{[x;y] x,: () y,: () i: y ?/: x j: & i = #y :?x[j] } / Count the difference differcount:{[x;y] i: y ?/: x :# & i = #y } avg:{(+/ x) % # x} var:{avg[_sqr x] - _sqr avg[x]} std:{_sqrt var[x]} cov:{avg[x * y] - avg[x] * avg[y]} corr:{ (cov[x;y])%((std[x]) * (std[y]))} / delay based search / END OF BASICS / GENERATE HTML / Generate the html / The vals array has a name in upper left hand corner and then / it has column headers / Row headers are below name. / Values are inside. / Does the actual work printtable:{[file; vals; tablecolor] out: ,printheader[vals[0]] rem: 1 _ vals jj: !#rem out,: printrow[rem; tablecolor]'jj name: (file),(".html") web,: ,("http://cs.nyu.edu/cs/faculty/shasha/papers/data.d/"),name name 0: out } / first line printheader:{[vals] / width: 650 / width: _ (((#vals))%((#vals)-1)) * 450 / lastwidth: width - 450 superplywidth: (((#vals) - 1) * basicwidth) | (9*basicwidth) width: ((#vals) * basicwidth) | _ (((#vals))%((#vals)-1)) * superplywidth lastwidth: width - superplywidth colspan: (#vals) - 1 / out: "" out: "
"
 out,: " tablewidth.html"
 out,: ""
 out,: " "
 / change table width to change everything
 out,: ("
" out,: "" out,: (" " out,: (" " out,: "\" alt=\"\" width=\"" out,: "37" out,: "\" height=\"33\"> " j: 0 while[j < #vals / out,: "") j+: 1 ] out,: "" :out } / Does the actual work for multi-row header printtablemulti:{[file; vals; tablecolor] out: ,printheadermulti[vals[0]] rem: 1 _ vals jj: !#rem out,: printrow[rem; tablecolor]'jj / name: ($vals[0][0]),(".html") name: (file),(".html") web,: ,("http://cs.nyu.edu/cs/faculty/shasha/papers/data.d/"),name name 0: out } / first line printheadermulti:{[vals] / width: 650 / width: 50*((#vals)+1) / width: 650 / width: _ (((#vals))%((#vals)-1)) * 450 / lastwidth: width - 450 superplywidth: (((#vals) - 1) * basicwidth) | (9*basicwidth) width: ((#vals) * basicwidth) | _ (((#vals))%((#vals)-1)) * superplywidth lastwidth: width - superplywidth colspan: (#vals) - 1 / out: "
\"\"
" / out,: " " out,: " " out,: ($vals[j]), ("
" out: "
"
 out,: " tablewidth.html"
 out,: ""
 out,: " "
 / change TABLE WIDTH to change everything
 out,: ("
" out,: "" out,: (" " out,: (" " out,: "\" alt=\"\" width=\"" out,: "37" out,: "\" height=\"33\"> " j: 0 / I don't know about height and width. I think I don't / want it because it is already big enough. / I'm not sure: width=\"38\" height=\"38\" while[j < #vals out,: "") j+: 1 ] out,: "" :out } / spit out a table of values / starting with a second line. printrow:{[vals;tablecolor; i] even: (_ i % 2) = (i % 2) val: vals[i], () j: 0 out: "" while[j < #val x: even + j flag: (_ x % 2) = (x % 2) / out,: "") j+: 1 ] out,: "" if[i = ((#vals) - 1) / last one out,: "
\"\"
" / out,: " " out,: ($vals[j]), ("
0) & flag); out,: (" BGCOLOR=\"#"), tablecolor, ("\"")] out,: " NOWRAP>" v: val[j] out,: ,/(" " $v "
" ] :out } / Does the actual work printcardsold:{[vals] / out: ,"
"
  out: ,"  hint cards "
  out,: ,"  "    
  jj: !#vals
  out,: printcardrow[vals]'jj
  / out,: ,"
" out,: ," " name: "card.html" web,: ,("http://cs.nyu.edu/cs/faculty/shasha/papers/data.d/"),name name 0: out } / decide how to wrap a line to make it fit / no line should be bigger than about 25 wrapline:{[line] if[23 > #line; :line] if[line _sm "*src*"; :line] blanks: & line = " " blanks,: #line out: line[!*blanks] lastclear: 0 i: 1 while[i < #blanks flag: 23 < blanks[i] - lastclear if[flag lastclear: blanks[i-1] x: blanks[i-1] + 1 out,: ("
"), line[x + !(blanks[i] - x)] ] if[~ flag out,: line[blanks[i-1] + !(blanks[i] - blanks[i-1])] ] i+: 1 ] :out } printcardrowold:{[vals;i] / out: " " out,: " " out,: wrapline[vals[i]] out,: " " / out,: " " :out } / Does the actual work printcards:{[file; vals; valscolors] / out: ,"
"
  out: ,"  hint cards "
  out,: ,"  "    
  by3:{[i] (_ i % 3) = (i % 3)}
  if[~ by3[#vals]
	vals,: ,*|vals
	valscolors,: ,*|valscolors
  	if[~ by3[#vals]
		vals,: ,*|vals
		valscolors,: ,*|valscolors
	]
  ]
  i: 0
  while[(i) < #vals
    out,: ,printcardrow[vals;i;i+1; i+2; valscolors]
    i+: 3
  ]
  / out,: ,"
" out,: ," " name: file web,: ,("http://cs.nyu.edu/cs/faculty/shasha/papers/data.d/"),name name 0: out } printcardrow:{[vals;i; j; k; valscolors] / out: " " out,: "" out,: " " out,: wrapline[vals[i]] out,: " " out,: "" out,: " " out,: wrapline[vals[j]] out,: " " out,: "" out,: " " out,: wrapline[vals[k]] out,: " " out,: " " / out,: " " :out } / END OF GENERATE HTML / APPLICATION-SPECIFIC / print out a set printset:{[vec] if[0 = #vec; :("{}")] x: -2 _ ,/ ($vec) ,\: (", ") :("{"), x, ("}") } / GENERATE INTERIOR VALUES FOR ADDITION / generate the values given rows and columns / for 2-ply genvalsplus:{[title; rows; cols] vals: ,(,title), cols / operation name is here calcvals: () i: 0 while[i < #rows row: rows[i] newvals: row+cols / function is here allrow: row, newvals vals,: ,allrow calcvals,: newvals i+: 1 ] :(vals; ?calcvals) } / GENERATE INTERIOR VALUES FOR MULTIPLICATION / generate the values given rows and columns / for 2-ply genvalsmult:{[title; rows; cols] vals: ,(,title), cols / operation name is here calcvals: () i: 0 while[i < #rows row: rows[i] newvals: row*cols / function is here allrow: row, newvals vals,: ,allrow calcvals,: newvals i+: 1 ] :(vals; ("Multiplication: The product is "),/: ($?calcvals),\:(".")) } / GENERATE INTERIOR VALUES FOR DIVISION / generate the values given rows and columns / for 2-ply genvalsdiv:{[title; rows; cols] vals: ,(,title), cols / operation name is here calcvals: () i: 0 while[i < #rows row: rows[i] x: _:' cols % row y: cols - (_:' row * x) newvals: ` $ ($x) ,' (" R"),/: ($y) allrow: row, newvals vals,: ,allrow calcvals,: newvals i+: 1 ] :(vals; ("Division: The quotient is "),/: ($?calcvals),\:(".")) } / GENERATE INTERIOR VALUES FOR INTERSECTION / algorithm for intersection is simply to find the intersection of two / sets / first evaluate, for each member, the product of the other members. / then generate for that member all multiples up to that product. / Take the intersection of those multiples and find the minimum value. / generate the values given rows and columns / for 2-ply genvalsintersect:{[rows; cols] vals: ,(,"Intersection"), printset'cols / operation name is here calcvals: () i: 0 while[i < #rows row: rows[i] newvals: printset'intersect[row]'cols / function is here allrow: (,printset[row]), newvals vals,: ,allrow calcvals,: newvals i+: 1 ] :(vals; ("Sets: The intersection is "),/: ($?calcvals),\:(".")) } / GENERATE INTERIOR VALUES FOR LEAST COMMON MULTIPLE (LCM) / algorithm for lcm is given a vector / first evaluate, for each member, the product of the other members. / then generate for that member all multiples up to that product. / Take the intersection of those multiples and find the minimum value. lcm:{[vec] m: genmemberslcm[vec]'vec x: multiintersect[m] :&/x } genmemberslcm:{[vec; mem] i: vec ? mem newvec: vec _di i x: */newvec y: 1 + !x :mem * y } / generate the values given rows and columns / for 2-ply genvalslcm:{[rows; cols] vals: ,(,"LeastComMult"), cols / operation name is here calcvals: () i: 0 while[i < #rows row: rows[i] newvec: row,/: cols / create a vector for lcm newvals: lcm'newvec / function is here allrow: row, newvals vals,: ,allrow calcvals,: newvals i+: 1 ] :(vals; ?calcvals) } / GENERATE INTERIOR VALUES FOR GREATEST COMMON DIVISOR (GCD) / algorithm for gcd is given a vector / first evaluate, for each member, the product of the other members. / then generate for that member all multiples up to that product. / Take the intersection of those multiples and find the minimum value. gcd:{[vec] m: genmembersgcd'vec x: multiintersect[m] :|/x } / we find the divisors of num genmembersgcd:{[num] x: 1 + !num i: & isdivisor[num]'x :x[i] } isdivisor:{[num;x] y: num % x : y = _ y } / generate the values given rows and columns / for 2-ply genvalsgcd:{[rows; cols] vals: ,(,"GreatestCommonFact"), cols / operation name is here calcvals: () i: 0 while[i < #rows row: rows[i] newvec: row,/: cols / create a vector for gcd newvals: gcd'newvec / function is here allrow: row, newvals vals,: ,allrow calcvals,: newvals i+: 1 ] :(vals; ("The greatest common factor is "),/: ($?calcvals),\:(".")) } / GENERATE PICTORIAL FRACTIONS genfracpict:{[title; rows; cols] vals: ,(,title), cols / operation name is here calcvals: () i: 0 while[i < #rows row: rows[i] newvals: genfrac[row]'cols allrow: row, newvals vals,: ,allrow calcvals,: printfracsup'convertto12ths'(row ,/: cols) i+: 1 ] :(vals; ("Fraction expressed in 12ths: "),/: ($?calcvals),\:(".")) } convertto12ths:{[pair] num: pair[0] denom: pair[1] x: _ 12 % denom denom: 12 num*: x :(num;denom) } / generate a pictorial fraction table for this num out of this many / denoms, e.g. 7/12 would be 7 reds among 12 lines. genfrac:{[num; denom] x: _ 12 % denom denom: 12 num*: x out: () / out,: "" / out,: " littletable" / out,: " " / out,: " " out,: " " i: 0 while[i < denom - num out,: " " i+: 1 ] while[i < denom out,: " " i+: 1 ] out,: "
" out,: "
" / out,: " " :out } / GENERATE INTERIOR VALUES FOR FRACTION ADD / reduce a pair to its lowest terms / but leave as improper reducelowest:{[pair] num: pair[0] den: pair[1] y: gcd[num,den] num: _ num % y den: _ den % y :(num;den) } / add two fractions addfrac:{[pair1; pair2] num1: pair1[0] den1: pair1[1] num2: pair2[0] den2: pair2[1] x: lcm[den1,den2] mult1: _ x % den1 mult2: _ x % den2 new: ( (num1*mult1) + (num2*mult2); x) / add is here :reducelowest[new] / num: new[0] / den: new[1] / y: gcd[num,den] / num: _ num % y / den: _ den % y / :(num;den) } / 123/128 / print out a fraction printfracsup:{[pair] if[pair[0] = pair[1]; :"1"] out: () if[pair[0] > pair[1] out,: ("1 ") pair[0]-: pair[1] ] :out,(""),($pair[0]),("/"),($pair[1]),("") } / print out a fraction using a table printfracnew:{[pair] if[pair[0] = pair[1]; :"1"] out: "" if[pair[0] > pair[1] x: _ pair[0] % pair[1] out,: ($x), (" ") pair[0]-: pair[1] ] / :out,(""),($pair[0]),("/"),($pair[1]),("") y: (" ") y,: (out), ("") y,: "" y,: ("
") y,: ($pair[0]), ("
") / y,: (out), (" —
") y,: ($pair[1]), ("
") / :out, y : y } / print out a fraction using a table printfrac:{[pair] if[pair[0] = pair[1]; :"1"] out: "" if[~ pair[0] < pair[1] x: _ pair[0] % pair[1] out,: ($x), (" ") pair[0]-: x*pair[1] ] / :out,(""),($pair[0]),("/"),($pair[1]),("") y: " " y,: "" y,: "" y,: "" y,: "" y,: "" y,: "
" y,: out y,: "" if[0 < pair[0] / beginning of fraction y,: (" ") y,: ("
") y,: ($pair[0]), ("
") y,: (" ---
") y,: ($pair[1]), ("
") / end of fraction ] / y,: ("
") y,: "" y,: " " y,: "" y,: (" ") y,: " " y,: " " y,: " " y,: "" y,: "" / :out, y : y } / print out a fraction using a table / reducelowest[pair] printfrac2:{[pair] if[1 = #pair; :pair] if[(pair ~ reducelowest[pair]) & (pair[0] < pair[1]); :printfrac[pair]] y: (" ") y,: " " y,: "" y,: "" y,: "" y,: "" y,: "" y,: "" y,: "" y,: "" y,: "" y,: "" y,: "" / pair: reducelowest[pair] out: "" if[~ pair[0] < pair[1] x: _ pair[0] % pair[1] out,: ($x), (" ") pair[0]-: x*pair[1] ] if[0 < pair[0] pair: reducelowest[pair] ] / :out,(""),($pair[0]),("/"),($pair[1]),("") y,: "" y,: "" y,: "" y,: (" ") y,: "" y,: "" y,: "" y,: "" y,: "" y,: "" y,: "" y,: "
" / beginning of fraction y,: (" ") y,: ("
") y,: ($pair[0]), ("
") y,: (" _
") y,: ($pair[1]), ("
") y,: "
= " y,: out y,: "" if[0 < pair[0] / beginning of fraction y,: (" ") y,: ("
") y,: ($pair[0]), ("
") y,: (" _
") y,: ($pair[1]), ("
") / end of fraction ] y,: "
" / :out, y : y } / UNUSED printfractext:{[pair] if[pair[0] = pair[1]; :"1"] out: () if[pair[0] > pair[1] out,: ("1 ") pair[0]-: pair[1] ] :out,($pair[0]),("/"),($pair[1]) } / generate the values given rows and columns / for 2-ply / rows and columns are vectors of pairs genvalsfracadd:{[rows; cols] vals: ,(,"+"), printfrac'cols / operation name is here calcvals: () i: 0 while[i < #rows row: rows[i] newvec: addfrac[row]'cols / create a vector for fractions newvals: newvec allrow: (,row), newvals vals,: ,printfrac'allrow calcvals,: printfracsup'newvals i+: 1 ] :(vals; ("Fractions: The sum is "),/: ($?calcvals),\:(".")) } genvalsfracpie:{[rows; cols] vals: ,(,"FractionPie"), cols / operation name is here calcvals: () i: 0 while[i < #rows row: rows[i] / newvec: (row ,/: cols) newvec: (cols ,\: row) newvals: newvec allrow: (,row), newvals vals,: ,printfrac2'allrow calcvals,: printfracsup'newvals i+: 1 ] :(vals; ("Fractions: The sum is "),/: ($?calcvals),\:(".")) } / GENERATE INTERIOR VALUES FOR EVALUATION / These are globals x: 0 y: 0 z: 0 printvar:{[vec] vec,: () if[1 = #vec; :("x = "),($vec[0])] if[2 = #vec; :("x = "),($vec[0]), ("
y = "),($vec[1])] if[3 = #vec :("x = "),($vec[0]), ("
y = "),($vec[1]),("
z = "),($vec[2]) ] } printexp:{[exp] i: & ~ exp _in\: "*()" :exp[i] } eval:{[exp; vec] if[0 < #vec; . ("x:: "),($vec[0])] if[1 < #vec; . ("y:: "),($vec[1])] if[2 < #vec; . ("z:: "),($vec[2])] : . exp } / generate the values given rows and columns / for 2-ply / rows and columns are vectors of pairs genvalseval:{[rows; cols] vals: ,(,"Evaluate"), printvar'cols / operation name is here calcvals: () i: 0 while[i < #rows row: rows[i] newvec: eval[row]'cols / create a vector for fractions newvals: newvec allrow: (,printexp[row]), newvals vals,: ,allrow calcvals,: newvals i+: 1 ] :(vals; ("Evaluation: The expression is "),/: ($?calcvals),\:(".")) } / GENERATE INTERIOR VALUES FOR ONE VARIABLE SOLVING / So we have something like (3*x) + 2 which is represented by (3 2) / or 4*x - 2 (4 -2) / print one side of the equation printside:{[pair] if[0 > pair[1] yy: _abs pair[1] :[1 = pair[0] :("x - "),($yy) :($pair[0]),("x - "),($yy)] ] if[~ 0 > pair[1] :[1 = pair[0] :("x + "),($pair[1]) :($pair[0]),("x + "),($pair[1])] ] } / one variable expression solver / 3x + 2 = 4x + 15 / (3-4)x = 15 - 2 solveone:{[pair1; pair2] newcoef1: pair1[0] - pair2[0] / coefficient of x on left side after / subtracting the right side. newconst2: pair2[1] - pair1[1] / coefficient of x^0 on right side x: (newconst2 % newcoef1) :(` $ ("x = "), ($x)) } / generate the values given rows and columns / for 2-ply / rows and columns are vectors of pairs gensolveone:{[rows; cols] vals: ,(,"Find_x"), printside'cols / operation name is here calcvals: () i: 0 while[i < #rows row: rows[i] newvec: solveone[row]'cols / create a vector for fractions newvals: newvec allrow: (,printside[row]), newvals vals,: ,allrow calcvals,: newvals i+: 1 ] :(vals; ("Find_x: "),/: ($?calcvals),\:(".")) } / GENERATE INTERIOR VALUES FOR LEVERS torqueL:{[dist; pos; weight] (pos - (-dist)) * weight} torqueR:{[dist; pos; weight] (pos - (dist)) * weight} / stable if net effect on R is negative torque / and net effect on L is positive torque stable:{[posvec; weightvec] dist: 1 / of fulcrums from center boardweight: 1 / weight of board netL: +/ torqueL[dist]'[posvec;weightvec] netL+: torqueL[dist;0; boardweight] netR: +/ torqueR[dist]'[posvec;weightvec] netR+: torqueR[dist;0; boardweight] flag: :[(netL < 0) ; `"Tips left" (netR > 0); `"Tips right" `"Does not tip"] :flag } / 123/128 / print out a fraction printlever:{[pair] :("Position: "), ($pair[0]), ("
Weight: "), ($pair[1]) } / generate the values given rows and columns / for 2-ply / rows and columns are vectors of pairs / posvec: 2 -2 / weightvec: 5 2 / stable[posvec; weightvec] genvalslever:{[rows; cols] vals: ,(,"Lever"), printlever'cols / operation name is here calcvals: () otherpos: cols[;0] otherweight: cols[;1] i: 0 while[i < #rows row: rows[i] rowpos: row[0] rowweight: row[1] allposvec: rowpos ,/: otherpos allweightvec: rowweight ,/: otherweight newvec: stable'[allposvec; allweightvec] / vector of stability newvals: newvec allrow: (,printlever[row]), newvals vals,: ,allrow calcvals,: newvals i+: 1 ] :(vals; ("Lever: "),/: ($?calcvals),\:(".")) } / GENERATE INTERIOR VALUES FOR OLDER THAN / algorithm for lcm is given a vector / first evaluate, for each member, the product of the other members. / then generate for that member all multiples up to that product. / Take the intersection of those multiples and find the minimum value. older:{[vec] m: genmemberslcm[vec]'vec x: multiintersect[m] :&/x } genmembersolder:{[vec; mem] i: vec ? mem newvec: vec _di i x: */newvec y: 1 + !x :mem * y } / return a pair the first element of which are the people in the / cols[index] and the second is the number of other people each of them / is older than. fillcol:{[cols;index] mycol: cols[index] / all pairs people: ?,/mycol nums: howmany[mycol]'people :(people;nums) } / given a set of pairs and a person, how many people is that / person older than howmany:{[pairs;person] out: person,() realnew: out lefts: pairs[;0] rights: pairs[;1] flag: 1 while[flag i: & lefts _in\: realnew new: rights[i] realnew: differ[new;out] flag: 0 < #realnew out,: realnew ] :#?out _dv person } / generate the values given rows and columns / for 2-ply / cols are of the form of a set of pairs e.g. (`Tom `Judy; `Judy `Linda;...) / rows are a single assertion, e.g. (`Joe `Tom) / We want to count the number of people the person in the left of the / row assertion is surely older than. genvalsolder:{[rows; cols] vals: ,(,"JoeOlder"), convertcolsolder[cols] / operation name is here / col.id: ,/(#:' cols) #' (!#cols) / first fill in for each column how many people each person is older than col.id: !#cols col.people: (#cols) # ,() col.numbers: (#cols) # ,() i: 0 while[i < #cols pair: fillcol[cols; i] col.people[i]: pair[0] col.numbers[i]: pair[1] i+: 1 ] calcvals: () i: 0 while[i < #rows pair: rows[i] / e.g. `Joe `Henry younger: pair[1] / younger person in the pair newvec: () j: 0 while[j < #cols x: col.people[j] ? younger newvec,: :[x = #col.people[j]; 1;1+col.numbers[j][x]] j+: 1 ] allrow: (,($pair[0]), (" older than "), ($pair[1])), newvec vals,: ,allrow calcvals,: newvec i+: 1 ] name: ($rows[0;0]) / name of older person :(vals; (("Age Logic: "), (name), (" is surely older than ")) ,/: ($?calcvals) ,\:(".")) } / convert header for cols into a string convertcolsolder:{[cols] i: 0 out: () while[i< #cols out,: ,convertline[cols[i]] / out,: "|" i+: 1 ] / :(-1) _ out :out } / each col is a a set of pairs e.g. (`Tom `Judy; `Judy `Linda;...) convertline:{[pairs] i: 0 out: () while[i < #pairs out,: ($pairs[i;0]), (" older than "),($pairs[i;1]),("
") i+: 1 ] :(-4) _ out } / INPUT FROM A TEXT LINE USING VERTICAL BARS / parses a field based on vertical bars getfields:{[line] i: line = "|" j1: &i j2: &~i line @:j2 size: #j1 :(0,(j1 - !size)) _ line } / get rid of blanks at either end of the string delendblanks:{[string] if[0 = #string; :""] if[string ~ ,"" ; :""] i: & ~ string = " " if[(#string) = (#i); :string] if[0 = (#i); :""] string: (- ((#string) - (1 + *|i))) _ string :(*i) _ string } / Handles one line of input at a time according to table schema above. / A little more space efficient than the previous version. processline:{[line] :delendblanks'getfields[line] } / EXECUTION web: () cards: () / card content cardcolors: () / card backgrounds / addition rows: !10 cols: !10 title: "Plus" pair: genvalsplus["+"; rows; cols] tablecolor: "0000FF" printtable["Plus";pair[0]; tablecolor] / pair[1] / these are to generate hint cards advsum: ("The sum is odd." "The sum contains a 2." "The sum contains a 5." "The sum contains a 1." "The sum contains a 4." "The sum contains a 3." "The sum contains a 6." "The sum contains a 7." "The sum contains a 9." "The sum contains a 8." "The sum contains a 0.") advsum: ("Addition Hint: "),/: advsum / cards,: advsum / fourth grade addition rows: 47 63 19 54 78 39 42 cols: 6 3 9 8 7 4 pair: genvalsplus["+"; rows; cols] tablecolor: "0000FF" printtable["AdvancedPlus"; pair[0]; tablecolor] / cards,: advsum / decimal addition rows: .05, .1, .12, .34, .5, .63, .925, 1.2 ,5 cols: .05, .1, .12, .37, .6, .78, .925, 1.8, .5 pair: genvalsplus["+"; rows; cols] title: "DecimalAdd" tablecolor: "0000FF" printtable[title; pair[0]; tablecolor] / pair[1] / these are to generate hint cards / multiplication rows: 1+!9 cols: 1 + !9 pair: genvalsmult["X"; rows; cols] title: "Times" tablecolor: "FF9900" printtable[title; pair[0]; tablecolor] / cards,: pair[1] / these are to generate hint cards advmult: ("The product is odd." "The product is between 40 and 50, inclusive." "The product contains a 2." "The product contains a 5." "The product contains a 1." "The product contains a 4." "The product contains a 3." "The product contains a 6." "The product contains a 7." "The product contains a 9." "The product contains a 8." "The product contains a 0." "The product is less than 30.") advmult: ("Multiplication Hint: "),/: advmult / cards,: advmult / cardcolors,: (#advmult) # ,"hintcardorange.gif" / multiplication rows: .3, .03, 3, .4, 4, .04, .2, .02, 1 cols: .2, .02, 2, .04, .4, 4, .05, .5, 5 pair: genvalsmult["x"; rows; cols] title: "DecimalMult" tablecolor: "0000FF" printtable[title; pair[0]; tablecolor] / cards,: pair[1] / these are to generate hint cards xx: ("Decimal Part < 0.7." "Decimal Part > 0.3." "Decimal Part > 0.6." "Decimal Part < 0.4." "Whole Number Part < 2." "Whole Number Part > 1.") / cards,: xx rows: -4, -7, 8, -6, 9, 1, -2, 3, -5 cols: -3, 4, 7, -8, 0, 1, -5, 2, -9 pair: genvalsmult["x"; rows; cols] title: "SignedMult" tablecolor: "0000FF" printtable[title; pair[0]; tablecolor] / cards,: pair[1] / these are to generate hint cards rows: 6, 60, .6, .06, 600, .006 cols: 1, 10, 100, 1000, 10000, 100000 pair: genvalsmult["x"; rows; cols] title: "Multby10" tablecolor: "0000FF" printtable[title; pair[0]; tablecolor] / cards,: pair[1] / these are to generate hint cards cols: 426 5629 872 7871 353 3213 rows: 21 121 57 82 165 pair: genvalsdiv["_"; rows; cols] title: "Division" tablecolor: "0000FF" printtable[title; pair[0]; tablecolor] / cards,: pair[1] / these are to generate hint cards xx: ("The quotient < 10" "The quotient > 100" "The quotient < 80" "The quotient is between 15 and 60 inclusive" "The quotient is between 50 and 120 inclusive") / cards,: xx / least common multiples rows: 2, 3, 4, 5, 6, 8, 9, 10, 12 cols: 1,2,3,4,6,8,9,10,12 pair: genvalslcm[rows;cols] tablecolor: "00FFFF" printtable["LeastCommonMult"; pair[0]; tablecolor] xx: ("Least Common Multiple is even." "Least Common Multiple is odd." "Least Common Multiple is 6." "Least Common Multiple is 8." "Least Common Multiple is 12." "Least Common Multiple is 20." "Least Common Multiple is 24." "Least Common Multiple < 11." "Least Common Multiple > 10." "Least Common Multiple > 8." "Least Common Multiple < 18.") / xx: ("Greatest Common Factor Hint: "),/: xx / cards,: xx / cardcolors,: (#xx) # ,"hintcardaqua.gif" / greatest common divisors rows: 4, 6, 9, 12, 15, 18, 20, 30, 60 cols: 2, 4, 7, 8, 9, 10, 12, 15, 24 pair: genvalsgcd[rows;cols] tablecolor: "FF00FF" printtable["GreatestCommonFact"; pair[0]; tablecolor] / cards,: pair[1] xx: ("Greatest Common Factor is even." "Greatest Common Factor is odd." "Greatest Common Factor < 5." "Greatest Common Factor < 4." "Greatest Common Factor > 8." "Greatest Common Factor > 6." "Greatest Common Factor > 10." "Greatest Common Factor < 15." "Greatest Common Factor > 3.") / xx: ("Greatest Common Factor Hint: "),/: xx / cards,: xx xx: xx, xx, xx / cards,: xx / cardcolors,: (#xx) # ,"hintcardpink.gif" / Evaluate rows: ("(3*x) + 2*y" "x + 5" "15") cols:((1 2 3) (4 5 6) (6 4 5)) pair: genvalseval[rows; cols] tablecolor: "0000FF" printtablemulti["Evaluate"; pair[0]; tablecolor] / pair[1] / Solve a one variable problem rows: ((3 2) (2 1) (-4 3)) cols: ((1 3) (4 5) (-2 -5)) pair: gensolveone[rows; cols] tablecolor: "0000FF" printtablemulti["Solve"; pair[0]; tablecolor] / cards,: pair[1] advalg: ("x < -1." "x < 2." "x > -1." "x > 0." "x > -2." "x > 1.") advalg: ("Algebra Hint: "),/: advalg cards,: advalg cardcolors,: (#advalg) # ,"hintcardblue.gif" / input from text line lines: ("Geometry | three sided figure | four sided figure | five sided figure" "equal angle| equilateral triangle | rectangle | pentagon" "unequal angle | triangle |quadrilateral |5-gon") vals: processline'lines / printtable[vals] / from a file lines: 0: "triangle" vals: processline'lines forcards: ?,/1 _' 1 _ vals / eliminate the first line and then first column forcards: ("Geometry Facts: "),/: forcards / cards,: forcards tablecolor: "0000FF" printtable["Triangle"; vals; tablecolor] / from a file lines: 0: "quads" vals: processline'lines forcards: ?,/1 _' 1 _ vals / eliminate the first line and then first column forcards: ("Geometry answer: "),/: forcards / cards,: forcards tablecolor: "0000FF" printtablemulti["Quadrilaterals"; vals; tablecolor] / from a file lines: 0: "cousins" vals: processline'lines forcards: ?,/1 _' 1 _ vals / eliminate the first line and then first column forcards: ("First Cousins: "),/: forcards / cards,: forcards tablecolor: "0000FF" printtablemulti["Cousins"; vals; tablecolor] / from a file lines: 0: "geography" vals: processline'lines forcards: ?,/1 _' 1 _ vals / eliminate the first line and then first column forcards: ("Geography: "),/: forcards / cards,: forcards tablecolor: "0000FF" printtablemulti["Geography"; vals; tablecolor] / from a file lines: 0: "wordproblem" vals: processline'lines forcards: ?,/1 _' 1 _ vals / eliminate the first line and then first column forcards: ("Word Problem: "),/: forcards / cards,: forcards tablecolor: "0000FF" printtablemulti["Word Problem"; vals; tablecolor] / from a file lines: 0: "words" vals: processline'lines forcards: ?,/1 _' 1 _ vals / eliminate the first line and then first column forcards: ("Language Arts: "),/: forcards / cards,: forcards tablecolor: "0000FF" printtablemulti["Words"; vals; tablecolor] / from a file lines: 0: "german" vals: processline'lines forcards: ?,/1 _' 1 _ vals / eliminate the first line and then first column forcards: ("German: "),/: forcards / cards,: forcards tablecolor: "0000FF" printtablemulti["Klein"; vals; tablecolor] / older than cols: ((`Tom `Judy; `Judy `Linda; `David `Linda; `Tom `Henry) (`Henry `Judy; `Judy `Linda; `Linda `Tom; `Henry `Tom) (`Linda `David; `Linda `Judy; `David `Henry; `Tom `Henry)) rows: (`Joe `Judy; `Joe `David; `Joe `Henry; `Joe `Linda; `Joe `Tom) pair: genvalsolder[rows; cols] tablecolor: "0000FF" printtablemulti["Joe_Older";pair[0]; tablecolor] / cards,: pair[1] / intersection rows: (`A `B `C `C `D `A `B `C `D `A `C) cols: (`A `C `D `B `D `E `A `A `B `C `D) pair: genvalsintersect[rows;cols] tablecolor: "0000FF" printtable["Intersection"; pair[0]; tablecolor] / cards,: pair[1] / fraction add rows: ((1 6) (1 4) (1 3) (1 2) (2 3) (3 4)) cols: rows pair: genvalsfracadd[rows; cols] tablecolor: "0000FF" printtable["FractionAdd"; pair[0]; tablecolor] / cards,: pair[1] advfrac: ("The fractional part < 1/2." "The fractional part < 1/4." "The fractional part > 1/3." "The fractional part < 2/3." "The fractional part > 3/4." "The whole part > 1.") advfrac: ("Fraction Hint: "),/: advfrac / cards,: advfrac / fraction pie rows: 1+!8 cols: 1+!4 pair: genvalsfracpie[rows; cols] tablecolor: "FF0022" printtable["FractionPie"; pair[0]; tablecolor] / cards,: pair[1] / fraction display rows: 1 2 3 cols: 12 3 4 6 pair: genfracpict["Expressin12ths"; rows; cols] tablecolor: "0000FF" printtable["Expressin12ths"; pair[0]; tablecolor] / cards,: pair[1] / physics of levers / rows are pairs of positions and weights / Similarly for columns. / There are fulcra at the two positions -1 and 1. The board weighs 1. rows: ((2 2) (3 1) (2 5) (3 4)) cols: ((-2 0.5) (-3 3) (-5 1) (-2 4)) pair: genvalslever[rows; cols] tablecolor: "0000FF" printtablemulti["Lever"; pair[0]; tablecolor] / cards,: pair[1] / cardcolors,: (#pair[1]) # ,"hintcardaqua.gif" / final output of cards / cards?: / "cards.html" 0: cards,\: ("
") printcards["cards.html"; cards; cardcolors] xx: 0: "piegifs" cards: ("") cardcolors: (#xx) # ,"-" / cards: 0: "piegifs" / cardcolors: (#cards) # ,"xx" printcards["cardspies.html"; cards; cardcolors] \\