-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
618ad72
add practice exercise Zebra Puzzle
rajatnai49 cb61bc2
Add backtracking solution to zebra puzzle and update docs
rajatnai49 16d0835
Merge branch 'exercism:main' into zebra-puzzle
rajatnai49 14742e3
Update the solution of the zebra puzzle
rajatnai49 a73966a
Merge branch 'main' into zebra-puzzle
vaeng de2ccf8
Single function to solve the zebra puzzle and answer questions
rajatnai49 fe50deb
Merge branch 'zebra-puzzle' of github.com:rajatnai49/cpp into zebra-p…
rajatnai49 aa30af8
Merge branch 'exercism:main' into zebra-puzzle
rajatnai49 48d1852
Merge branch 'zebra-puzzle' of github.com:rajatnai49/cpp into zebra-p…
rajatnai49 ebe65be
Improvements
rajatnai49 f9b9f4f
Make Clang Happy :)
rajatnai49 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
vaeng marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?