ðŸŽ‰ Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io ðŸŽ‰

# freddie2025's solution

## to High Scores in the C# Track

Published at Apr 15 2019 · 0 comments
Instructions
Test suite
Solution

#### Note:

This exercise has changed since this solution was written.

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 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.

## Running the tests

To run the tests, run the command `dotnet test` from within the exercise directory.

Initially, only the first test will be enabled. This is to encourage you to solve the exercise one step at a time. Once you get the first test passing, remove the `Skip` property from the next test and work on getting that test passing. Once none of the tests are skipped and they are all passing, you can submit your solution using `exercism submit HighScores.cs`

## Further information

For more detailed information about the C# track, including how to get help if you're having trouble, please visit the exercism.io C# language page.

## Source

Tribute to the eighties' arcade game Frogger

### HighScoresTest.cs

``````// This file was auto-generated based on version 4.0.0 of the canonical data.

using System.Collections.Generic;
using Xunit;

public class HighScoresTest
{
[Fact]
public void List_of_scores()
{
var sut = new HighScores(new List<int> { 30, 50, 20, 70 });
Assert.Equal(new List<int> { 30, 50, 20, 70 }, sut.Scores());
}

[Fact(Skip = "Remove to run test")]
public void Latest_score()
{
var sut = new HighScores(new List<int> { 100, 0, 90, 30 });
Assert.Equal(30, sut.Latest());
}

[Fact(Skip = "Remove to run test")]
public void Personal_best()
{
var sut = new HighScores(new List<int> { 40, 100, 70 });
Assert.Equal(100, sut.PersonalBest());
}

[Fact(Skip = "Remove to run test")]
public void Personal_top_three_from_a_list_of_scores()
{
var sut = new HighScores(new List<int> { 10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70 });
Assert.Equal(new List<int> { 100, 90, 70 }, sut.PersonalTopThree());
}

[Fact(Skip = "Remove to run test")]
public void Personal_top_highest_to_lowest()
{
var sut = new HighScores(new List<int> { 20, 10, 30 });
Assert.Equal(new List<int> { 30, 20, 10 }, sut.PersonalTopThree());
}

[Fact(Skip = "Remove to run test")]
public void Personal_top_when_there_is_a_tie()
{
var sut = new HighScores(new List<int> { 40, 20, 40, 30 });
Assert.Equal(new List<int> { 40, 40, 30 }, sut.PersonalTopThree());
}

[Fact(Skip = "Remove to run test")]
public void Personal_top_when_there_are_less_than_3()
{
var sut = new HighScores(new List<int> { 30, 70 });
Assert.Equal(new List<int> { 70, 30 }, sut.PersonalTopThree());
}

[Fact(Skip = "Remove to run test")]
public void Personal_top_when_there_is_only_one()
{
var sut = new HighScores(new List<int> { 40 });
Assert.Equal(new List<int> { 40 }, sut.PersonalTopThree());
}
}``````
``````using System;
using System.Collections.Generic;
using System.Linq;

public class HighScores
{
private readonly List<int> ListOfHighScores;

public HighScores(List<int> list)
{
ListOfHighScores = list;
}

public List<int> Scores()
{
return ListOfHighScores;
}

public int Latest()
{
return ListOfHighScores.Last();
}

public int PersonalBest()
{
return ListOfHighScores.Max();
}

public List<int> PersonalTopThree()
{
return ListOfHighScores.OrderByDescending(x => x).Take(3).ToList();
}
}``````

## Community comments

Find this solution interesting? Ask the author a question to learn more.

### What can you learn from this solution?

A huge amount can be learned from reading other peopleâ€™s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

• What compromises have been made?
• Are there new concepts here that you could read more about to improve your understanding?