Skip to content

Commit

Permalink
quiz: Add country/flag quiz
Browse files Browse the repository at this point in the history
  • Loading branch information
erg committed Jan 28, 2022
1 parent abacb5a commit 7395a8a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion extra/quiz/quiz.factor
Expand Up @@ -3,7 +3,8 @@
USING: accessors arrays assocs combinators combinators.smart
continuations formatting io kernel math math.functions
math.parser prettyprint quotations random sequences
sequences.extras splitting strings unicode ;
sequences.extras splitting strings unicode unicode.flags
unicode.flags.images ;
IN: quiz

GENERIC: generate-question* ( question -- quot )
Expand Down Expand Up @@ -63,6 +64,8 @@ TUPLE: sqrt-question < number-response random-choices ;
TUPLE: sq-question < number-response random-choices ;
TUPLE: stack-shuffler < string-response n-shufflers ;
TUPLE: state-capital-question < string-response ;
TUPLE: country-from-flag < string-response n ;
TUPLE: flag-from-countries < string-response n ;

M: multiplication generate-question*
[ count>> random ] [ n>> ] bi '[ _ random 2 + ] replicate
Expand Down Expand Up @@ -91,6 +94,12 @@ CONSTANT: state-capitals H{
M: state-capital-question generate-question* drop state-capitals keys random '[ _ state-capital ] ;
M: state-capital-question parse-response drop trim-blanks >title ;

M: country-from-flag generate-question* drop valid-flags random '[ _ flag>unicode ] ;
M: country-from-flag parse-response drop trim-blanks >title ;

M: flag-from-countries generate-question* drop valid-flag-names random '[ _ unicode>flag ] ;
M: flag-from-countries parse-response drop trim-blanks >title ;

CONSTANT: stack-shufflers { dup 2dup drop 2drop swap over rot -rot roll -roll 2dup pick dupd }

M: stack-shuffler generate-question*
Expand Down Expand Up @@ -181,6 +190,16 @@ M: sequence run-multiple-choice-quiz ( seq n -- questions )
T{ stack-shuffler { n-shufflers 4 } }
} 5 run-multiple-choice-quiz score-quiz ;

: run-country-from-flag-quiz ( -- )
{
T{ country-from-flag { n 4 } }
} 5 run-multiple-choice-quiz score-quiz ;

: run-flag-from-countries-quiz ( -- )
{
T{ flag-from-countries { n 4 } }
} 5 run-multiple-choice-quiz score-quiz ;

: run-main-quiz ( -- )
{
T{ multiplication { count 10 } { n 10 } }
Expand Down

0 comments on commit 7395a8a

Please sign in to comment.