Skip to content

Commit

Permalink
Solve lotto
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Aug 2, 2024
1 parent ef40fd8 commit ccf5a85
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tested/manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
),
Expand Down
25 changes: 25 additions & 0 deletions tests/exercises/lotto/solution/correct.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
#include <set>
#include <random>
#include <algorithm>
#include <sstream>

std::string loterij(int aantal = 6, int maximum = 42) {
std::set<int> 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;
}
23 changes: 23 additions & 0 deletions tests/exercises/lotto/solution/wrong.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
#include <set>
#include <random>
#include <algorithm>
#include <sstream>
#include <iterator>

std::string loterij(int aantal = 6, int maximum = 42) {
std::set<int> 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<int>(oss, " - "));
std::string result = oss.str();
result = result.substr(0, result.length() - 3); // Remove the trailing " - "
return result;
}

0 comments on commit ccf5a85

Please sign in to comment.