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 practice exercise Zebra Puzzle #788

Merged
merged 11 commits into from
Apr 23, 2024
85 changes: 40 additions & 45 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@
"prerequisites": []
},
{
"uuid": "88baa5ab-dacb-4fab-8f16-4f3ed726b27b",
"slug": "freelancer-rates",
"name": "Freelancer Rates",
"concepts": ["numbers"],
"uuid": "88baa5ab-dacb-4fab-8f16-4f3ed726b27b",
"concepts": [
"numbers"
],
"prerequisites": [
"basics",
"includes"
Expand Down Expand Up @@ -950,7 +952,7 @@
"name": "Darts",
"uuid": "e8ad3859-9999-4a36-900d-d82fa6e74b08",
"practices": [
"if-statements"
"if-statements"
],
"prerequisites": [
"numbers"
Expand Down Expand Up @@ -1018,9 +1020,7 @@
"prerequisites": [
"classes"
],
"difficulty": 4,
"topics": [
]
"difficulty": 4
},
{
"slug": "pop-count",
Expand All @@ -1033,30 +1033,23 @@
"if-statements",
"comparisons"
],
"difficulty": 3,
"topics": [
]
"difficulty": 3
},
{
"slug": "diamond",
"name": "Diamond",
"uuid": "f8298f68-ef4e-41e1-99af-85a1bef71561",
"practices": [
],
"prerequisites": [
],
"difficulty": 3,
"topics": [
]
"practices": [],
"prerequisites": [],
"difficulty": 3
},
{
"slug": "run-length-encoding",
"name": "Run-Length Encoding",
"uuid": "916fedd1-a9ed-4200-b115-cc1d1bc44aba",
"practices": [],
"prerequisites": [],
"difficulty": 3,
"topics": []
"difficulty": 3
},
{
"slug": "rotational-cipher",
Expand All @@ -1068,53 +1061,55 @@
"prerequisites": [
"loops"
],
"difficulty": 3,
"topics": []
"difficulty": 3
},
{
"slug": "resistor-color",
"name": "Resistor Color",
"uuid": "15a9277e-59e2-484a-9877-64437556825c",
"practices": [],
"prerequisites": [],
"difficulty": 2,
"topics": []
"difficulty": 2
},
{
"slug": "resistor-color-duo",
"name": "Resistor Color Duo",
"uuid": "83ce95e9-f8af-4dbb-b96b-d94b12421d77",
"practices": [],
"prerequisites": [],
"difficulty": 3,
"topics": []
"difficulty": 3
},
{
"slug": "minesweeper",
"name": "Minesweeper",
"uuid": "3753a72a-78b7-429f-b79a-f68d55a00387",
"practices": [],
"prerequisites": [],
"difficulty": 5,
"topics": []
"difficulty": 5
},
{
"slug": "sublist",
"name": "Sublist",
"uuid": "801cb315-91d6-48e6-92f4-36423a89d4e1",
"practices": [],
"prerequisites": [],
"difficulty": 5,
"topics": []
"difficulty": 5
},
{
"slug": "zebra-puzzle",
"name": "Zebra Puzzle",
"uuid": "2badf89b-efc4-46f1-af8d-b7d2440e61c0",
"practices": [],
"prerequisites": [],
"difficulty": 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would give this a higher difficulty, maybe 7 or 8.
@vaeng What do you think?

},
{
"slug": "two-bucket",
"name": "Two Bucket",
"uuid": "83c92b7f-fb0e-43d8-ab7d-d514408b8575",
"practices": [],
"prerequisites": [],
"difficulty": 7,
"topics": []
"difficulty": 7
}
],
"foregone": [
Expand Down Expand Up @@ -1205,47 +1200,47 @@
],
"key_features": [
{
"icon": "fast",
"title": "Fast execution speed",
"content": "With execution speed in mind, C++ is used in a wide range of computation-intensive domains."
"content": "With execution speed in mind, C++ is used in a wide range of computation-intensive domains.",
"icon": "fast"
},
{
"icon": "multi-paradigm",
"title": "Multi-paradigm",
"content": "C++ supports a variety of programming paradigms like OOP, functional and procedural programming."
"content": "C++ supports a variety of programming paradigms like OOP, functional and procedural programming.",
"icon": "multi-paradigm"
},
{
"icon": "powerful",
"title": "High-level programming",
"content": "C++ standardizes a comprehensive library, enabling the developer to concentrate on the problem."
"content": "C++ standardizes a comprehensive library, enabling the developer to concentrate on the problem.",
"icon": "powerful"
},
{
"icon": "homoiconic",
"title": "Low-level programming",
"content": "C++ masters the strength of its predecessor C and gives the developer access to the bits and bytes."
"content": "C++ masters the strength of its predecessor C and gives the developer access to the bits and bytes.",
"icon": "homoiconic"
},
{
"icon": "widely-used",
"title": "Popular",
"content": "Thanks to the flexibility and portability, you can find applications written in C++ in every scale."
"content": "Thanks to the flexibility and portability, you can find applications written in C++ in every scale.",
"icon": "widely-used"
},
{
"icon": "evolving",
"title": "Ever-evolving",
"content": "Although mature, C++ is still evolving and developed by a committee to fit the developers needs."
"content": "Although mature, C++ is still evolving and developed by a committee to fit the developers needs.",
"icon": "evolving"
}
],
"tags": [
"paradigm/object_oriented",
"typing/static",
"typing/strong",
"execution_mode/compiled",
"paradigm/object_oriented",
"platform/android",
"platform/ios",
"platform/linux",
"platform/mac",
"platform/windows",
"runtime/standalone_executable",
"typing/static",
"typing/strong",
"used_for/backends",
"used_for/cross_platform_development",
"used_for/embedded_systems",
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/zebra-puzzle/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Instructions

Solve the zebra puzzle.

1. There are five houses.
2. The Englishman lives in the red house.
3. The Spaniard owns the dog.
4. Coffee is drunk in the green house.
5. The Ukrainian drinks tea.
6. The green house is immediately to the right of the ivory house.
7. The Old Gold smoker owns snails.
8. Kools are smoked in the yellow house.
9. Milk is drunk in the middle house.
10. The Norwegian lives in the first house.
11. The man who smokes Chesterfields lives in the house next to the man with the fox.
12. Kools are smoked in the house next to the house where the horse is kept.
13. The Lucky Strike smoker drinks orange juice.
14. The Japanese smokes Parliaments.
15. The Norwegian lives next to the blue house.

Each of the five houses is painted a different color, and their inhabitants are of different national extractions, own different pets, drink different beverages and smoke different brands of cigarettes.

Which of the residents drinks water?
Who owns the zebra?
19 changes: 19 additions & 0 deletions exercises/practice/zebra-puzzle/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": ["rajatnai49"],
"files": {
"solution": [
"zebra_puzzle.cpp",
"zebra_puzzle.h"
vaeng marked this conversation as resolved.
Show resolved Hide resolved
],
"test": [
"zebra_puzzle_test.cpp"
],
"example": [
"example.cpp",
"example.h"
vaeng marked this conversation as resolved.
Show resolved Hide resolved
]
},
"blurb": "Solve the zebra puzzle.",
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/Zebra_Puzzle"
}
14 changes: 14 additions & 0 deletions exercises/practice/zebra-puzzle/.meta/example.cpp
vaeng marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "zebra_puzzle.h"

#include <string>

namespace zebra_puzzle {
std::string zebra_puzzle::drinks_water() const {
return "Norwegian";
}

std::string zebra_puzzle::who_owns_zebra() const {
return "Japanese";
}
}

15 changes: 15 additions & 0 deletions exercises/practice/zebra-puzzle/.meta/example.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#if !defined(ZEBRA_PUZZLE_H)
#define ZEBRA_PUZZLE_H

#include <string>

namespace zebra_puzzle {
class zebra_puzzle {
public:
std::string drinks_water() const;
std::string who_owns_zebra() const;
};
}


#endif
16 changes: 16 additions & 0 deletions exercises/practice/zebra-puzzle/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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.

[16efb4e4-8ad7-4d5e-ba96-e5537b66fd42]
description = "resident who drinks water"

[084d5b8b-24e2-40e6-b008-c800da8cd257]
description = "resident who owns zebra"
64 changes: 64 additions & 0 deletions exercises/practice/zebra-puzzle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Get the exercise name from the current directory
get_filename_component(exercise ${CMAKE_CURRENT_SOURCE_DIR} NAME)

# Basic CMake project
cmake_minimum_required(VERSION 3.5.1)

# Name the project after the exercise
project(${exercise} CXX)

# Get a source filename from the exercise name by replacing -'s with _'s
string(REPLACE "-" "_" file ${exercise})

# Implementation could be only a header
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.cpp)
set(exercise_cpp ${file}.cpp)
else()
set(exercise_cpp "")
endif()

# Use the common Catch library?
if(EXERCISM_COMMON_CATCH)
# For Exercism track development only
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h $<TARGET_OBJECTS:catchlib>)
elseif(EXERCISM_TEST_SUITE)
# The Exercism test suite is being run, the Docker image already
# includes a pre-built version of Catch.
find_package(Catch2 REQUIRED)
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
target_link_libraries(${exercise} PRIVATE Catch2::Catch2WithMain)
# When Catch is installed system wide we need to include a different
# header, we need this define to use the correct one.
target_compile_definitions(${exercise} PRIVATE EXERCISM_TEST_SUITE)
else()
# Build executable from sources and headers
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h test/tests-main.cpp)
endif()

set_target_properties(${exercise} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED OFF
CXX_EXTENSIONS OFF
)

set(CMAKE_BUILD_TYPE Debug)

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
set_target_properties(${exercise} PROPERTIES
COMPILE_FLAGS "-Wall -Wextra -Wpedantic -Werror"
)
endif()

# Configure to run all the tests?
if(${EXERCISM_RUN_ALL_TESTS})
target_compile_definitions(${exercise} PRIVATE EXERCISM_RUN_ALL_TESTS)
endif()

# Tell MSVC not to warn us about unchecked iterators in debug builds
if(${MSVC})
set_target_properties(${exercise} PROPERTIES
COMPILE_DEFINITIONS_DEBUG _SCL_SECURE_NO_WARNINGS)
endif()

# Run the tests on every build
add_custom_target(test_${exercise} ALL DEPENDS ${exercise} COMMAND ${exercise})
Loading
Loading