Assn3.hs 3.18 KB
Newer Older
Christopher League's avatar
Christopher League committed
1
{-# LANGUAGE FlexibleInstances #-}
2
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
Christopher League's avatar
Christopher League committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE OverloadedStrings #-}
module App.Assn3
  ( handleU2LogicAssnR
  , assn3
  , a3SubmittedBadge
  ) where

import App.Activity
import App.YamlStore
import App.User
import App.Prelude
import App.Foundation
19

Christopher League's avatar
Christopher League committed
20
21
22
23
24
25
assn3 :: Activity
assn3 =
  makeActivity "a3" 60 "2020-03-01 23:59 EST"

a3SubmittedBadge :: Widget
a3SubmittedBadge =
Christopher League's avatar
Christopher League committed
26
  submittedPointsBadge assn3 \_ ->
Christopher League's avatar
Christopher League committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  return False

data A2GivenKey = A2GivenKey
  deriving (Eq, Ord, Show)

instance Key A2GivenKey where
  keyDir = "course"
  keyToFileName A2GivenKey = "assn3.yaml"
  keyFromFileName fn
    | fn == keyToFileName A2GivenKey = Just A2GivenKey
    | otherwise = Nothing

instance YamlEntity A2GivenKey (Map UserId Text)

handleU2LogicAssnR :: Handler Html
handleU2LogicAssnR = do
  uid <- requireAuthId
  exprOpt <- runRo $ (^. at uid) <$> loadY A2GivenKey
  defaultLayout $ do
    setTitle "Assignment 2: Boolean logic"
    toWidget
      [lucius|
.bigger-text {
  font-size: 120%;
}
52
53
54
table.truth td {
  text-align: center;
}
Christopher League's avatar
Christopher League committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|]
    [whamlet|
<div .col-12>
  <p>
    ^{a3SubmittedBadge}
    ^{dueBadge assn3}

  $maybe expr <- exprOpt
    <p .bigger-text .border .border-success .p-2>
        Your Boolean expression is:  
        <span .text-monospace>
        #{expr}
  $nothing
    <div .alert .alert-danger>
      You have not been assigned an expression yet!
      Please ask the instructor to assign one ASAP.

  <p>
    This assignment has two parts. <b>First,</b> write a complete truth
    table for all possible values of the Boolean expression assigned
    to you. Remember the correct order of operations:

    <pre>
      parentheses   ( )
      NOT            '
      AND            ·
      OR             +
      XOR            ⊕

    Your expression uses exactly three variables, so your table should
    have <b>eight</b> rows. You may create your truth table on paper
    and then take a very clear picture of it, or do it directly in a
    document or spreadsheet file.

  <p>
    <b>Second,</b> using Logisim, implement a circuit for your assigned
    Boolean expression. It should have exactly three two-state input
    pins, labeled as A, B, and C. It should have one output pin or
    LED. Test the circuit against your truth table to verify the
    results. If you find a way to implement exactly the same
    calculation with fewer gates, that's fine (but not necessary).
    Save your circuit file (it should have the extension
    <tt>.circ</tt>) and also upload that below.

99
  <p>
Christopher League's avatar
Christopher League committed
100
101
102
    To submit, please just email your files and/or pics to
    <a href="mailto:christopher.league@liu.edu">christopher.league@liu.edu
    using the Subject: <b>CS101 A3</b>
Christopher League's avatar
Christopher League committed
103
|]
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120


  -- <table .table .truth>
  --   <tr>
  --     <th>A
  --     <th>B
  --     <th>C
  --     <th>… other columns …
  --     <th>#{fromMaybe "" exprOpt}
  --   $forall (a,b,c) <- bits
  --     <tr>
  --       <td>#{tshow a}
  --       <td>#{tshow b}
  --       <td>#{tshow c}
  --       <td>
  --       <td>
  --         <input .form-control style="width:3em" type=text size=2>