{"id":189,"date":"2021-01-21T21:52:10","date_gmt":"2021-01-21T21:52:10","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/data-science\/?p=189"},"modified":"2021-01-21T21:52:10","modified_gmt":"2021-01-21T21:52:10","slug":"solving-cryparithetic-puzzle-in-python","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/","title":{"rendered":"Solving Cryparithetic Puzzle in Python"},"content":{"rendered":"<p>A cryptarithmetic (also called verbal arithmetic) puzzle is a mathematical operation where the numbers are represented by letters. So each letter in the puzzle represent a certain unique digit.<\/p>\n<p>The objective is to find out the digit represented by each letter that satisfies a given equation.<\/p>\n<pre dir=\"ltr\" translate=\"no\">     SEND\r\n+    MORE\r\n---------\r\n=   MONEY\r\n<\/pre>\n<p>In this example, the solution to the puzzle is:<br \/>\nO = 0, M = 1, Y = 2, E = 5, N = 6, D = 7, R = 8, and S = 9.<\/p>\n<p>which gives us:<\/p>\n<pre dir=\"ltr\" translate=\"no\">     9567\r\n+    1085\r\n---------\r\n=   10652\r\n<\/pre>\n<p><strong>Another example<\/strong> is give below<\/p>\n<pre dir=\"ltr\" translate=\"no\">      CP\r\n+     IS\r\n+    FUN\r\n--------\r\n=   TRUE\r\n<\/pre>\n<p>Here, the solution is R=0, T=1, C=2, P=3, <span style=\"font-family: 'Source Sans Pro', Graphik, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 1.125rem;\">S=4, E=5, U-6,<\/span><span style=\"font-family: 'Source Sans Pro', Graphik, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 1.125rem;\"> I=7, N=8, F=9<\/span><\/p>\n<p>which gives us:<\/p>\n<pre dir=\"ltr\" translate=\"no\">      23\r\n+     74\r\n+    968\r\n--------\r\n=   1065<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Modelling the Problem<\/strong><\/p>\n<p><strong>Step 1<\/strong>: The first step is to identify the variables. In this case, out variables are all the letters in the problem. They are:<\/p>\n<p>C, P, I, S, F, U, N, T, R, E<\/p>\n<p>Not that there will be not repeating variable. Also, the values of the variable are single digits, therefore the ranges are 0 to 9. The code below defines the variable.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">from<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">ortools.sat.python<\/span> <span style=\"color: #008800; font-weight: bold;\">import<\/span> cp_model\r\nmodel <span style=\"color: #333333;\">=<\/span> cp_model<span style=\"color: #333333;\">.<\/span>CpModel()\r\n<\/pre>\n<p>The next code sets up the variables<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">base <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>\r\n\r\nc <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"background-color: #fff0f0;\">'C'<\/span>)\r\np <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"background-color: #fff0f0;\">'P'<\/span>)\r\ni <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"background-color: #fff0f0;\">'I'<\/span>)\r\ns <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"background-color: #fff0f0;\">'S'<\/span>)\r\nf <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"background-color: #fff0f0;\">'F'<\/span>)\r\nu <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"background-color: #fff0f0;\">'U'<\/span>)\r\nn <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"background-color: #fff0f0;\">'N'<\/span>)\r\nt <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">1<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"background-color: #fff0f0;\">'T'<\/span>)\r\nr <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"background-color: #fff0f0;\">'R'<\/span>)\r\ne <span style=\"color: #333333;\">=<\/span> model<span style=\"color: #333333;\">.<\/span>NewIntVar(<span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">9<\/span>, <span style=\"background-color: #fff0f0;\">'E'<\/span>)\r\n\r\n<span style=\"color: #888888;\"># List of variables<\/span>\r\nletters <span style=\"color: #333333;\">=<\/span> [c, p, i, s, f, u, n, t, r, e]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 2:<\/strong> Then we identify the constraints<\/p>\n<p>The variables are letter and can take on single digit value<\/p>\n<p>Therefore we can establish the following constraints<\/p>\n<ul>\n<li>CP + IS + FUN = TRUE<\/li>\n<li>each of the letter must be a different digit<\/li>\n<li>C, I, F, T \u2260 0 (since leading digit in a number is not zero)<\/li>\n<\/ul>\n<p>The code below defines the constraints and the objective function<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># Define the constraints<\/span>\r\nmodel<span style=\"color: #333333;\">.<\/span>AddAllDifferent(letters)\r\n\r\n<span style=\"color: #888888;\"># CP + IS + FUN = TRUE<\/span>\r\nmodel<span style=\"color: #333333;\">.<\/span>Add(c <span style=\"color: #333333;\">*<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span> <span style=\"color: #333333;\">+<\/span> p <span style=\"color: #333333;\">+<\/span> i <span style=\"color: #333333;\">*<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span> <span style=\"color: #333333;\">+<\/span> s <span style=\"color: #333333;\">+<\/span> f <span style=\"color: #333333;\">*<\/span> base<span style=\"color: #333333;\">**<\/span><span style=\"color: #0000dd; font-weight: bold;\">2<\/span> <span style=\"color: #333333;\">+<\/span> u <span style=\"color: #333333;\">*<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span> <span style=\"color: #333333;\">+<\/span> n <span style=\"color: #333333;\">==<\/span> t <span style=\"color: #333333;\">*<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span><span style=\"color: #333333;\">**<\/span><span style=\"color: #0000dd; font-weight: bold;\">3<\/span> <span style=\"color: #333333;\">+<\/span> r <span style=\"color: #333333;\">*<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span><span style=\"color: #333333;\">**<\/span><span style=\"color: #0000dd; font-weight: bold;\">2<\/span> <span style=\"color: #333333;\">+<\/span> u <span style=\"color: #333333;\">*<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span> <span style=\"color: #333333;\">+<\/span> e)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 3:<\/strong> Printing all Solutions<\/p>\n<p>We want the solver to print\u00a0 the solution as it finds them. The code below does that:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># Solution Printer Class<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">VarArraySolutionPrinter<\/span>(cp_model<span style=\"color: #333333;\">.<\/span>CpSolverSolutionCallback):\r\n    \r\n    <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">__init__<\/span>(<span style=\"color: #007020;\">self<\/span>, variables):\r\n        cp_model<span style=\"color: #333333;\">.<\/span>CpSolverSolutionCallback<span style=\"color: #333333;\">.<\/span>__init__(<span style=\"color: #007020;\">self<\/span>)\r\n        <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>__variables <span style=\"color: #333333;\">=<\/span> variables\r\n        <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>__solution_count <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>\r\n    \r\n    <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">on_solution_callback<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n        <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>__solution_count <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>\r\n        <span style=\"color: #008800; font-weight: bold;\">for<\/span> v <span style=\"color: #000000; font-weight: bold;\">in<\/span> <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>__variables:\r\n            <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">'%s=%i '<\/span> <span style=\"color: #333333;\">%<\/span>(v, <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>Value(v)), end<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">''<\/span>)\r\n        <span style=\"color: #007020;\">print<\/span>()\r\n    \r\n    <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">solution_count<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n        <span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>__solution_count\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4:<\/strong> Invoke the Solver and call the printer.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\"># Call the solver<\/span>\r\nsolver <span style=\"color: #333333;\">=<\/span> cp_model<span style=\"color: #333333;\">.<\/span>CpSolver()\r\nsolution_printer <span style=\"color: #333333;\">=<\/span> VarArraySolutionPrinter(letters)\r\nstatus <span style=\"color: #333333;\">=<\/span>  solver<span style=\"color: #333333;\">.<\/span>SearchForAllSolutions(model, solution_printer)\r\n<\/pre>\n<p>The Complete program<\/p>\n<figure id=\"attachment_192\" aria-describedby=\"caption-attachment-192\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.kindsonthegenius.com\/data-science\/wp-content\/uploads\/sites\/12\/2021\/01\/Screenshot-2021-01-21-at-22.48.53.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-192 size-large\" src=\"https:\/\/www.kindsonthegenius.com\/data-science\/wp-content\/uploads\/sites\/12\/2021\/01\/Screenshot-2021-01-21-at-22.48.53-1024x852.png\" alt=\"Solution to Cryptarithmetic in Python\" width=\"1024\" height=\"852\" srcset=\"https:\/\/www.kindsonthegenius.com\/data-science\/wp-content\/uploads\/sites\/12\/2021\/01\/Screenshot-2021-01-21-at-22.48.53-1024x852.png 1024w, https:\/\/www.kindsonthegenius.com\/data-science\/wp-content\/uploads\/sites\/12\/2021\/01\/Screenshot-2021-01-21-at-22.48.53-300x250.png 300w, https:\/\/www.kindsonthegenius.com\/data-science\/wp-content\/uploads\/sites\/12\/2021\/01\/Screenshot-2021-01-21-at-22.48.53-768x639.png 768w, https:\/\/www.kindsonthegenius.com\/data-science\/wp-content\/uploads\/sites\/12\/2021\/01\/Screenshot-2021-01-21-at-22.48.53.png 1029w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-192\" class=\"wp-caption-text\">Solution to Cryptarithmetic in Python<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>If you run the code you will have the following result:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">C=6 P=4 I=3 S=5 F=9 U=2 N=8 T=1 R=0 E=7 \r\nC=3 P=4 I=6 S=5 F=9 U=2 N=8 T=1 R=0 E=7 \r\nC=3 P=4 I=6 S=8 F=9 U=2 N=5 T=1 R=0 E=7 \r\nC=3 P=2 I=6 S=7 F=9 U=8 N=5 T=1 R=0 E=4 \r\nC=3 P=2 I=6 S=5 F=9 U=8 N=7 T=1 R=0 E=4 \r\nC=2 P=3 I=7 S=6 F=9 U=8 N=5 T=1 R=0 E=4 \r\nC=2 P=3 I=7 S=4 F=9 U=6 N=8 T=1 R=0 E=5 \r\nC=2 P=3 I=7 S=5 F=9 U=4 N=8 T=1 R=0 E=6 \r\nC=2 P=3 I=7 S=8 F=9 U=4 N=5 T=1 R=0 E=6 \r\nC=2 P=3 I=7 S=8 F=9 U=6 N=4 T=1 R=0 E=5 \r\nC=2 P=3 I=7 S=5 F=9 U=8 N=6 T=1 R=0 E=4 \r\nC=7 P=3 I=2 S=5 F=9 U=8 N=6 T=1 R=0 E=4 \r\nC=7 P=3 I=2 S=6 F=9 U=8 N=5 T=1 R=0 E=4 \r\nC=6 P=2 I=3 S=7 F=9 U=8 N=5 T=1 R=0 E=4 \r\nC=6 P=2 I=3 S=5 F=9 U=8 N=7 T=1 R=0 E=4 \r\nC=7 P=3 I=2 S=4 F=9 U=6 N=8 T=1 R=0 E=5 \r\nC=7 P=3 I=2 S=8 F=9 U=6 N=4 T=1 R=0 E=5 \r\nC=7 P=4 I=2 S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=5 \r\nC=2 P=8 I=7 S=4 F=9 U=6 N=3 T=1 R=0 E=5 \r\nC=2 P=8 I=7 S=5 F=9 U=4 N=3 T=1 R=0 E=6 \r\nC=7 P=6 I=2 S=5 F=9 U=8 N=3 T=1 R=0 E=4 \r\nC=7 P=5 I=2 S=6 F=9 U=8 N=3 T=1 R=0 E=4 \r\nC=6 P=5 I=3 S=7 F=9 U=8 N=2 T=1 R=0 E=4 \r\nC=6 P=7 I=3 S=5 F=9 U=8 N=2 T=1 R=0 E=4 \r\nC=6 P=7 I=3 S=2 F=9 U=8 N=5 T=1 R=0 E=4 \r\nC=6 P=5 I=3 S=2 F=9 U=8 N=7 T=1 R=0 E=4 \r\n<\/pre>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>A cryptarithmetic (also called verbal arithmetic) puzzle is a mathematical operation where the numbers are represented by letters. So each letter in the puzzle represent &hellip; <!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[29],"tags":[],"class_list":["post-189","post","type-post","status-publish","format-standard","hentry","category-constraint-optimization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Solving Cryparithetic Puzzle in Python - Data Science Tutorials<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Solving Cryparithetic Puzzle in Python - Data Science Tutorials\" \/>\n<meta property=\"og:description\" content=\"A cryptarithmetic (also called verbal arithmetic) puzzle is a mathematical operation where the numbers are represented by letters. So each letter in the puzzle represent &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Data Science Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-21T21:52:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/data-science\/wp-content\/uploads\/sites\/12\/2021\/01\/Screenshot-2021-01-21-at-22.48.53-1024x852.png\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"headline\":\"Solving Cryparithetic Puzzle in Python\",\"datePublished\":\"2021-01-21T21:52:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/\"},\"wordCount\":285,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/wp-content\\\/uploads\\\/sites\\\/12\\\/2021\\\/01\\\/Screenshot-2021-01-21-at-22.48.53-1024x852.png\",\"articleSection\":[\"Constraint Optimization\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/\",\"name\":\"Solving Cryparithetic Puzzle in Python - Data Science Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/wp-content\\\/uploads\\\/sites\\\/12\\\/2021\\\/01\\\/Screenshot-2021-01-21-at-22.48.53-1024x852.png\",\"datePublished\":\"2021-01-21T21:52:10+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/wp-content\\\/uploads\\\/sites\\\/12\\\/2021\\\/01\\\/Screenshot-2021-01-21-at-22.48.53.png\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/wp-content\\\/uploads\\\/sites\\\/12\\\/2021\\\/01\\\/Screenshot-2021-01-21-at-22.48.53.png\",\"width\":1029,\"height\":856,\"caption\":\"Solution to Cryptarithmetic in Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/solving-cryparithetic-puzzle-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Solving Cryparithetic Puzzle in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/\",\"name\":\"Data Science Tutorials\",\"description\":\"Data Science and Machine Learning in Python and R\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=wavatar&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=wavatar&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/data-science\\\/author\\\/kindsonthegenius-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Solving Cryparithetic Puzzle in Python - Data Science Tutorials","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Solving Cryparithetic Puzzle in Python - Data Science Tutorials","og_description":"A cryptarithmetic (also called verbal arithmetic) puzzle is a mathematical operation where the numbers are represented by letters. So each letter in the puzzle represent &hellip;","og_url":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/","og_site_name":"Data Science Tutorials","article_published_time":"2021-01-21T21:52:10+00:00","og_image":[{"url":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-content\/uploads\/sites\/12\/2021\/01\/Screenshot-2021-01-21-at-22.48.53-1024x852.png","type":"","width":"","height":""}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/data-science\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"headline":"Solving Cryparithetic Puzzle in Python","datePublished":"2021-01-21T21:52:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/"},"wordCount":285,"commentCount":0,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-content\/uploads\/sites\/12\/2021\/01\/Screenshot-2021-01-21-at-22.48.53-1024x852.png","articleSection":["Constraint Optimization"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/","url":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/","name":"Solving Cryparithetic Puzzle in Python - Data Science Tutorials","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/data-science\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-content\/uploads\/sites\/12\/2021\/01\/Screenshot-2021-01-21-at-22.48.53-1024x852.png","datePublished":"2021-01-21T21:52:10+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/data-science\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-content\/uploads\/sites\/12\/2021\/01\/Screenshot-2021-01-21-at-22.48.53.png","contentUrl":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-content\/uploads\/sites\/12\/2021\/01\/Screenshot-2021-01-21-at-22.48.53.png","width":1029,"height":856,"caption":"Solution to Cryptarithmetic in Python"},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/data-science\/solving-cryparithetic-puzzle-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/data-science\/"},{"@type":"ListItem","position":2,"name":"Solving Cryparithetic Puzzle in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/data-science\/#website","url":"https:\/\/www.kindsonthegenius.com\/data-science\/","name":"Data Science Tutorials","description":"Data Science and Machine Learning in Python and R","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/data-science\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/data-science\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=wavatar&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=wavatar&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/data-science\/author\/kindsonthegenius-3\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/posts\/189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/comments?post=189"}],"version-history":[{"count":3,"href":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/posts\/189\/revisions"}],"predecessor-version":[{"id":193,"href":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/posts\/189\/revisions\/193"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/media?parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/categories?post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/data-science\/wp-json\/wp\/v2\/tags?post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}