Skip to content
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
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,14 @@
"practices": [],
"prerequisites": [],
"difficulty": 1
},
{
"slug": "high-scores",
"name": "High Scores",
"uuid": "94471fe8-e533-4046-a7a2-32f35d5a56ff",
"practices": [],
"prerequisites": [],
"difficulty": 1
}
]
},
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": [
"habere-et-dispertire"
],
"files": {
"solution": [
"lib/HighScores.rakumod"
],
"test": [
"t/high-scores.rakutest"
],
"example": [
".meta/solutions/lib/HighScores.rakumod"
]
},
"blurb": "Manage a player's High Score list.",
"source": "Tribute to the eighties' arcade game Frogger"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
unit class HighScores;

has $.scores;

method scores { $!scores }
method latest { $!scores.tail }
method personal-best { $!scores.max }
method personal-top-three { $!scores.sort.reverse.head(3) }
106 changes: 106 additions & 0 deletions exercises/practice/high-scores/.meta/template-data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
unit: class

properties:
scores:
test: |-
sprintf(q:to/END/, %case<input><scores>.Array.raku, %case<expected>.Array.raku, %case<description>.raku);
cmp-ok(
HighScores.new( scores => %s ).scores,
"eqv",
%s,
%s,
);
END

latest:
test: |-
sprintf(q:to/END/, %case<input><scores>.Array.raku, %case<expected>.Int.raku, %case<description>.raku);
cmp-ok(
HighScores.new( scores => %s ).latest,
"==",
%s,
%s,
);
END

personalBest:
test: |-
sprintf(q:to/END/, %case<input><scores>.Array.raku, %case<expected>.Int.raku, %case<description>.raku);
cmp-ok(
HighScores.new( scores => %s ).personal-best,
"==",
%s,
%s,
);
END

personalTopThree:
test: |-
sprintf(q:to/END/, %case<input><scores>.Array.raku, %case<expected>.Int.raku, %case<description>.raku);
cmp-ok(
HighScores.new( scores => %s ).personal-top-three,
"==",
%s,
%s,
);
END

latestAfterTopThree:
test: |-
sprintf(q:to/END/, %case<input><scores>.Array.raku, %case<expected>.Int.raku, %case<description>.raku);
cmp-ok(
( given HighScores.new( scores => %s ) { sink .personal-top-three; .latest } ),
"==",
%s,
%s,
);
END

scoresAfterTopThree:
test: |-
sprintf(q:to/END/, %case<input><scores>.Array.raku, %case<expected>.Array.raku, %case<description>.raku);
cmp-ok(
( given HighScores.new( scores => %s ) { sink .personal-top-three; .scores } ),
"eqv",
%s,
%s,
);
END

latestAfterBest:
test: |-
sprintf(q:to/END/, %case<input><scores>.Array.raku, %case<expected>.Int.raku, %case<description>.raku);
cmp-ok(
( given HighScores.new( scores => %s ) { sink .personal-best; .latest } ),
"==",
%s,
%s,
);
END

scoresAfterBest:
test: |-
sprintf(q:to/END/, %case<input><scores>.Array.raku, %case<expected>.Array.raku, %case<description>.raku);
cmp-ok(
( given HighScores.new( scores => %s ) { sink .personal-best; .scores } ),
"eqv",
%s,
%s,
);
END

example: |-
has $.scores;

method scores { $!scores }
method latest { $!scores.tail }
method personal-best { $!scores.max }
method personal-top-three { $!scores.sort.reverse.head(3) }

stub: |-
has $.scores;

method scores { }
method latest { }
method personal-best { }
method personal-top-three { }
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"
8 changes: 8 additions & 0 deletions exercises/practice/high-scores/lib/HighScores.rakumod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
unit class HighScores;

has $.scores;

method scores { }
method latest { }
method personal-best { }
method personal-top-three { }
90 changes: 90 additions & 0 deletions exercises/practice/high-scores/t/high-scores.rakutest
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env raku
use Test;
use lib $?FILE.IO.parent(2).add('lib');
use HighScores;

cmp-ok( # begin: 1035eb93-2208-4c22-bab8-fef06769a73c
HighScores.new( scores => [30, 50, 20, 70] ).scores,
"eqv",
[30, 50, 20, 70],
"List of scores",
); # end: 1035eb93-2208-4c22-bab8-fef06769a73c

cmp-ok( # begin: 6aa5dbf5-78fa-4375-b22c-ffaa989732d2
HighScores.new( scores => [100, 0, 90, 30] ).latest,
"==",
30,
"Latest score",
); # end: 6aa5dbf5-78fa-4375-b22c-ffaa989732d2

cmp-ok( # begin: b661a2e1-aebf-4f50-9139-0fb817dd12c6
HighScores.new( scores => [40, 100, 70] ).personal-best,
"==",
100,
"Personal best",
); # end: b661a2e1-aebf-4f50-9139-0fb817dd12c6

cmp-ok( # begin: 3d996a97-c81c-4642-9afc-80b80dc14015
HighScores.new( scores => [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70] ).personal-top-three,
"==",
3,
"Top 3 scores: Personal top three from a list of scores",
); # end: 3d996a97-c81c-4642-9afc-80b80dc14015

cmp-ok( # begin: 1084ecb5-3eb4-46fe-a816-e40331a4e83a
HighScores.new( scores => [20, 10, 30] ).personal-top-three,
"==",
3,
"Top 3 scores: Personal top highest to lowest",
); # end: 1084ecb5-3eb4-46fe-a816-e40331a4e83a

cmp-ok( # begin: e6465b6b-5a11-4936-bfe3-35241c4f4f16
HighScores.new( scores => [40, 20, 40, 30] ).personal-top-three,
"==",
3,
"Top 3 scores: Personal top when there is a tie",
); # end: e6465b6b-5a11-4936-bfe3-35241c4f4f16

cmp-ok( # begin: f73b02af-c8fd-41c9-91b9-c86eaa86bce2
HighScores.new( scores => [30, 70] ).personal-top-three,
"==",
2,
"Top 3 scores: Personal top when there are less than 3",
); # end: f73b02af-c8fd-41c9-91b9-c86eaa86bce2

cmp-ok( # begin: 16608eae-f60f-4a88-800e-aabce5df2865
HighScores.new( scores => [40] ).personal-top-three,
"==",
1,
"Top 3 scores: Personal top when there is only one",
); # end: 16608eae-f60f-4a88-800e-aabce5df2865

cmp-ok( # begin: 2df075f9-fec9-4756-8f40-98c52a11504f
( given HighScores.new( scores => [70, 50, 20, 30] ) { sink .personal-top-three; .latest } ),
"==",
30,
"Top 3 scores: Latest score after personal top scores",
); # end: 2df075f9-fec9-4756-8f40-98c52a11504f

cmp-ok( # begin: 809c4058-7eb1-4206-b01e-79238b9b71bc
( given HighScores.new( scores => [30, 50, 20, 70] ) { sink .personal-top-three; .scores } ),
"eqv",
[30, 50, 20, 70],
"Top 3 scores: Scores after personal top scores",
); # end: 809c4058-7eb1-4206-b01e-79238b9b71bc

cmp-ok( # begin: ddb0efc0-9a86-4f82-bc30-21ae0bdc6418
( given HighScores.new( scores => [20, 70, 15, 25, 30] ) { sink .personal-best; .latest } ),
"==",
30,
"Top 3 scores: Latest score after personal best",
); # end: ddb0efc0-9a86-4f82-bc30-21ae0bdc6418

cmp-ok( # begin: 6a0fd2d1-4cc4-46b9-a5bb-2fb667ca2364
( given HighScores.new( scores => [20, 70, 15, 25, 30] ) { sink .personal-best; .scores } ),
"eqv",
[20, 70, 15, 25, 30],
"Top 3 scores: Scores after personal best",
); # end: 6a0fd2d1-4cc4-46b9-a5bb-2fb667ca2364

done-testing;