~willvaughn/kata

7dc3ec4b01081a88a9ccc2a2f29727a8cad89d25 — William Vaughn 1 year, 5 months ago 4df5540
exercism cars-assemble download
A exercism/clojure/cars-assemble/.exercism/config.json => exercism/clojure/cars-assemble/.exercism/config.json +20 -0
@@ 0,0 1,20 @@
{
  "authors": [
    "porkostomus"
  ],
  "files": {
    "solution": [
      "src/cars_assemble.clj"
    ],
    "test": [
      "test/cars_assemble_test.clj"
    ],
    "exemplar": [
      ".meta/exemplar.clj"
    ]
  },
  "forked_from": [
    "fsharp/cars-assemble"
  ],
  "blurb": "Learn about numbers and conditionals by analyzing the production of an assembly line in a car factory"
}

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

A exercism/clojure/cars-assemble/HELP.md => exercism/clojure/cars-assemble/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/cars_assemble.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/cars-assemble/HINTS.md => exercism/clojure/cars-assemble/HINTS.md +13 -0
@@ 0,0 1,13 @@
# Hints

## 1. Calculate the production rate per hour

- Determining the success rate can be done through a [conditional expression][conditional-expression].

## 2. Calculate the number of working items produced per minute

- Numbers can be coerced to and from [doubles][double] and [ints][int].

[conditional-expression]: https://clojure.org/guides/learn/flow#_cond
[double]: https://clojuredocs.org/clojure.core/double
[int]: https://clojuredocs.org/clojure.core/int
\ No newline at end of file

A exercism/clojure/cars-assemble/README.md => exercism/clojure/cars-assemble/README.md +66 -0
@@ 0,0 1,66 @@
# Cars, Assemble!

Welcome to Cars, Assemble! 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

Numbers in Clojure include:

- Integers: numbers with no digits behind the decimal separator (whole numbers). Examples are `-6`, `0`, `1`, `25`, `976` and `500000`.
- Floating-point numbers: numbers with zero or more digits behind the decimal separator. Examples are `-2.4`, `0.1`, `3.14`, `16.984025` and `1024.0`.

Two common numeric types are `int` and `float`. An `int` is a 32-bit integer and a `float` is a 64-bit floating-point number.

Arithmetic is done using the standard arithmetic operators. Numbers can be compared using the standard numeric comparison operators and the equality (`=`) and inequality (`<>`) operators.

In this exercise you must conditionally execute logic. A common way to do this in Clojure is by using `cond`:

```clojure
(cond (= x 5) "Expression to evaluate when x equals 5"
      (> x 7) "Expression to evaluate when x is greater than 7"
      :else   "Expression to evaluate in all other cases")
```

## Instructions

In this exercise you'll be writing code to analyze the production of an assembly line in a car factory. The assembly line's speed can range from `0` (off) to `10` (maximum).

At its lowest speed (`1`), `221` cars are produced each hour. The production increases linearly with the speed. So with the speed set to `4`, it should produce `4 * 221 = 884` cars per hour. However, higher speeds increase the likelihood that faulty cars are produced, which then have to be discarded. The following table shows how speed influences the success rate:

- `0`: 0% success rate.
- `1` to `4`: 100% success rate.
- `5` to `8`: 90% success rate.
- `9`: 80% success rate.
- `10`: 77% success rate.

You have two tasks.

## 1. Calculate the production rate per hour

Implement the `production-rate` function to calculate the assembly line's production rate per hour, taking into account its success rate:

```clojure
(production-rate 6)
;;=> 1193.4
```

Note that the value returned is a `double`.

## 2. Calculate the number of working items produced per minute

Implement the `working-items` function to calculate how many working cars are produced per minute:

```clojure
(working-items 6)
;;=> 19
```

Note that the value returned is an `int`.

## Source

### Created by

- @porkostomus
\ No newline at end of file

A exercism/clojure/cars-assemble/deps.edn => exercism/clojure/cars-assemble/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/cars-assemble/project.clj => exercism/clojure/cars-assemble/project.clj +4 -0
@@ 0,0 1,4 @@
(defproject cars-assemble "0.1.0-SNAPSHOT"
  :description "cars-assemble exercise."
  :url "https://github.com/exercism/clojure/tree/main/exercises/concept/cars-assemble"
  :dependencies [[org.clojure/clojure "1.10.0"]])
\ No newline at end of file

A exercism/clojure/cars-assemble/src/cars_assemble.clj => exercism/clojure/cars-assemble/src/cars_assemble.clj +12 -0
@@ 0,0 1,12 @@
(ns cars-assemble)

(defn production-rate
  "Returns the assembly line's production rate per hour,
   taking into account its success rate"
  [speed]
  )

(defn working-items
  "Calculates how many working cars are produced per minute"
  [speed]
  )

A exercism/clojure/cars-assemble/test/cars_assemble_test.clj => exercism/clojure/cars-assemble/test/cars_assemble_test.clj +51 -0
@@ 0,0 1,51 @@
(ns cars-assemble-test
  (:require [clojure.test :refer [deftest testing is]]
            cars-assemble))

(deftest production-rate-speed-0-test
    (testing "Production rate for speed 0"
      (is (= 0.0 (cars-assemble/production-rate 0)))))

(deftest production-rate-speed-1-test
    (testing "Production rate for speed 1"
      (is (= 221.0 (cars-assemble/production-rate 1)))))

(deftest production-rate-speed-4-test
    (testing "Production rate for speed 4"
      (is (= 884.0 (cars-assemble/production-rate 4)))))

(deftest production-rate-speed-7-test
    (testing "Production rate for speed 7"
      (is (= 1392.3 (cars-assemble/production-rate 7)))))

(deftest production-rate-speed-9-test
    (testing "Production rate for speed 9"
      (is (= 1591.2 (cars-assemble/production-rate 9)))))

(deftest production-rate-speed-10-test
    (testing "Production rate for speed 10"
      (is (= 1701.7 (cars-assemble/production-rate 10)))))

(deftest working-items-speed-0-test
    (testing "Working items for speed 0"
      (is (= 0 (cars-assemble/working-items 0)))))

(deftest working-items-speed-1-test
    (testing "Working items for speed 1"
      (is (= 3 (cars-assemble/working-items 1)))))

(deftest working-items-speed-5-test
    (testing "Working items for speed 5"
      (is (= 16 (cars-assemble/working-items 5)))))

(deftest working-items-speed-8-test
    (testing "Working items for speed 8"
      (is (= 26 (cars-assemble/working-items 8)))))

(deftest working-items-speed-9-test
    (testing "Working items for speed 9"
      (is (= 26 (cars-assemble/working-items 9)))))

(deftest working-items-speed-10-test
    (testing "Working items for speed 10"
      (is (= 28 (cars-assemble/working-items 10)))))