From 88356293e60a89c6f867d173b9f4222d420b383c Mon Sep 17 00:00:00 2001 From: Jean-Christophe Jameux Date: Sun, 10 Oct 2021 20:05:40 +0200 Subject: [PATCH] =?UTF-8?q?G=C3=A9n=C3=A9rateur=20fonctionnel=20!!!!!!!!!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- elm-stuff/0.19.1/QCM.elmi | Bin 9952 -> 11014 bytes elm-stuff/0.19.1/QCM.elmo | Bin 71379 -> 72120 bytes elm-stuff/0.19.1/d.dat | Bin 1626 -> 1630 bytes src/QCM.elm | 184 +++++++++++++++++++------------------- 4 files changed, 94 insertions(+), 90 deletions(-) diff --git a/elm-stuff/0.19.1/QCM.elmi b/elm-stuff/0.19.1/QCM.elmi index 65835a4e748ca417aa78c43dcaf77590b25b8922..86818cd53dc31e66da2762ad074597324412ec34 100644 GIT binary patch delta 456 zcmaFh+ZHxKjK`cSF(@^+ASW?7wP>=xh{I%7$^6L+c)})YiHd;O8^x=68JQ=qm5b)) zEK4lPOiap2EoPXkC@VGjJ#PqB8NJC{_$E$X#UIQrP>@(u3^aG6s_iIYSoe~^<9kt>2Z$tN)kYU$=kDK%yp1%ym$ zF-)r1B{8qqCvmcZn$qTd;+%|%%6L@yCMFlFg?bjC)N&O|E>5`fCg-afOn#suF3H4z9WZYeP|arKVdf|VhDu3hejWqk fB}VxkM)m z3X3p<*gzW2RuBx{yisT^`{Ydd8I!lmwQ}(krREmoBqpa8O?H$}*jy_g$H*lD7u$SZ zN{xB*Z3SIMsC6AmI#8C0vK552`JHkD3y7&xFjRg8R!(#W+BaNh&g(b1I5KA M8%T>!{;S0a0Q>VhDgXcg diff --git a/elm-stuff/0.19.1/QCM.elmo b/elm-stuff/0.19.1/QCM.elmo index c6fa286cc9dfdeb2c90ffbf39d6da61d3ab1a1ae..edd1e4eace0a6f12e2412345ad327a44667e1161 100644 GIT binary patch delta 2612 zcmbtWO>7%g5Z>|bTd!j~vAt`X)Fg4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$WiT@br%wLD0Kr0J)nD A(*OVf diff --git a/src/QCM.elm b/src/QCM.elm index 5c64d8f..4377e45 100644 --- a/src/QCM.elm +++ b/src/QCM.elm @@ -3,10 +3,11 @@ module QCM exposing (..) import Browser import Parser as P exposing (Parser, (|.), (|=), succeed, symbol, float, spaces) import List as L +import Set import ParserMaths as PM import String as S import Fractions as F exposing (Frac) -import Html exposing (Html, Attribute, button, div, input, text, p) +import Html exposing (Html, Attribute, button, div, textarea, input, text, p) import Html.Attributes exposing (..) import Html.Events exposing (onInput, onClick) @@ -31,14 +32,16 @@ main = -} type alias Model = - { question : String + { variables : String + , question : String , questions : List String } init : Model init = - { question = "" + { variables = "" + , question = "" , questions = [ "" ] } @@ -53,6 +56,7 @@ init = type Msg = Question String + | Variables String | GenererQuestion update : Msg -> Model -> Model @@ -60,13 +64,10 @@ update msg model = case msg of Question nouvelleQuestion -> { model | question = nouvelleQuestion } + Variables nouvellesVariables -> + { model | variables = nouvellesVariables } GenererQuestion -> - { model | questions = [ - case P.run questions model.question of - Ok macro -> voirMacro macro - Err _ -> "Y a un truc qui cloche !" - ] } - + { model | questions = remplacer model.variables model.question } {- @@ -80,9 +81,11 @@ update msg model = view : Model -> Html Msg view model = div [] - <| input [ placeholder "Format de la question", value model.question, onInput Question ] [] + <| textarea [ placeholder "Liste des variables", value model.variables, onInput Variables ] [] + :: textarea [ placeholder "Format de la question", value model.question, onInput Question ] [] :: button [ onClick GenererQuestion ] [ text "Générer les questions" ] - :: ( p [] <| L.map text model.questions ) + :: [ ( p [] <| L.map (\q -> p [] [text q]) model.questions ) ] + {-- :: text ( let expressionParseePotentielle = PM.parseMaths "3+(2/3)^-2/3" @@ -101,6 +104,7 @@ view model = ) ++ L.map text (remplacer [] [Texte "chose"]) ++ L.map text (remplacer [] [Texte "chose"]) + --} {- , [ dl05 [0, 4, 2] 5 ] @@ -130,15 +134,21 @@ view model = , List.concat <| List.map ( mapTwist [3,5,9] ) ( List.map dl05 ( mix [ [0], [2,4,7,8,11,13,16,17], [2,4,7,8,11,13,16,17] ] ) ) -- 192 possibilités OK , d3 -- 512 possibilités OK :: ( List.map primitPoly01 <| mix [ List.range -3 -2 ++ List.range 2 3, List.range -3 -2 ++ List.range 2 3, List.range -3 -2 ++ List.range 2 3, List.range -3 -2 ++ List.range 2 3 ] ) -- 256 possibilités OK +-- mix [ [1,2] , [3,4] , [5,6] ] == [ [1,3,5] , [1,3,6] , [1,4,5] , [1,4,6] , [2,3,5] , ... ] +mix lls = + case lls of + [] -> [] + [] :: llss -> [] + l :: [] -> List.map List.singleton l + (a :: ls) :: llss -> ( List.map ( (::) a ) ( mix llss ) ) ++ mix ( ls :: llss ) -} - {- - ██████ █████ ██████ ███████ ███████ ██████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██████ ███████ ██████ ███████ █████ ██████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██ ██ ██ ██ ██ ███████ ███████ ██ ██ + ██████ █████ ██████ ███████ ███████ ██████ ██████ ██████ ███ ███ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ + ██████ ███████ ██████ ███████ █████ ██████ ██ ██ ██ ██ ████ ██ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ▄▄ ██ ██ ██ ██ ██ + ██ ██ ██ ██ ██ ███████ ███████ ██ ██ ██████ ██████ ██ ██ -} type TexteVariable @@ -180,6 +190,11 @@ expressionVariable |= P.getChompedString ( P.chompUntil "#" ) |. symbol "#" +parserQuestion question = + case P.run questions question of + Ok macro -> macro + Err _ -> [] + questions : Parser Macro questions = P.loop [] questionsBis @@ -193,6 +208,49 @@ questionsBis ls = |> P.map (\_ -> P.Done (List.reverse ls)) ] + +{- + ██████ █████ ██████ ███████ ███████ ██████ ██ ██ █████ ██████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██████ ███████ ██████ ███████ █████ ██████ ██ ██ ███████ ██████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██ ██ ██ ██ ██ ███████ ███████ ██ ██ ████ ██ ██ ██ ██ +-} + +type alias Aremplacer = + { var : String + , vals : List String + } + +parserAremplacer variables = + case P.run aRemplacer variables of + Ok ars -> ars + Err _ -> Aremplacer "" [] + +aRemplacer : Parser Aremplacer +aRemplacer = + succeed Aremplacer + |. P.spaces + |= P.variable + { start = \_ -> True + , inner = Char.isAlpha + , reserved = Set.fromList [] + } + |. P.spaces + |. P.symbol ":" + |= P.sequence + { start = "" + , separator = "," + , end = "" + , spaces = spaces + , item = P.variable + { start = \x -> Char.isDigit x || x == '-' + , inner = Char.isDigit + , reserved = Set.fromList [] + } + , trailing = P.Optional + } + {- ███ ███ ██ ██ ██ ███████ ██ ██ ██████ ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ @@ -201,68 +259,33 @@ questionsBis ls = ██ ██ ██ ██ ██ ███████ ██████ ██ ██ -} --- mix [ [1,2] , [3,4] , [5,6] ] == [ [1,3,5] , [1,3,6] , [1,4,5] , [1,4,6] , [2,3,5] , ... ] -mix lls = - case lls of - [] -> [] - [] :: llss -> [] - l :: [] -> List.map List.singleton l - (a :: ls) :: llss -> ( List.map ( (::) a ) ( mix llss ) ) ++ mix ( ls :: llss ) - -type alias Aremplacer = - { var : String - , vals : List String - } +remplacer : String -> String -> List String +remplacer variables question = + let + ars = + S.lines variables + |> L.map parserAremplacer + macro = + parserQuestion question + in + remplacerLesVariablesDansLaMacro ars macro -remplacer : List Aremplacer -> Macro -> List String -remplacer ars macro = - remplacerBis ars [macro] +remplacerLesVariablesDansLaMacro : List Aremplacer -> Macro -> List String +remplacerLesVariablesDansLaMacro ars macro = + remplacerLesVariablesDansLaMacroBis ars [macro] |> L.map voirMacro -remplacerBis : List Aremplacer -> List Macro -> List Macro -remplacerBis ars macros = +remplacerLesVariablesDansLaMacroBis : List Aremplacer -> List Macro -> List Macro +remplacerLesVariablesDansLaMacroBis ars macros = case ars of [] -> macros ar :: arss -> - L.map (remplacerDansLaMacro ar) macros - |> L.concat - |> remplacerBis arss - -{-- -remplacer ars tvs = - case tvs of - [] -> [""] - Texte chaine :: tvss -> L.map (S.append chaine) <| remplacer ars tvss - Variable chaine :: tvss -> - mix - [ remplacerToutDansLesChaines ars [chaine] - , remplacer ars tvss - ] - |> L.map S.concat ---} - -{-- -remplacerToutDansLesChaines : List Aremplacer -> List String -> List String -remplacerToutDansLesChaines ars chaines = - case ars of - [] -> chaines - ar :: arss -> - L.map (remplacerLaVariableParLesValeursDansLaChaine ar.var ar.vals) chaines + L.map (remplacerLaVariableDansLaMacro ar) macros |> L.concat - |> remplacerToutDansLesChaines arss - {-- - case chaines of - chaine :: chainess -> - remplacerLaVariableParLesValeursDansLaChaine ar.var ar.val chaine - :: - - remplacerDansLeTexteVariable ar t - |> - --} ---} + |> remplacerLesVariablesDansLaMacroBis arss -remplacerDansLaMacro : Aremplacer -> Macro -> List Macro -remplacerDansLaMacro ar macro = +remplacerLaVariableDansLaMacro : Aremplacer -> Macro -> List Macro +remplacerLaVariableDansLaMacro ar macro = let f val = remplacerLaVariableParLaValeurDansLaMacro ar.var val macro in @@ -277,25 +300,6 @@ remplacerLaVariableParLaValeurDansLeTexteVariable var val tv = Texte chaine -> Texte chaine Variable chaine -> Variable <| S.replace var val chaine -{-- -remplacerDansLeTexteVariable : Aremplacer -> TexteVariable -> List String -remplacerDansLeTexteVariable a t = - case t of - Texte tt -> Texte tt - Variable tt -> remplacerLaVariableParLesValeursDansLaChaine a.var a.vals tt ---} - -{-- -remplacerLaVariableParLesValeursDansLaChaine : String -> List String -> String -> List String -remplacerLaVariableParLesValeursDansLaChaine var vals chaine = - case vals of - [] -> [] - val :: valss -> - S.replace var val chaine - :: remplacerLaVariableParLesValeursDansLaChaine var valss chaine ---} - - {- ███████ ██ ██ ██████ ██████ ███████ ███████ ███████ ██ ██████ ███ ██ ███████