Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add high-scores exercise #743

Merged
merged 7 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,17 @@
"math"
]
},
{
"slug": "high-scores",
"name": "High Scores",
"uuid": "e0e4006a-7720-4ef9-adf1-95c19b93284d",
"practices": [],
"prerequisites": [
"lists",
"numbers"
],
"difficulty": 2
},
{
"slug": "triangle",
"name": "Triangle",
Expand Down
6 changes: 6 additions & 0 deletions exercises/practice/high-scores/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Instructions

Manage a game player's High Score list.

Your task is to build a high-score component of the classic Frogger game, one of the highest selling and most addictive games of all time, and a classic of the arcade era.
Your task is to write methods that return the highest score from the list, the last added score and the three highest scores.
18 changes: 18 additions & 0 deletions exercises/practice/high-scores/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"authors": [
"erikschierboom"
],
"files": {
"solution": [
"src/high_scores.clj"
],
"test": [
"test/high_scores_test.clj"
],
"example": [
".meta/example.clj"
]
},
"blurb": "Manage a player's High Score list.",
"source": "Tribute to the eighties' arcade game Frogger"
}
6 changes: 6 additions & 0 deletions exercises/practice/high-scores/.meta/example.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns high-scores)

(def scores identity)
(def latest last)
(defn personal-best [scores] (apply max scores))
(defn personal-top-three [scores] (take 3 (sort > scores)))
23 changes: 23 additions & 0 deletions exercises/practice/high-scores/.meta/generator.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(ns high-scores-test
(:require [clojure.test :refer [deftest testing is]]
high-scores))
{{#test_cases.scores}}
(deftest scores_test_{{idx}}
(testing {{string description}}
(is (= {{list expected}} (high-scores/scores {{list input.scores}})))))
{{/test_cases.scores~}}
{{#test_cases.latest}}
(deftest latest_test_{{idx}}
(testing {{string description}}
(is (= {{expected}} (high-scores/latest {{list input.scores}})))))
{{/test_cases.latest~}}
{{#test_cases.personalBest}}
(deftest personal-best_test_{{idx}}
(testing {{string description}}
(is (= {{expected}} (high-scores/personal-best {{list input.scores}})))))
{{/test_cases.personalBest~}}
{{#test_cases.personalTopThree}}
(deftest personal-top-three_test_{{idx}}
(testing {{string description}}
(is (= {{list expected}} (high-scores/personal-top-three {{list input.scores}})))))
{{/test_cases.personalTopThree~}}
46 changes: 46 additions & 0 deletions exercises/practice/high-scores/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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.

[1035eb93-2208-4c22-bab8-fef06769a73c]
description = "List of scores"

[6aa5dbf5-78fa-4375-b22c-ffaa989732d2]
description = "Latest score"

[b661a2e1-aebf-4f50-9139-0fb817dd12c6]
description = "Personal best"

[3d996a97-c81c-4642-9afc-80b80dc14015]
description = "Top 3 scores -> Personal top three from a list of scores"

[1084ecb5-3eb4-46fe-a816-e40331a4e83a]
description = "Top 3 scores -> Personal top highest to lowest"

[e6465b6b-5a11-4936-bfe3-35241c4f4f16]
description = "Top 3 scores -> Personal top when there is a tie"

[f73b02af-c8fd-41c9-91b9-c86eaa86bce2]
description = "Top 3 scores -> Personal top when there are less than 3"

[16608eae-f60f-4a88-800e-aabce5df2865]
description = "Top 3 scores -> Personal top when there is only one"

[2df075f9-fec9-4756-8f40-98c52a11504f]
description = "Top 3 scores -> Latest score after personal top scores"

[809c4058-7eb1-4206-b01e-79238b9b71bc]
description = "Top 3 scores -> Scores after personal top scores"

[ddb0efc0-9a86-4f82-bc30-21ae0bdc6418]
description = "Top 3 scores -> Latest score after personal best"

[6a0fd2d1-4cc4-46b9-a5bb-2fb667ca2364]
description = "Top 3 scores -> Scores after personal best"
6 changes: 6 additions & 0 deletions exercises/practice/high-scores/deps.edn
Original file line number Diff line number Diff line change
@@ -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}}}
4 changes: 4 additions & 0 deletions exercises/practice/high-scores/project.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(defproject high-scores "0.1.0-SNAPSHOT"
:description "high-scores exercise."
:url "https://github.com/exercism/clojure/tree/master/exercises/high-scores"
:dependencies [[org.clojure/clojure "1.11.1"]])
25 changes: 25 additions & 0 deletions exercises/practice/high-scores/src/high_scores.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(ns high-scores)

(defn scores
"Returns all scores"
[scores]
;; function body
)

(defn latest
"Returns the latest score"
[scores]
;; function body
)

(defn personal-best
"Returns the top (highest) score"
[scores]
;; function body
)

(defn personal-top-three
"Returns the top three scores"
[scores]
;; function body
)
35 changes: 35 additions & 0 deletions exercises/practice/high-scores/test/high_scores_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(ns high-scores-test
(:require [clojure.test :refer [deftest testing is]]
high-scores))

(deftest scores_test_1
(testing "List of scores"
(is (= '(30 50 20 70) (high-scores/scores '(30 50 20 70))))))

(deftest latest_test_1
(testing "Latest score"
(is (= 30 (high-scores/latest '(100 0 90 30))))))

(deftest personal-best_test_1
(testing "Personal best"
(is (= 100 (high-scores/personal-best '(40 100 70))))))

(deftest personal-top-three_test_1
(testing "Top 3 scores - Personal top three from a list of scores"
(is (= '(100 90 70) (high-scores/personal-top-three '(10 30 90 30 100 20 10 0 30 40 40 70 70))))))

(deftest personal-top-three_test_2
(testing "Top 3 scores - Personal top highest to lowest"
(is (= '(30 20 10) (high-scores/personal-top-three '(20 10 30))))))

(deftest personal-top-three_test_3
(testing "Top 3 scores - Personal top when there is a tie"
(is (= '(40 40 30) (high-scores/personal-top-three '(40 20 40 30))))))

(deftest personal-top-three_test_4
(testing "Top 3 scores - Personal top when there are less than 3"
(is (= '(70 30) (high-scores/personal-top-three '(30 70))))))

(deftest personal-top-three_test_5
(testing "Top 3 scores - Personal top when there is only one"
(is (= '(40) (high-scores/personal-top-three '(40))))))