Skip to content

Instantly share code, notes, and snippets.

@dtanner
Created October 30, 2012 18:03
Show Gist options
  • Save dtanner/3981914 to your computer and use it in GitHub Desktop.
Save dtanner/3981914 to your computer and use it in GitHub Desktop.
Groovy script to generate addition table quizzes for kids.
def getRandomNumber() {
randomInt = new Random().nextInt(11)
}
def buildCell() {
"""${getRandomNumber()} <br>
+ ${getRandomNumber()} <br>
<hr width=40px>
"""
}
def createHtmlFile(String fileName){
int rows = 5
int colsPerRow = 8
def writer = new StringWriter()
def builder = new groovy.xml.MarkupBuilder(writer)
builder.html(){
body {
table(cellpadding:'20px') {
rows.times {
tr {
colsPerRow.times {
td([align:'right', style:'font-size:18px'], { mkp.yieldUnescaped (buildCell()) })
}
}
}
}
}
}
def f = new File("/tmp/$fileName")
f.delete()
f << writer.toString()
}
40.times {
createHtmlFile("${it}.html")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment