@ -3,10 +3,11 @@ module QCM exposing (..)
import Browser
import Browser
import Parser as P exposing ( Parser , ( | . ) , ( | = ) , succeed , symbol , float , spaces )
import Parser as P exposing ( Parser , ( | . ) , ( | = ) , succeed , symbol , float , spaces )
import List as L
import List as L
import Set
import ParserMaths as PM
import ParserMaths as PM
import String as S
import String as S
import Fractions as F exposing ( Frac )
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.Attributes exposing (..)
import Html.Events exposing ( onInput , onClick )
import Html.Events exposing ( onInput , onClick )
@ -31,14 +32,16 @@ main =
- }
- }
type alias Model =
type alias Model =
{ question : String
{ variables : String
, question : String
, questions : List String
, questions : List String
}
}
init : Model
init : Model
init =
init =
{ question = " "
{ variables = " "
, question = " "
, questions = [ " " ]
, questions = [ " " ]
}
}
@ -53,6 +56,7 @@ init =
type Msg
type Msg
= Question String
= Question String
| Variables String
| GenererQuestion
| GenererQuestion
update : Msg -> Model -> Model
update : Msg -> Model -> Model
@ -60,13 +64,10 @@ update msg model =
case msg of
case msg of
Question nouvelleQuestion ->
Question nouvelleQuestion ->
{ model | question = nouvelleQuestion }
{ model | question = nouvelleQuestion }
Variables nouvellesVariables ->
{ model | variables = nouvellesVariables }
GenererQuestion ->
GenererQuestion ->
{ model | questions = [
{ model | questions = remplacer model . variables model . question }
case P . run questions model . question of
Ok macro -> voirMacro macro
Err _ -> " Y a u n t r u c q u i c l o c h e ! "
] }
{-
{-
@ -80,9 +81,11 @@ update msg model =
view : Model -> Html Msg
view : Model -> Html Msg
view model =
view model =
div [ ]
div [ ]
<| input [ placeholder " F o r m a t d e l a q u e s t i o n " , value model . question , onInput Question ] [ ]
<| textarea [ placeholder " L i s t e d e s v a r i a b l e s " , value model . variables , onInput Variables ] [ ]
:: textarea [ placeholder " F o r m a t d e l a q u e s t i o n " , value model . question , onInput Question ] [ ]
:: button [ onClick GenererQuestion ] [ text " G é n é r e r l e s q u e s t i o n s " ]
:: button [ onClick GenererQuestion ] [ text " G é n é r e r l e s q u e s t i o n s " ]
:: ( p [ ] <| L . map text model . questions )
:: [ ( p [ ] <| L . map ( \ q -> p [ ] [ text q ] ) model . questions ) ]
{- -
:: text
:: text
(
(
let expressionParseePotentielle = PM . parseMaths " 3 + ( 2 / 3 ) ^ - 2 / 3 "
let expressionParseePotentielle = PM . parseMaths " 3 + ( 2 / 3 ) ^ - 2 / 3 "
@ -101,6 +104,7 @@ view model =
)
)
++ L . map text ( remplacer [ ] [ Texte " c h o s e " ] )
++ L . map text ( remplacer [ ] [ Texte " c h o s e " ] )
++ L . map text ( remplacer [ ] [ Texte " c h o s e " ] )
++ L . map text ( remplacer [ ] [ Texte " c h o s e " ] )
--}
{-
{-
, [ dl 05 [ 0 , 4 , 2 ] 5 ]
, [ dl 05 [ 0 , 4 , 2 ] 5 ]
@ -130,15 +134,21 @@ view model =
, List . concat <| List . map ( mapTwist [ 3 , 5 , 9 ] ) ( List . map dl 05 ( mix [ [ 0 ] , [ 2 , 4 , 7 , 8 , 11 , 13 , 16 , 17 ] , [ 2 , 4 , 7 , 8 , 11 , 13 , 16 , 17 ] ] ) ) -- 192 possibilités OK
, List . concat <| List . map ( mapTwist [ 3 , 5 , 9 ] ) ( List . map dl 05 ( mix [ [ 0 ] , [ 2 , 4 , 7 , 8 , 11 , 13 , 16 , 17 ] , [ 2 , 4 , 7 , 8 , 11 , 13 , 16 , 17 ] ] ) ) -- 192 possibilités OK
, d 3 -- 512 possibilités OK
, d 3 -- 512 possibilités OK
:: ( List . map primitPoly 01 <| 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
:: ( List . map primitPoly 01 <| 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
type TexteVariable
@ -180,6 +190,11 @@ expressionVariable
| = P . getChompedString ( P . chompUntil " # " )
| = P . getChompedString ( P . chompUntil " # " )
| . symbol " # "
| . symbol " # "
parserQuestion question =
case P . run questions question of
Ok macro -> macro
Err _ -> [ ]
questions : Parser Macro
questions : Parser Macro
questions =
questions =
P . loop [ ] questionsBis
P . loop [ ] questionsBis
@ -193,6 +208,49 @@ questionsBis ls =
|> P . map ( \ _ -> P . Done ( List . reverse 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] , ... ]
remplacer : String -> String -> List String
mix lls =
remplacer variables question =
case lls of
let
[ ] -> [ ]
ars =
[ ] :: llss -> [ ]
S . lines variables
l :: [ ] -> List . map List . singleton l
|> L . map parserAremplacer
( a :: ls ) :: llss -> ( List . map ( (::) a ) ( mix llss ) ) ++ mix ( ls :: llss )
macro =
parserQuestion question
type alias Aremplacer =
in
{ var : String
remplacerLesVariablesDansLaMacro ars macro
, vals : List String
}
remplacer : List Aremplacer -> Macro -> List String
remplacerLesVariablesDansLaMacro : List Aremplacer -> Macro -> List String
remplacer ars macro =
remplacerLesVariablesDansLaMacro ars macro =
remplacerBis ars [ macro ]
remplacerLesVariablesDansLaMacro Bis ars [ macro ]
|> L . map voirMacro
|> L . map voirMacro
remplacerBis : List Aremplacer -> List Macro -> List Macro
remplacerLesVariablesDansLaMacro Bis : List Aremplacer -> List Macro -> List Macro
remplacerBis ars macros =
remplacerLesVariablesDansLaMacro Bis ars macros =
case ars of
case ars of
[ ] -> macros
[ ] -> macros
ar :: arss ->
ar :: arss ->
L . map ( remplacerDansLaMacro ar ) macros
L . map ( remplacerLaVariableDansLaMacro 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 . concat
|> L . concat
|> remplacerToutDansLesChaines arss
|> remplacerLesVariablesDansLaMacroBis arss
{- -
case chaines of
chaine :: chainess ->
remplacerLaVariableParLesValeursDansLaChaine ar . var ar . val chaine
::
remplacerDansLeTexteVariable ar t
|>
--}
--}
remplacerDansLaMacro : Aremplacer -> Macro -> List Macro
remplacerLaVariableDansLaMacro : Aremplacer -> Macro -> List Macro
remplacerDansLaMacro ar macro =
remplacerLaVariableDansLaMacro ar macro =
let
let
f val = remplacerLaVariableParLaValeurDansLaMacro ar . var val macro
f val = remplacerLaVariableParLaValeurDansLaMacro ar . var val macro
in
in
@ -277,25 +300,6 @@ remplacerLaVariableParLaValeurDansLeTexteVariable var val tv =
Texte chaine -> Texte chaine
Texte chaine -> Texte chaine
Variable chaine -> Variable <| S . replace var val 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
--}
{-
{-
█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █
█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █