Skip to content

Commit fb90edf

Browse files
author
callaghan
committed
add exercism exercises
1 parent 24d56b6 commit fb90edf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2409
-1
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# .gitignore
1+
.gitignore
22
*.json
33
.idea

go/annalyns-infiltration/HELP.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Help
2+
3+
## Running the tests
4+
5+
To run the tests run the command `go test` from within the exercise directory.
6+
7+
If the test suite contains benchmarks, you can run these with the `--bench` and `--benchmem`
8+
flags:
9+
10+
go test -v --bench . --benchmem
11+
12+
Keep in mind that each reviewer will run benchmarks on a different machine, with
13+
different specs, so the results from these benchmark tests may vary.
14+
15+
## Submitting your solution
16+
17+
You can submit your solution using the `exercism submit annalyns_infiltration.go` command.
18+
This command will upload your solution to the Exercism website and print the solution page's URL.
19+
20+
It's possible to submit an incomplete solution which allows you to:
21+
22+
- See how others have completed the exercise
23+
- Request help from a mentor
24+
25+
## Need to get help?
26+
27+
If you'd like help solving the exercise, check the following pages:
28+
29+
- The [Go track's documentation](https://exercism.org/docs/tracks/go)
30+
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
31+
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
32+
33+
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
34+
35+
To get help if you're having trouble, you can use one of the following resources:
36+
37+
- [How to Write Go Code](https://golang.org/doc/code.html)
38+
- [Effective Go](https://golang.org/doc/effective_go.html)
39+
- [Go Resources](http://golang.org/help)
40+
- [StackOverflow](http://stackoverflow.com/questions/tagged/go)

go/annalyns-infiltration/HINTS.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Hints
2+
3+
## General
4+
5+
- There are three [boolean operators][logical operators] to work with boolean values.
6+
- Multiple operators can be combined in a single expression.
7+
8+
## 1. Check if a fast attack can be made
9+
10+
- The logical NOT operator (`!`) can be placed before an expression to negate its value.
11+
12+
## 2. Check if the group can be spied upon
13+
14+
- Logical operators are typically used to evaluate whether two or more expressions are true or not true.
15+
16+
## 3. Check if the prisoner can be signaled
17+
18+
- Logical operators execute in the order of their precedence (from highest to lowest): `!`, `&&`, `||`.
19+
- For more details check out the Operator Precedence section on the [official golang documentation][operators] and the [truth table][truth table].
20+
21+
[logical operators]: https://golang.org/ref/spec#Logical_operators
22+
[operators]: https://golang.org/ref/spec#Operators
23+
[truth table]: https://www.digitalocean.com/community/tutorials/understanding-boolean-logic-in-go

go/annalyns-infiltration/README.md

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Annalyn's Infiltration
2+
3+
Welcome to Annalyn's Infiltration on Exercism's Go Track.
4+
If you need help running the tests or submitting your code, check out `HELP.md`.
5+
If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :)
6+
7+
## Introduction
8+
9+
Booleans in Go are represented by the predeclared boolean type `bool`, which values can be either `true` or `false`.
10+
It's a defined type.
11+
12+
```go
13+
var closed bool // boolean variable 'closed' implicitly initialized with 'false'
14+
speeding := true // boolean variable 'speeding' initialized with 'true'
15+
hasError := false // boolean variable 'hasError' initialized with 'false'
16+
```
17+
18+
Go supports three logical operators that can evaluate expressions down to Boolean values, returning either `true` or `false`.
19+
20+
| Operator | What it means |
21+
| ----------- | --------------------------------------------- |
22+
| `&&` (and) | It is true if both statements are true. |
23+
| `\|\|` (or) | It is true if at least one statement is true. |
24+
| `!` (not) | It is true only if the statement is false. |
25+
26+
## Instructions
27+
28+
In this exercise, you'll be implementing the quest logic for a new RPG game a friend is developing. The game's main character is Annalyn, a brave girl with a fierce and loyal pet dog. Unfortunately, disaster strikes, as her best friend was kidnapped while searching for berries in the forest. Annalyn will try to find and free her best friend, optionally taking her dog with her on this quest.
29+
30+
After some time spent following her best friend's trail, she finds the camp in which her best friend is imprisoned. It turns out there are two kidnappers: a mighty knight and a cunning archer.
31+
32+
Having found the kidnappers, Annalyn considers which of the following actions she can engage in:
33+
34+
- _Fast attack_: a fast attack can be made if the knight is sleeping, as it takes time for him to get his armor on, so he will be vulnerable.
35+
- _Spy_: the group can be spied upon if at least one of them is awake. Otherwise, spying is a waste of time.
36+
- _Signal prisoner_: the prisoner can be signaled using bird sounds if the prisoner is awake and the archer is sleeping, as archers are trained in bird signaling so they could intercept the message.
37+
- _Free prisoner_: Annalyn can try sneaking into the camp to free the prisoner.
38+
This is a risky thing to do and can only succeed in one of two ways:
39+
- If Annalyn has her pet dog with her she can rescue the prisoner if the archer is asleep.
40+
The knight is scared of the dog and the archer will not have time to get ready before Annalyn and the prisoner can escape.
41+
- If Annalyn does not have her dog then she and the prisoner must be very sneaky!
42+
Annalyn can free the prisoner if the prisoner is awake and the knight and archer are both sleeping, but if the prisoner is sleeping they can't be rescued: the prisoner would be startled by Annalyn's sudden appearance and wake up the knight and archer.
43+
44+
You have four tasks: to implement the logic for determining if the above actions are available based on the state of the three characters found in the forest and whether Annalyn's pet dog is present or not.
45+
46+
## 1. Check if a fast attack can be made
47+
48+
Define the `CanFastAttack()` function that takes a boolean value that indicates if the knight is awake. This function returns `true` if a fast attack can be made based on the state of the knight. Otherwise, returns `false`:
49+
50+
```go
51+
var knightIsAwake = true
52+
fmt.Println(CanFastAttack(knightIsAwake))
53+
// Output: false
54+
```
55+
56+
## 2. Check if the group can be spied upon
57+
58+
Define the `CanSpy()` function that takes three boolean values, indicating if the knight, archer and the prisoner, respectively, are awake. The function returns `true` if the group can be spied upon, based on the state of the three characters. Otherwise, returns `false`:
59+
60+
```go
61+
var knightIsAwake = false
62+
var archerIsAwake = true
63+
var prisonerIsAwake = false
64+
fmt.Println(CanSpy(knightIsAwake, archerIsAwake, prisonerIsAwake))
65+
// Output: true
66+
```
67+
68+
## 3. Check if the prisoner can be signaled
69+
70+
Define the `CanSignalPrisoner()` function that takes two boolean values, indicating if the archer and the prisoner, respectively, are awake. The function returns `true` if the prisoner can be signaled, based on the state of the two characters. Otherwise, returns `false`:
71+
72+
```go
73+
var archerIsAwake = false
74+
var prisonerIsAwake = true
75+
fmt.Println(CanSignalPrisoner(archerIsAwake, prisonerIsAwake))
76+
// Output: true
77+
```
78+
79+
## 4. Check if the prisoner can be freed
80+
81+
Define the `CanFreePrisoner()` function that takes four boolean values. The first three parameters indicate if the knight, archer and the prisoner, respectively, are awake. The last parameter indicates if Annalyn's pet dog is present. The function returns `true` if the prisoner can be freed based on the state of the three characters and Annalyn's pet dog presence. Otherwise, it returns `false`:
82+
83+
```go
84+
var knightIsAwake = false
85+
var archerIsAwake = true
86+
var prisonerIsAwake = false
87+
var petDogIsPresent = false
88+
fmt.Println(CanFreePrisoner(knightIsAwake, archerIsAwake, prisonerIsAwake, petDogIsPresent))
89+
// Output: false
90+
```
91+
92+
## Source
93+
94+
### Created by
95+
96+
- @oanaOM
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package annalyn
2+
3+
// CanFastAttack can be executed only when the knight is sleeping.
4+
func CanFastAttack(knightIsAwake bool) bool {
5+
panic("Please implement the CanFastAttack() function")
6+
}
7+
8+
// CanSpy can be executed if at least one of the characters is awake.
9+
func CanSpy(knightIsAwake, archerIsAwake, prisonerIsAwake bool) bool {
10+
panic("Please implement the CanSpy() function")
11+
}
12+
13+
// CanSignalPrisoner can be executed if the prisoner is awake and the archer is sleeping.
14+
func CanSignalPrisoner(archerIsAwake, prisonerIsAwake bool) bool {
15+
panic("Please implement the CanSignalPrisoner() function")
16+
}
17+
18+
// CanFreePrisoner can be executed if the prisoner is awake and the other 2 characters are asleep
19+
// or if Annalyn's pet dog is with her and the archer is sleeping.
20+
func CanFreePrisoner(knightIsAwake, archerIsAwake, prisonerIsAwake, petDogIsPresent bool) bool {
21+
panic("Please implement the CanFreePrisoner() function")
22+
}

0 commit comments

Comments
 (0)