From ccf5a854a79fdffd5c6f8d083131e7f28bf1bb50 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Fri, 2 Aug 2024 11:08:12 +0200 Subject: [PATCH] Solve lotto --- tested/manual.py | 6 +++--- tests/exercises/lotto/solution/correct.cpp | 25 ++++++++++++++++++++++ tests/exercises/lotto/solution/wrong.cpp | 23 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 tests/exercises/lotto/solution/correct.cpp create mode 100644 tests/exercises/lotto/solution/wrong.cpp diff --git a/tested/manual.py b/tested/manual.py index a093366f..6571933f 100644 --- a/tested/manual.py +++ b/tested/manual.py @@ -13,7 +13,7 @@ from tested.main import run from tested.testsuite import SupportedLanguage -exercise_dir = "/home/jorg/Documents/universal-judge/tests/exercises/isbn-list" +exercise_dir = "/home/jorg/Documents/universal-judge/tests/exercises/lotto" def read_config() -> DodonaConfig: @@ -24,10 +24,10 @@ def read_config() -> DodonaConfig: programming_language=SupportedLanguage("cpp"), natural_language="nl", resources=Path(exercise_dir, "evaluation"), - source=Path(exercise_dir, "solution/solution.cpp"), + source=Path(exercise_dir, "solution/wrong.cpp"), judge=Path("."), workdir=Path("workdir"), - test_suite="one-with-assignment.tson", + test_suite="two.tson", options=Options( linter=False, ), diff --git a/tests/exercises/lotto/solution/correct.cpp b/tests/exercises/lotto/solution/correct.cpp new file mode 100644 index 00000000..02f28f0a --- /dev/null +++ b/tests/exercises/lotto/solution/correct.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include + +std::string loterij(int aantal = 6, int maximum = 42) { + std::set getallen; + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(1, maximum); + + while (getallen.size() < aantal) { + getallen.insert(dis(gen)); + } + + std::ostringstream oss; + for (auto num : getallen) { + oss << num << " - "; + } + + std::string result = oss.str(); + result = result.substr(0, result.length() - 3); // Remove the last " - " + return result; +} \ No newline at end of file diff --git a/tests/exercises/lotto/solution/wrong.cpp b/tests/exercises/lotto/solution/wrong.cpp new file mode 100644 index 00000000..9416e8db --- /dev/null +++ b/tests/exercises/lotto/solution/wrong.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include +#include + +std::string loterij(int aantal = 6, int maximum = 42) { + std::set getallen; + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(1, maximum); + + while (getallen.size() < aantal) { + getallen.insert(dis(gen)); + } + + std::ostringstream oss; + std::copy(getallen.rbegin(), getallen.rend(), std::ostream_iterator(oss, " - ")); + std::string result = oss.str(); + result = result.substr(0, result.length() - 3); // Remove the trailing " - " + return result; +}