Skip to content

Commit

Permalink
Merge branch 'main' of github.com:exercism/clojure into exercise/list…
Browse files Browse the repository at this point in the history
…-ops
  • Loading branch information
kahgoh committed Sep 9, 2024
2 parents 081276c + 7b46e1f commit 3e1954c
Show file tree
Hide file tree
Showing 167 changed files with 1,859 additions and 1,146 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'daily'
interval: 'monthly'
23 changes: 23 additions & 0 deletions .github/workflows/no-important-files-changed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: No important files changed

on:
pull_request_target:
types: [opened]
branches: [main]
paths:
- "exercises/concept/**"
- "exercises/practice/**"
- "!exercises/*/*/.approaches/**"
- "!exercises/*/*/.articles/**"
- "!exercises/*/*/.docs/**"
- "!exercises/*/*/.meta/**"

permissions:
pull-requests: write

jobs:
check:
uses: exercism/github-actions/.github/workflows/check-no-important-files-changed.yml@main
with:
repository: ${{ github.event.pull_request.head.repo.owner.login }}/${{ github.event.pull_request.head.repo.name }}
ref: ${{ github.head_ref }}
16 changes: 16 additions & 0 deletions .github/workflows/ping-cross-track-maintainers-team.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Ping cross-track maintainers team

on:
pull_request_target:
types:
- opened

permissions:
pull-requests: write

jobs:
ping:
if: github.repository_owner == 'exercism' # Stops this job from running on forks
uses: exercism/github-actions/.github/workflows/ping-cross-track-maintainers-team.yml@main
secrets:
github_membership_token: ${{ secrets.COMMUNITY_CONTRIBUTIONS_WORKFLOW_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
path: clojure-test-runner

- name: setup babashka
uses: turtlequeue/setup-babashka@83e81711f784e0dcb593e53b642fc9850067f234
uses: turtlequeue/setup-babashka@2d4df498c7a578b4f3e906283f9af913590bdec7
with:
babashka-version: 0.8.1

Expand Down
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ This policy was initially adopted from the Front-end London Slack community and
A version history can be seen on [GitHub](https://github.com/exercism/website-copy/edit/main/pages/code_of_conduct.md).

_This policy is a "living" document, and subject to refinement and expansion in the future.
This policy applies to the Exercism website, the Exercism GitHub organization, any other Exercism-related communication channels (e.g. Slack, Twitter, email) and any other Exercism entity or event._
This policy applies to the Exercism website, the Exercism GitHub organization, any other Exercism-related communication channels (e.g. Discord, Forum, Twitter, email) and any other Exercism entity or event._
11 changes: 0 additions & 11 deletions appveyor.yml

This file was deleted.

23 changes: 12 additions & 11 deletions bin/fetch-configlet
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ get_download_url() {
local latest='https://api.github.com/repos/exercism/configlet/releases/latest'
local arch
case "$(uname -m)" in
x86_64) arch='x86-64' ;;
*686*) arch='i386' ;;
*386*) arch='i386' ;;
*) arch='x86-64' ;;
aarch64|arm64) arch='arm64' ;;
x86_64) arch='x86-64' ;;
*686*) arch='i386' ;;
*386*) arch='i386' ;;
*) arch='x86-64' ;;
esac
local suffix="${os}_${arch}.${ext}"
curl "${curlopts[@]}" --header 'Accept: application/vnd.github.v3+json' "${latest}" |
Expand All @@ -47,7 +48,7 @@ main() {
fi

local os
case "$(uname)" in
case "$(uname -s)" in
Darwin*) os='macos' ;;
Linux*) os='linux' ;;
Windows*) os='windows' ;;
Expand All @@ -58,8 +59,8 @@ main() {

local ext
case "${os}" in
windows*) ext='zip' ;;
*) ext='tar.gz' ;;
windows) ext='zip' ;;
*) ext='tar.gz' ;;
esac

echo "Fetching configlet..." >&2
Expand All @@ -69,16 +70,16 @@ main() {
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"

case "${ext}" in
*zip) unzip "${output_path}" -d "${output_dir}" ;;
*) tar xzf "${output_path}" -C "${output_dir}" ;;
zip) unzip "${output_path}" -d "${output_dir}" ;;
*) tar xzf "${output_path}" -C "${output_dir}" ;;
esac

rm -f "${output_path}"

local executable_ext
case "${os}" in
windows*) executable_ext='.exe' ;;
*) executable_ext='' ;;
windows) executable_ext='.exe' ;;
*) executable_ext='' ;;
esac

local configlet_path="${output_dir}/configlet${executable_ext}"
Expand Down
2 changes: 1 addition & 1 deletion concepts/atoms/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Since all of Clojure's standard data types are immutable, it offers *reference types* which offer controlled mutation. The simplest and most commonly used of these are called Atoms.

Atoms are created with the `atom` function, which take an initial value:
Atoms are created with the `atom` function, which takes an initial value:

```clojure
(def players (atom ()))
Expand Down
2 changes: 1 addition & 1 deletion concepts/atoms/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Since all of Clojure's standard data types are immutable, it offers *reference types* which offer controlled mutation. The simplest and most commonly used of these are called Atoms.

Atoms are created with the `atom` function, which take an initial value:
Atoms are created with the `atom` function, which takes an initial value:

```clojure
(def players (atom ()))
Expand Down
12 changes: 6 additions & 6 deletions concepts/functions-generating-functions/about.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# About

Being a functional language, functions in Clojure are first-class citizens. This means that they can be passed to and generated by other functions just like data. Clojure in particular comes with a rich set of high-order functions that derive new functions based on existing ones. We will explore here four important cases: `partial`, `comp`, `memoize` and `juxt`. These function-generating functions fall into a broader category of higher-order functions, such as `map`, `reduce`, `apply`, `complement`, to name a few, which operate on existing functions.
Being a functional language, functions in Clojure are first-class citizens. This means that they can be passed to and generated by other functions just like data. Clojure in particular comes with a rich set of higher-order functions that derive new functions based on existing ones. We will explore here four important cases: `partial`, `comp`, `memoize` and `juxt`. These function-generating functions fall into a broader category of higher-order functions, such as `map`, `reduce`, `apply`, `complement`, to name a few, which operate on existing functions.

## partial

Expand All @@ -15,7 +15,7 @@ The result is a new function which applies the original one `my-function` by fix
; => equivalent to (my-function v1 v2 ... vM xM+1 xM+2 ... xN)
```

As a simple example, let's define a function `inc-by-9` which increases by 9, a fixed amount, whatever we pass-in. We could implement such function as follows:
As a simple example, let's define a function `inc-by-9` which increases by 9, a fixed amount, whatever we pass-in. We could implement such a function as follows:

```clojure
(def inc-by-9 (partial + 9))
Expand All @@ -42,13 +42,13 @@ And use `partial` to always use a specific greetings message:

## comp

`comp` can be used to create a composition of any number of functions we want to compose. In general, composing `N` functions `f1, f2, ..., fN` means applying those functions in sequential order, passing the ouput of the previous function to the next one. In mathematical notation this is expressed as:
`comp` can be used to create a composition of any number of functions we want to compose. In general, composing `N` functions `f1, f2, ..., fN` means applying those functions in sequential order, passing the output of the previous function to the next one. In mathematical notation this is expressed as:

```
f1 (f2 (... fN(x)))
```

In clojure, this is equivalent to doing:
In Clojure, this is equivalent to doing:
```clojure
(f1 (f2 (... (fN x))))
```
Expand Down Expand Up @@ -79,7 +79,7 @@ As an example, let's say we want to sum a series of numbers and then multiply th

`memoize` allows to reuse previously computed results associated with a given input. Given the same input, the *memoized* function returns the same result without having to recompute it again. It takes advantage of the fact that `clojure` functions are, by default, *referentially transparent*: given the same input, they always produce the same output, which makes it possible to reuse previous computations with ease.

In order to see how this works, let us use a synthetic case where the function sleeps for two seconds before producing the output, so we can easily compare the *computation time* before and after using `memoize`.
In order to see how this works, let us use a synthetic case where the function sleeps for two seconds before producing the output, so that we can easily compare the *computation time* before and after using `memoize`.

```clojure
(defn my-time-consuming-fn
Expand All @@ -89,7 +89,7 @@ In order to see how this works, let us use a synthetic case where the function s
(* x 2)
)

; We measure the time it takes the original function
; We measure the time it takes for the original function
(time (my-time-consuming-fn 3))
; => "Elapsed time: 2007.785622 msecs"
; => 6
Expand Down
12 changes: 6 additions & 6 deletions concepts/functions-generating-functions/introduction.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Introduction

Being a functional language, functions in Clojure are first-class citizens. This means that they can be passed to and generated by other functions just like data. Clojure in particular comes with a rich set of high-order functions that derive new functions based on existing ones. We will explore here four important cases: `partial`, `comp`, `memoize` and `juxt`. These function-generating functions fall into a broader category of higher-order functions, such as `map`, `reduce`, `apply`, `complement`, to name a few, which operate on existing functions.
Being a functional language, functions in Clojure are first-class citizens. This means that they can be passed to and generated by other functions just like data. Clojure in particular comes with a rich set of higher-order functions that derive new functions based on existing ones. We will explore here four important cases: `partial`, `comp`, `memoize` and `juxt`. These function-generating functions fall into a broader category of higher-order functions, such as `map`, `reduce`, `apply`, `complement`, to name a few, which operate on existing functions.

## partial

Expand All @@ -15,7 +15,7 @@ The result is a new function which applies the original one `my-function` by fix
; => equivalent to (my-function v1 v2 ... vM xM+1 xM+2 ... xN)
```

As a simple example, let's define a function `inc-by-9` which increases by 9, a fixed amount, whatever we pass-in. We could implement such function as follows:
As a simple example, let's define a function `inc-by-9` which increases by 9, a fixed amount, whatever we pass-in. We could implement such a function as follows:

```clojure
(def inc-by-9 (partial + 9))
Expand All @@ -42,13 +42,13 @@ And use `partial` to always use a specific greetings message:

## comp

`comp` can be used to create a composition of any number of functions we want to compose. In general, composing `N` functions `f1, f2, ..., fN` means applying those functions in sequential order, passing the ouput of the previous function to the next one. In mathematical notation this is expressed as:
`comp` can be used to create a composition of any number of functions we want to compose. In general, composing `N` functions `f1, f2, ..., fN` means applying those functions in sequential order, passing the output of the previous function to the next one. In mathematical notation this is expressed as:

```
f1 (f2 (... fN(x)))
```

In clojure, this is equivalent to doing:
In Clojure, this is equivalent to doing:
```clojure
(f1 (f2 (... (fN x))))
```
Expand Down Expand Up @@ -79,7 +79,7 @@ As an example, let's say we want to sum a series of numbers and then multiply th

`memoize` allows to reuse previously computed results associated with a given input. Given the same input, the *memoized* function returns the same result without having to recompute it again. It takes advantage of the fact that `clojure` functions are, by default, *referentially transparent*: given the same input, they always produce the same output, which makes it possible to reuse previous computations with ease.

In order to see how this works, let us use a synthetic case where the function sleeps for two seconds before producing the output, so we can easily compare the *computation time* before and after using `memoize`.
In order to see how this works, let us use a synthetic case where the function sleeps for two seconds before producing the output, so that we can easily compare the *computation time* before and after using `memoize`.

```clojure
(defn my-time-consuming-fn
Expand All @@ -89,7 +89,7 @@ In order to see how this works, let us use a synthetic case where the function s
(* x 2)
)

; We measure the time it takes the original function
; We measure the time it takes for the original function
(time (my-time-consuming-fn 3))
; => "Elapsed time: 2007.785622 msecs"
; => 6
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/card-games/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Introduction

In Clojure, Lists are [collections][type-collection], just as like [lists in other languages][type-list]. Similar to other languages in the Lisp family, Clojure uses parentheses to express lists.
In Clojure, Lists are [collections][type-collection], just like [lists in other languages][type-list]. Similar to other languages in the Lisp family, Clojure uses parentheses to express lists.

Clojure lists can be created in one of two ways. The `list` function can create a list, or you can `quote` a literal list.

Expand Down
16 changes: 10 additions & 6 deletions exercises/concept/cars-assemble/test/cars_assemble_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@
(:require cars-assemble
[clojure.test :refer [deftest is testing]]))

(defn- float-equal?
[x y]
(= (float x) (float y)))

(deftest ^{:task 1} production-rate-speed-0-test
(testing "Production rate for speed 0"
(is (= 0.0 (cars-assemble/production-rate 0)))))
(is (float-equal? 0.0 (cars-assemble/production-rate 0)))))

(deftest ^{:task 1} production-rate-speed-1-test
(testing "Production rate for speed 1"
(is (= 221.0 (cars-assemble/production-rate 1)))))
(is (float-equal? 221.0 (cars-assemble/production-rate 1)))))

(deftest ^{:task 1} production-rate-speed-4-test
(testing "Production rate for speed 4"
(is (= 884.0 (cars-assemble/production-rate 4)))))
(is (float-equal? 884.0 (cars-assemble/production-rate 4)))))

(deftest ^{:task 1} production-rate-speed-7-test
(testing "Production rate for speed 7"
(is (= 1392.3 (cars-assemble/production-rate 7)))))
(is (float-equal? 1392.3 (cars-assemble/production-rate 7)))))

(deftest ^{:task 1} production-rate-speed-9-test
(testing "Production rate for speed 9"
(is (= 1591.2 (cars-assemble/production-rate 9)))))
(is (float-equal? 1591.2 (cars-assemble/production-rate 9)))))

(deftest ^{:task 1} production-rate-speed-10-test
(testing "Production rate for speed 10"
(is (= 1701.7 (cars-assemble/production-rate 10)))))
(is (float-equal? 1701.7 (cars-assemble/production-rate 10)))))

(deftest ^{:task 2} working-items-speed-0-test
(testing "Working items for speed 0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ Implement the `memoize-transform` function. It takes a function to _memoize_, th
(def triple-scale (scale2d 3 3))
(def memoized-scale (memoize-transform triple-scale))

(memoizedScale 4 3)
(memoized-scale 4 3)
;; => [12, 9], this is computed since it hasn't been computed before for the arguments

(memoizedScale 4 3)
(memoized-scale 4 3)
;; => [12, 9], this is remembered, since it was computed already
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ In this exercise you'll be working with savings accounts. Each year, the balance

- -3.213% for a negative balance.
- 0.5% for a positive balance less than `1000` dollars.
- 1.621% for a positive balance greater or equal than `1000` dollars and less than `5000` dollars.
- 2.475% for a positive balance greater or equal than `5000` dollars.
- 1.621% for a positive balance greater than or equal to `1000` dollars and less than `5000` dollars.
- 2.475% for a positive balance greater than or equal to `5000` dollars.

Each year, **before** the balance of your savings account is updated, the government allows you to donate a percentage of your money to charity, tax free. Because you're a nice person, if your balance is positive at the end of the year, you donate twice this amount to charities, rounded down to the nearest whole dollar.

Expand Down
8 changes: 2 additions & 6 deletions exercises/practice/accumulate/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Instructions

Implement the `accumulate` operation, which, given a collection and an
operation to perform on each element of the collection, returns a new
collection containing the result of applying that operation to each element of
the input collection.
Implement the `accumulate` operation, which, given a collection and an operation to perform on each element of the collection, returns a new collection containing the result of applying that operation to each element of the input collection.

Given the collection of numbers:

Expand All @@ -21,6 +18,5 @@ Check out the test suite to see the expected function signature.

## Restrictions

Keep your hands off that collect/map/fmap/whatchamacallit functionality
provided by your standard library!
Keep your hands off that collect/map/fmap/whatchamacallit functionality provided by your standard library!
Solve this one yourself using other basic tools instead.
2 changes: 1 addition & 1 deletion exercises/practice/accumulate/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
},
"blurb": "Implement the `accumulate` operation, which, given a collection and an operation to perform on each element of the collection, returns a new collection containing the result of applying that operation to each element of the input collection.",
"source": "Conversation with James Edward Gray II",
"source_url": "https://twitter.com/jeg2"
"source_url": "http://graysoftinc.com/"
}
30 changes: 30 additions & 0 deletions exercises/practice/accumulate/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[64d97c14-36dd-44a8-9621-2cecebd6ed23]
description = "accumulate empty"

[00008ed2-4651-4929-8c08-8b4dbd70872e]
description = "accumulate squares"

[551016da-4396-4cae-b0ec-4c3a1a264125]
description = "accumulate upcases"

[cdf95597-b6ec-4eac-a838-3480d13d0d05]
description = "accumulate reversed strings"

[bee8e9b6-b16f-4cd2-be3b-ccf7457e50bb]
description = "accumulate recursively"
include = false

[0b357334-4cad-49e1-a741-425202edfc7c]
description = "accumulate recursively"
reimplements = "bee8e9b6-b16f-4cd2-be3b-ccf7457e50bb"
Loading

0 comments on commit 3e1954c

Please sign in to comment.