summaryrefslogtreecommitdiff
path: root/assignments/3-solution.md
blob: b0a72a8d0f7f323394429c91fe993d762a750836 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
52
53
54
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
99
100
101
102
103
104
105
106
# COMP-200: Intro to Computer Systems
## Assignment 3
### mo khan - 3431709

Choose ONE exercise each from Chapters 6, 7, and 8

Chapter 6:

> 13. Write a complete assembly language program (including all necessary pseudo-ops) that reads in a series of integers, one at a time, and outputs the largest and smallest values. The input will consist of a list of integer values

main.c
```c
!include assignments/3/main.c
```

main.s
```assembly
!include assignments/3/main.s
```

Chapter 7:

> 16. Given the following diagram, where the numbers represent the time delays across a link:

>  a. How many simple paths (those that do not repeat a node) are there from node A to G?
  ```plaintext
    A<->B: 5
    A<->D: 6
    A<->F: 3
    B<->C: 4
    B<->E: 2
    C<->D: 3
    C<->E: 1
    C<->G: 2
    D<->E: 1
    F<->G: 8
  ```

  There are 6 simple paths

  ```plaintext
  | Path        |
  | ----        |
  | a,b,c,g     |
  | a,b,e,c,g   |
  | a,d,c,g     |
  | a,d,e,b,c,g |
  | a,d,e,c,g   |
  | a,f,g       |
  ```

>  b. What is the shortest path from node A to node G? What is the overall delay?

  The shortest path has a distance of 10. The overall delay is 11.

  ```plaintext
  | Path        | Total Distance |
  | ----        | -------------- |
  | a,b,c,g     | 5+4+2 = 11     |
  | a,b,e,c,g   | 5+2+1+2 = 10   |
  | a,d,c,g     | 6+3+2 = 11     |
  | a,d,e,b,c,g | 6+1+2+4+2 = 15 |
  | a,d,e,c,g   | 6+1+1+2 = 10   |
  | a,f,g       | 3+8 = 11       |
  ```

>  c. If node E fails, does that change the shortest path? If so, what is the new shortest path?

  Yes, if node E fails then there are 3 simple paths remaining with the shortest path having a distance of 11.

  ```plaintext
    A<->B: 5
    A<->D: 6
    A<->F: 3
    B<->C: 4
    C<->D: 3
    C<->G: 2
    F<->G: 8
  ```

  ```plaintext
  | Path        | Total Distance |
  | ----        | -------------- |
  | a,b,c,g     | 5+4+2 = 11     |
  | a,d,c,g     | 6+3+2 = 11     |
  | a,f,g       | 3+8 = 11       |
  ```

Chapter 8:

> 9. Using a Caesar cipher with s = 5, decode the received message RTAJ TZY FY IF

```plaintext
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |

Key: s = 5

| F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E |

| Ciphertext | RTAJ TZY FY IFBS |
| Plaintext  | MOVE OUT AT DAWN |
```

```ruby
!include assignments/3/caesar.rb
```