C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
Functions
exprtk_riddle.cpp File Reference
#include <string>
#include "exprtk.hpp"
Include dependency graph for exprtk_riddle.cpp:

Go to the source code of this file.

Functions

template<typename T >
void logical_deducation_riddle ()
 
int main ()
 

Function Documentation

◆ logical_deducation_riddle()

template<typename T >
void logical_deducation_riddle ( )

Definition at line 48 of file exprtk_riddle.cpp.

49{
50 typedef exprtk::symbol_table<T> symbol_table_t;
51 typedef exprtk::expression<T> expression_t;
52 typedef exprtk::parser<T> parser_t;
53 typedef exprtk::function_compositor<T> compositor_t;
54 typedef typename compositor_t::function function_t;
55
56 symbol_table_t symbol_table;
57
59
60 symbol_table.add_function("println", println);
61
62 compositor_t compositor(symbol_table);
63
64 compositor.add(function_t()
65 .name("constraint")
66 .var("person_x").var("person_y")
67 .expression
68 (
69 " person_x xor person_y; "
70 ));
71
72 const std::string logical_deducation_riddle_program =
73 " var number_of_culprits := 1; "
74 " "
75 " for (var Tori := false; Tori <= true; Tori += true) "
76 " { "
77 " for (var Annie := false; Annie <= true; Annie += true) "
78 " { "
79 " for (var Betsy := false; Betsy <= true; Betsy += true) "
80 " { "
81 " for (var Chloe := false; Chloe <= true; Chloe += true) "
82 " { "
83 " for (var Zoey := false; Zoey <= true; Zoey += true) "
84 " { "
85 " if (sum(Annie, Betsy, Chloe, Tori, Zoey) != number_of_culprits) "
86 " continue; "
87 " "
88 " var solution := "
89 " constraint( not(Zoey) , Annie ) and /* Tori */ "
90 " constraint( not(Betsy) , not(Zoey) ) and /* Annie */ "
91 " constraint( Zoey , not(Tori) ) and /* Betsy */ "
92 " constraint( Betsy , Annie ) and /* Chloe */ "
93 " constraint( Chloe , not(Tori) ) ; /* Zoey */ "
94 " "
95 " if (solution == true) "
96 " { "
97 " var culprit := ''; "
98 " [*] "
99 " { "
100 " case Annie : culprit := 'Annie'; "
101 " case Betsy : culprit := 'Betsy'; "
102 " case Chloe : culprit := 'Chloe'; "
103 " case Tori : culprit := 'Tori' ; "
104 " case Zoey : culprit := 'Zoey' ; "
105 " }; "
106 " "
107 " println(culprit,' broke the window!'); "
108 " } "
109 " } "
110 " } "
111 " } "
112 " } "
113 " } "
114 " ";
115
116 expression_t expression;
117 expression.register_symbol_table(symbol_table);
118
119 parser_t parser;
120 parser.compile(logical_deducation_riddle_program,expression);
121
122 expression.value();
123}

◆ main()

int main ( )

Definition at line 125 of file exprtk_riddle.cpp.

126{
127 logical_deducation_riddle<double>();
128 return 0;
129}