~willvaughn/kata

902abcab68cc3253141f6c6cf7a6cc94d9fcb39a — William Vaughn 1 year, 5 months ago b54f879
exercism annalyns-infiltration download
A exercism/clojure/annalyns-infiltration/.exercism/config.json => exercism/clojure/annalyns-infiltration/.exercism/config.json +20 -0
@@ 0,0 1,20 @@
{
  "authors": [
    "porkostomus"
  ],
  "files": {
    "solution": [
      "src/annalyns_infiltration.clj"
    ],
    "test": [
      "test/annalyns_infiltration_test.clj"
    ],
    "exemplar": [
      ".meta/exemplar.clj"
    ]
  },
  "forked_from": [
    "fsharp/annalyns-infiltration"
  ],
  "blurb": "Learn about booleans while helping Annalyn rescue her friend"
}

A exercism/clojure/annalyns-infiltration/.exercism/metadata.json => exercism/clojure/annalyns-infiltration/.exercism/metadata.json +1 -0
@@ 0,0 1,1 @@
{"track":"clojure","exercise":"annalyns-infiltration","id":"d11c78fc50ec455383ae057e07c230c0","url":"https://exercism.org/tracks/clojure/exercises/annalyns-infiltration","handle":"willvaughn","is_requester":true,"auto_approve":false}
\ No newline at end of file

A exercism/clojure/annalyns-infiltration/HELP.md => exercism/clojure/annalyns-infiltration/HELP.md +75 -0
@@ 0,0 1,75 @@
# Help

## Running the tests

## Clojure CLI

The Clojure exercises on Exercism ship with a `deps.edn` file with a `:test` alias to invoke the [cognitect-labs test-runner](https://github.com/cognitect-labs/test-runner):

``` bash
$ clj -X:test
```

## Leiningen

Leiningen can also be used to run the exercise's test by running the following command from the exercise's directory:

```bash
lein test
```

## REPL

To use the REPL to run the exercise's test, run the following command from the exercise's directory:

```bash
$ clj
```

-or-

```bash
$ lein repl
```

Then `require` the exercise's test namespace and the Clojure test namespace):

```clojure
;; replace <exercise> with the exercise's name
=> (require '<exercise>-test)
```

Then call `run-tests` on `<exercise>-test`:

```clojure
;; replace <exercise> with the exercise's name
=> (clojure.test/run-tests '<exercise>-test)
```

## Submitting your solution

You can submit your solution using the `exercism submit src/annalyns_infiltration.clj` command.
This command will upload your solution to the Exercism website and print the solution page's URL.

It's possible to submit an incomplete solution which allows you to:

- See how others have completed the exercise
- Request help from a mentor

## Need to get help?

If you'd like help solving the exercise, check the following pages:

- The [Clojure track's documentation](https://exercism.org/docs/tracks/clojure)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)

Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.

To get help if you're having trouble, you can use one of the following resources:

- [Ask Clojure](https://ask.clojure.org/) Official forum for Clojure Q & A.
- [ClojureDocs](https://clojuredocs.org) A repository of language references and examples by function or keyword.
- [/r/clojure](https://www.reddit.com/r/clojure) is the Clojure subreddit.
- [StackOverflow](http://stackoverflow.com/questions/tagged/clojure) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
- [Clojureverse](https://clojureverse.org/) Friendly and inclusive Clojure(Script) Community
\ No newline at end of file

A exercism/clojure/annalyns-infiltration/HINTS.md => exercism/clojure/annalyns-infiltration/HINTS.md +21 -0
@@ 0,0 1,21 @@
# Hints

## 1. Check if a fast attack can be made

We need to check if the knight is awake and _invert_ its truth value. This can be done with the [`not`][not] function.

## 2. Check if the group can be spied upon

We want the function to return `true` if _any_ of the supplied predicates are true. This can be done using the [`or`][or] function.

## 3. Check if the prisoner can be signalled

We want to return `true` if and only if _all_ of the supplied predicates are truthy. This can be done with the [`and`][and] function.

## 4. Check if the prisoner can be freed

Here, we need to combine the three basic logical operators, [`and`][and], [`or`][or], and [`not`][not].

[not]: https://clojuredocs.org/clojure.core/not
[or]: https://clojuredocs.org/clojure.core/or
[and]: https://clojuredocs.org/clojure.core/and
\ No newline at end of file

A exercism/clojure/annalyns-infiltration/README.md => exercism/clojure/annalyns-infiltration/README.md +89 -0
@@ 0,0 1,89 @@
# Annalyn's Infiltration

Welcome to Annalyn's Infiltration on Exercism's Clojure Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :)

## Introduction

Booleans in Clojure are represented by `true` or `false`.

Predicate functions (functions which return a boolean) will typically end with a quesion mark (`?`), but this is by convention only.

The core library includes functions for logical operators such as `not`, `and`, and `or`.

## Instructions

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.

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.

Having found the kidnappers, Annalyn considers which of the following actions she can engage in:

- 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.
- Spy: the group can be spied upon if at least one of them is awake. Otherwise, spying is a waste of time.
- 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.
- _Free prisoner_: Annalyn can try sneaking into the camp to free the prisoner.
  This is a risky thing to do and can only succeed in one of two ways:
  - If Annalyn has her pet dog with her she can rescue the prisoner if the archer is asleep.
    The knight is scared of the dog and the archer will not have time to get ready before Annalyn and the prisoner can escape.
  - If Annalyn does not have her dog then she and the prisoner must be very sneaky!
    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.

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.

## 1. Check if a fast attack can be made

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`:

```clojure
(def knight-awake? true)

(can-fast-attack? knight-awake?)
;;=> false
```

## 2. Check if the group can be spied upon

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`:

```clojure
(def knight-awake? false)
(def archer-awake? true)
(def prisoner-awake? false)

(can-spy? knight-awake? archer-awake? prisoner-awake?)
;;=> true
```

## 3. Check if the prisoner can be signalled

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`:

```clojure
(def archer-awake? false)
(def prisoner-awake? true)

(can-signal-prisoner? archer-awake? prisoner-awake?)
;;=> true
```

## 4. Check if the prisoner can be freed

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`:

```clojure
(def knight-awake? false)
(def archer-awake? true)
(def prisoner-awake? false)
(def dog-present? false)

(can-free-prisoner? knight-awake? archer-awake? prisoner-awake? dog-present?)
;;=> false
```

## Source

### Created by

- @porkostomus
\ No newline at end of file

A exercism/clojure/annalyns-infiltration/deps.edn => exercism/clojure/annalyns-infiltration/deps.edn +6 -0
@@ 0,0 1,6 @@
{:aliases {:test {:extra-paths ["test"]
                  :extra-deps {io.github.cognitect-labs/test-runner
                               {:git/url "https://github.com/cognitect-labs/test-runner.git"
                                :sha "705ad25bbf0228b1c38d0244a36001c2987d7337"}}
                  :main-opts ["-m" "cognitect.test-runner"]
                  :exec-fn cognitect.test-runner.api/test}}}
\ No newline at end of file

A exercism/clojure/annalyns-infiltration/project.clj => exercism/clojure/annalyns-infiltration/project.clj +4 -0
@@ 0,0 1,4 @@
(defproject annalyns-infiltration "0.1.0-SNAPSHOT"
  :description "annalyns-infiltration exercise."
  :url "https://github.com/exercism/clojure/tree/main/exercises/concept/annalyns-infiltration"
  :dependencies [[org.clojure/clojure "1.10.0"]])
\ No newline at end of file

A exercism/clojure/annalyns-infiltration/src/annalyns_infiltration.clj => exercism/clojure/annalyns-infiltration/src/annalyns_infiltration.clj +21 -0
@@ 0,0 1,21 @@
(ns annalyns-infiltration)

(defn can-fast-attack?
  "Returns true if a fast-attack can be made, false otherwise."
  [knight-awake?]
  )

(defn can-spy?
  "Returns true if the kidnappers can be spied upon, false otherwise."
  [knight-awake? archer-awake? prisoner-awake?]
  )

(defn can-signal-prisoner?
  "Returns true if the prisoner can be signalled, false otherwise."
  [archer-awake? prisoner-awake?]
  )

(defn can-free-prisoner?
  "Returns true if prisoner can be freed, false otherwise."
  [knight-awake? archer-awake? prisoner-awake? dog-present?]
  )

A exercism/clojure/annalyns-infiltration/test/annalyns_infiltration_test.clj => exercism/clojure/annalyns-infiltration/test/annalyns_infiltration_test.clj +123 -0
@@ 0,0 1,123 @@
(ns annalyns-infiltration-test
  (:require [clojure.test :refer [deftest testing is]]
            annalyns-infiltration))

(deftest fast-attack-awake-test
  (testing "Fast attack if knight is awake"
    (is (= false (annalyns-infiltration/can-fast-attack? true)))))

(deftest fast-attack-asleep-test
  (testing "Fast attack if knight is sleeping"
    (is (= true (annalyns-infiltration/can-fast-attack? false)))))

(deftest spy-everyone-sleeping-test
  (testing "Cannot spy if everyone is sleeping"
    (is (= false (annalyns-infiltration/can-spy? false false false)))))

(deftest spy-but-knight-sleeping-test
  (testing "Can spy if everyone but knight is sleeping"
    (is (= true (annalyns-infiltration/can-spy? true false false)))))

(deftest spy-but-archer-sleeping-test
  (testing "Can spy if everyone but archer is sleeping"
    (is (= true (annalyns-infiltration/can-spy? false true false)))))

(deftest spy-but-prisoner-sleeping-test
  (testing "Can spy if everyone but prisoner is sleeping"
    (is (= true (annalyns-infiltration/can-spy? false false true)))))

(deftest spy-only-knight-sleeping-test
  (testing "Can spy if only knight is sleeping"
    (is (= true (annalyns-infiltration/can-spy? false true true)))))

(deftest spy-only-archer-sleeping-test
  (testing "Can spy if only archer is sleeping"
    (is (= true (annalyns-infiltration/can-spy? true false true)))))

(deftest spy-only-prisoner-sleeping-test
  (testing "Can spy if only prisoner is sleeping"
    (is (= true (annalyns-infiltration/can-spy? true true false)))))

(deftest spy-everyone-awake-test
  (testing "Can spy if everyone is awake"
    (is (= true (annalyns-infiltration/can-spy? true true true)))))

(deftest signal-prisoner-archer-sleeping-prisoner-awake-test
  (testing "Can signal prisoner if archer is sleeping and prisoner is awake"
    (is (= true (annalyns-infiltration/can-signal-prisoner? false true)))))

(deftest signal-prisoner-archer-awake-prisoner-sleeping-test
  (testing "Cannot signal prisoner if archer is awake and prisoner is sleeping"
      (is (= false (annalyns-infiltration/can-signal-prisoner? true false)))))

(deftest signal-prisoner-both-sleeping-test
  (testing "Cannot signal prisoner if archer and prisoner are both sleeping"
      (is (= false (annalyns-infiltration/can-signal-prisoner? false false)))))

(deftest signal-prisoner-both-awake-test
  (testing "Cannot signal prisoner if archer and prisoner are both awake"
      (is (= false (annalyns-infiltration/can-signal-prisoner? true true)))))

(deftest release-prisoner-everyone-awake-dog-present-test
  (testing "Cannot release prisoner if everyone is awake and pet dog is present"
      (is (= false (annalyns-infiltration/can-free-prisoner? true true true true)))))

(deftest release-prisoner-everyone-awake-dog-absent-test
    (testing "Cannot release prisoner if everyone is awake and pet dog is absent"
      (is (= false (annalyns-infiltration/can-free-prisoner? true true true false)))))
    
(deftest release-prisoner-everyone-asleep-dog-absent-test
    (testing "Cannot release prisoner if everyone is asleep and pet dog is absent"
      (is (= false (annalyns-infiltration/can-free-prisoner? false false false false)))))

(deftest release-prisoner-archer-awake-dog-present-test
    (testing "Cannot release prisoner if only archer is awake and pet dog is present"
      (is (= false (annalyns-infiltration/can-free-prisoner? false true false true)))))

(deftest release-prisoner-archer-awake-dog-absent-test
    (testing "Cannot release prisoner if only archer is awake and pet dog is absent"
      (is (= false (annalyns-infiltration/can-free-prisoner? false true false false)))))

(deftest release-prisoner-knight-awake-dog-absent-test
    (testing "Cannot release prisoner if only knight is awake and pet dog is absent"
      (is (= false (annalyns-infiltration/can-free-prisoner? true false false false)))))

(deftest release-prisoner-knight-awake-dog-present-test
    (testing "Cannot release prisoner if only knight is asleep and pet dog is present"
      (is (= false (annalyns-infiltration/can-free-prisoner? false true true true)))))

(deftest release-prisoner-knight-asleep-dog-absent-test
    (testing "Cannot release prisoner if only knight is asleep and pet dog is absent"
      (is (= false (annalyns-infiltration/can-free-prisoner? false true true false)))))

(deftest release-prisoner-archer-asleep-dog-absent-test
    (testing "Cannot release prisoner if only archer is asleep and pet dog is absent"
      (is (= false (annalyns-infiltration/can-free-prisoner? true false true false)))))

(deftest release-prisoner-prisoner-asleep-dog-present-test
    (testing "Cannot release prisoner if only prisoner is asleep and pet dog is present"
      (is (= false (annalyns-infiltration/can-free-prisoner? true true false true)))))

(deftest release-prisoner-prisoner-asleep-dog-absent-test
    (testing "Cannot release prisoner if only prisoner is asleep and pet dog is absent"
      (is (= false (annalyns-infiltration/can-free-prisoner? true true false false)))))

(deftest release-prisoner-everyone-asleep-dog-present-test
    (testing "Can release prisoner if everyone is asleep and pet dog is present"
      (is (= true (annalyns-infiltration/can-free-prisoner? false false false true)))))

(deftest release-prisoner-prisoner-awake-dog-present-test
    (testing "Can release prisoner if only prisoner is awake and pet dog is present"
      (is (= true (annalyns-infiltration/can-free-prisoner? false false true true)))))

(deftest release-prisoner-prisoner-awake-dog-absent-test
    (testing "Can release prisoner if only prisoner is awake and pet dog is absent"
      (is (= true (annalyns-infiltration/can-free-prisoner? false false true false)))))

(deftest release-prisoner-knight-awake-dog-present-test
    (testing "Can release prisoner if only knight is awake and pet dog is present"
      (is (= true (annalyns-infiltration/can-free-prisoner? true false false true)))))

(deftest release-prisoner-archer-asleep-dog-present-test
    (testing "Can release prisoner if only archer is asleep and pet dog is present"
      (is (= true (annalyns-infiltration/can-free-prisoner? true false true true)))))