~willvaughn/kata

8f79c51523a35fe42d506521410327e318a9cdbf — William Vaughn 1 year, 5 months ago d5ebcc0
exercism elyses-destructured-enchantments download
A exercism/clojure/elyses-destructured-enchantments/.exercism/config.json => exercism/clojure/elyses-destructured-enchantments/.exercism/config.json +21 -0
@@ 0,0 1,21 @@
{
  "authors": [
    "porkostomus"
  ],
  "files": {
    "solution": [
      "src/elyses_destructured_enchantments.clj"
    ],
    "test": [
      "test/elyses_destructured_enchantments_test.clj"
    ],
    "exemplar": [
      ".meta/exemplar.clj"
    ]
  },
  "forked_from": [
    "javascript/elyses-destructured-enchantments"
  ],
  "icon": "elyses-enchantments",
  "blurb": "Elyse's magic training continues, teaching you about sequential destructing."
}

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

A exercism/clojure/elyses-destructured-enchantments/HELP.md => exercism/clojure/elyses-destructured-enchantments/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/elyses_destructured_enchantments.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/elyses-destructured-enchantments/HINTS.md => exercism/clojure/elyses-destructured-enchantments/HINTS.md +24 -0
@@ 0,0 1,24 @@
# Hints

## 1. Get the first card

- [This guide][destructuring_resource] has a good overview of sequential destructuring. You can find an example of binding names to values.

## 2. Get the second card

- You can use placeholders to ignore one or more values in the binding.

## 3. Swap the first two cards

- It's possible to use `&` to combine the tail elements into a sequence.

## 4. Discard the top card

- You can use `:as all` to bind the entire vector to the symbol `all`.

## 5. Insert face cards

- You can find more info on where to destructure [here][where-to-destructure].

[destructuring_resource]: https://clojure.org/guides/destructuring#_sequential_destructuring
[where-to-destructure]: https://clojure.org/guides/destructuring#_where_to_destructure
\ No newline at end of file

A exercism/clojure/elyses-destructured-enchantments/README.md => exercism/clojure/elyses-destructured-enchantments/README.md +87 -0
@@ 0,0 1,87 @@
# Elyses Destructured Enchantments

Welcome to Elyses Destructured Enchantments 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

Clojure's sequential destructuring syntax is a concise way to extract values from a vector and assign them to distinct variables.

In this example, each value in the `number-of-moons` vector is assigned to its corresponding planet:

```clojure
(def number-of-moons [0 2 14])

(let [[venus mars neptune] number-of-moons]
  neptune)

;=> 14
```

## Instructions

Elyse, magician-to-be, continues her training. She has a deck of cards she wants to manipulate.

To make things easier, she usually only starts with cards numbered 1 to 10, although some of the tricks may involve additional cards.

## 1. Get the first card

Elyse will summon the first card in the deck, without using its index or `first`. It's just like magic.

```clojure
(def deck [5 9 7 1 8])

(first-card deck)
;=> 5
```

## 2. Get the second card

Elyse performs sleight of hand, and summons the second card in the deck, without using its index or `second`.

```clojure
(def deck [3 2 10 6 7])

(second-card deck)
;=> 2
```

## 3. Swap the first two cards

Elyse will make the top two cards of the deck switch places.

```clojure
(def deck [10 7 3 8 5])

(swap-top-two-cards deck)
;=> [7 10 3 8 5]
```

## 4. Discard the top card

Elyse will separate the deck into two piles. The first pile will contain only the top card of the original deck, while the second pile will contain all the other cards.

```clojure
(def deck [2 5 4 9 3])

(discard-top-card deck)
;=> [2 [5 4 9 3]]
```

## 5. Insert face cards

Elyse will insert a set of face cards (i.e. jack, queen, and king) into her deck such that they become the second, third, and fourth cards respectively.

```clojure
(def deck [5 4 7 10])

(insert-face-cards deck)
;=> [5 "jack" "queen" "king" 4 7 10]
```

## Source

### Created by

- @porkostomus
\ No newline at end of file

A exercism/clojure/elyses-destructured-enchantments/deps.edn => exercism/clojure/elyses-destructured-enchantments/deps.edn +18 -0
@@ 0,0 1,18 @@
{:paths ["src" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.10.1"}}
 :aliases
 {:test {:extra-paths ["test"]
         :extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}}}
  :runner
  {:extra-deps {com.cognitect/test-runner
                {:git/url "https://github.com/cognitect-labs/test-runner"
                 :sha "b6b3193fcc42659d7e46ecd1884a228993441182"}}
   :main-opts ["-m" "cognitect.test-runner"
               "-d" "test"]}
  :jar {:extra-deps {seancorfield/depstar {:mvn/version "1.1.133"}}
        :exec-fn hf.depstar/jar
        :exec-args {:jar "elyses-destructured-enchantments.jar"}}
  :install {:extra-deps {slipset/deps-deploy {:mvn/version "0.1.1"}}
            :main-opts ["-m" "deps-deploy.deps-deploy" "install" "elyses-destructured-enchantments.jar"]}
  :deploy {:extra-deps {slipset/deps-deploy {:mvn/version "0.1.1"}}
           :main-opts ["-m" "deps-deploy.deps-deploy" "deploy" "elyses-destructured-enchantments.jar"]}}}

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

A exercism/clojure/elyses-destructured-enchantments/src/elyses_destructured_enchantments.clj => exercism/clojure/elyses-destructured-enchantments/src/elyses_destructured_enchantments.clj +30 -0
@@ 0,0 1,30 @@
(ns elyses-destructured-enchantments)

(defn first-card
  "Returns the first card from deck."
  [deck]
)

(defn second-card
  "Returns the second card from deck."
  [deck]
)

(defn swap-top-two-cards
  "Returns the deck with first two items reversed."
  [deck]
)

(defn discard-top-card
  "Returns a sequence containing the first card and
   a sequence of the remaining cards in the deck."
  [deck]
)

(def face-cards
  ["jack" "queen" "king"])

(defn insert-face-cards
  "Returns the deck with face cards between its head and tail."
  [deck]
)

A exercism/clojure/elyses-destructured-enchantments/test/elyses_destructured_enchantments_test.clj => exercism/clojure/elyses-destructured-enchantments/test/elyses_destructured_enchantments_test.clj +42 -0
@@ 0,0 1,42 @@
(ns elyses-destructured-enchantments-test
  (:require [clojure.test :refer :all]
            [elyses-destructured-enchantments :refer :all]))

(deftest first-card-single-test
  (is (= 3 (first-card [3]))))

(deftest first-card-multiple-test
  (is (= 8 (first-card [8 3 9 5]))))

(deftest second-card-2-test
  (is (= 4 (second-card [10 4]))))

(deftest second-card-4-test
  (is (= 5 (second-card [2 5 1 6]))))

(deftest second-card-empty-test
  (is (nil? (second-card []))))

(deftest second-card-single-test
  (is (nil? (second-card [8]))))

(deftest swap-top-two-cards-2-test
  (is (= [6 3] (swap-top-two-cards [3 6]))))

(deftest swap-top-two-cards-5-test
  (is (= [4 10 3 7 8] (swap-top-two-cards [10 4 3 7 8]))))

(deftest discard-top-card-single-test
  (is (= [7 nil] (discard-top-card [7]))))

(deftest discard-top-card-4-test
  (is (= [9 [2 10 4]] (discard-top-card [9 2 10 4]))))

(deftest insert-face-cards-3-test
  (is (= [3 "jack" "queen" "king" 10 7] (insert-face-cards [3 10 7]))))

(deftest insert-face-cards-1-test
  (is (= [9 "jack" "queen" "king"] (insert-face-cards [9]))))

(deftest insert-face-cards-empty-test
  (is (= ["jack" "queen" "king"] (insert-face-cards []))))