Skip to content

Commit 0312378

Browse files
committed
✨ (concepts) Add concept exercise annalyns-infiltration
This concept is inspired from the same in csharp track
1 parent 399488b commit 0312378

File tree

11 files changed

+603
-0
lines changed

11 files changed

+603
-0
lines changed

config.json

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
},
3636
"exercises": {
3737
"concept": [
38+
{
39+
"slug": "annalyns-infiltration",
40+
"name": "Annalyn's Infiltration",
41+
"uuid": "897fa2ea-c29c-4d4e-9469-ff661a9b838a",
42+
"difficulty": 1,
43+
"concepts": [
44+
"booleans"
45+
],
46+
"prerequisites": [],
47+
"status": "active"
48+
},
3849
{
3950
"slug": "lucians-luscious-lasagna",
4051
"uuid": "29a2d3bd-eec8-454d-9dba-4b2d7d071925",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Hints
2+
3+
## General
4+
5+
- There are three boolean operators<sup>[1] [2]</sup> to work with boolean values.
6+
- Multiple operators can be combined in a single expression.
7+
8+
## 2. Check if a fast attack can be made
9+
10+
- The boolean operators<sup>[1] [2]</sup> can also be applied to boolean parameters.
11+
12+
[1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#lazy-boolean-operators
13+
[2]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#negation-operators
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Instructions
2+
3+
In this exercise, you'll be implementing the quest logic for a new RPG game a friend is developing.
4+
5+
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.
6+
7+
Annalyn will try to find and free her best friend, optionally taking her dog with her on this quest.
8+
9+
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.
10+
11+
Having found the kidnappers, Annalyn considers which of the following actions she can engage in:
12+
13+
- _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.
14+
- _Spy_: the group can be spied upon if at least one of them is awake. Otherwise, spying is a waste of time.
15+
- _Signal prisoner_: the prisoner can be signalled 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.
16+
- _Free prisoner_: Annalyn can try sneaking into the camp to free the prisoner.
17+
This is a risky thing to do and can only succeed in one of two ways:
18+
- If Annalyn has her pet dog with her she can rescue the prisoner if the archer is asleep.
19+
The knight is scared of the dog and the archer will not have time to get ready before Annalyn and the prisoner can escape.
20+
- If Annalyn does not have her dog then she and the prisoner must be very sneaky!
21+
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.
22+
23+
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.
24+
25+
## 1. Check if a fast attack can be made
26+
27+
Implement the `can_fast_attack()` 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`:
28+
29+
```rust
30+
let knight_is_awake = true;
31+
can_fast_attack(knight_is_awake);
32+
// => false
33+
```
34+
35+
## 2. Check if the group can be spied upon
36+
37+
Implement the `can_spy()` 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`:
38+
39+
```rust
40+
let knight_is_awake = false;
41+
let archer_is_awake = true;
42+
let prisoner_is_awake = false;
43+
can_spy(knight_is_awake, archer_is_awake, prisoner_is_awake);
44+
// => true
45+
```
46+
47+
## 3. Check if the prisoner can be signalled
48+
49+
Implement the `can_signal_prisoner()` 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 signalled, based on the state of the two characters. Otherwise, returns `false`:
50+
51+
```rust
52+
let archer_is_awake = false;
53+
let prisoner_is_awake = true;
54+
can_signal_prisoner(archer_is_awake, prisoner_is_awake);
55+
// => true
56+
```
57+
58+
## 4. Check if the prisoner can be freed
59+
60+
Implement the `can_free_prisoner()` 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`:
61+
62+
```rust
63+
let knight_is_awake = false;
64+
let archer_is_awake = true;
65+
let prisoner_is_awake = false;
66+
let pet_dog_is_present = false;
67+
can_free_prisoner(knight_is_awake, archer_is_awake, prisoner_is_awake, pet_dog_is_present);
68+
// => false
69+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Introduction
2+
3+
## Booleans
4+
5+
[Booleans in Rust][booleans-rust-book] are represented by the `bool` type, which values can be either `true` or `false`.
6+
7+
Rust supports three boolean operators: `!` (NOT), `&&` (AND), and `||` (OR).
8+
9+
10+
[booleans-rust-book]:
11+
https://doc.rust-lang.org/book/ch03-02-data-types.html#the-boolean-type
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
/target/
4+
**/*.rs.bk
5+
6+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7+
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
8+
Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"forked_from": [
3+
"fsharp/annalyns-infiltration"
4+
],
5+
"blurb": "Learn about booleans while helping Annalyn rescue her friend.",
6+
"authors": [
7+
"devkabiir"
8+
],
9+
"contributors": [],
10+
"files": {
11+
"solution": [
12+
"src/lib.rs",
13+
"Cargo.toml"
14+
],
15+
"test": [
16+
"tests/annalyns-infiltration.rs"
17+
],
18+
"exemplar": [
19+
".meta/exemplar.rs"
20+
]
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Design
2+
3+
## Learning objectives
4+
5+
- Know of the existence of the `bool` type and its two values.
6+
- Know about boolean operators and how to build logical expressions with them.
7+
- Know of the boolean operator precedence rules.
8+
9+
## Out of scope
10+
11+
- Pattern matching on booleans.
12+
13+
## Concepts
14+
15+
- `booleans`: know of the existence of the `bool` type and its two values; know about boolean operators and how to build logical expressions with them; know of the boolean operator precedence rules.
16+
17+
## Prerequisites
18+
19+
This exercise's prerequisites Concepts are:
20+
21+
- none
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pub fn can_fast_attack(knight_is_awake: bool) -> bool {
2+
return !knight_is_awake;
3+
}
4+
5+
pub fn can_spy(knight_is_awake: bool, archer_is_awake: bool, prisoner_is_awake: bool) -> bool {
6+
return knight_is_awake || archer_is_awake || prisoner_is_awake;
7+
}
8+
9+
pub fn can_signal_prisoner(archer_is_awake: bool, prisoner_is_awake: bool) -> bool {
10+
return !archer_is_awake && prisoner_is_awake;
11+
}
12+
13+
pub fn can_free_prisoner(
14+
knight_is_awake: bool,
15+
archer_is_awake: bool,
16+
prisoner_is_awake: bool,
17+
pet_dog_is_present: bool,
18+
) -> bool {
19+
return !knight_is_awake && !archer_is_awake && prisoner_is_awake
20+
|| !archer_is_awake && pet_dog_is_present;
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
edition = "2021"
3+
name = "annalyns_infiltration"
4+
version = "1.0.0"
5+
6+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pub fn can_fast_attack(knight_is_awake: bool) -> bool {
2+
return todo!("Implement can_fast_attack");
3+
}
4+
5+
pub fn can_spy(knight_is_awake: bool, archer_is_awake: bool, prisoner_is_awake: bool) -> bool {
6+
return todo!("Implement can_spy");
7+
}
8+
9+
pub fn can_signal_prisoner(archer_is_awake: bool, prisoner_is_awake: bool) -> bool {
10+
return todo!("Implement can_signal_prisoner");
11+
}
12+
13+
pub fn can_free_prisoner(
14+
knight_is_awake: bool,
15+
archer_is_awake: bool,
16+
prisoner_is_awake: bool,
17+
pet_dog_is_present: bool,
18+
) -> bool {
19+
return todo!("Implement can_free_prisoner");
20+
}

0 commit comments

Comments
 (0)