{"id":375799,"date":"2024-05-21T06:33:44","date_gmt":"2024-05-21T06:33:44","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=375799"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=375799","title":{"rendered":"<span>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u0438 \u0438\u0437 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0441\u043a\u043e\u0433\u043e \u043a\u0432\u0435\u0441\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/web.archive.org\/web\/20140401201607\/http:\/\/www.ms.unimelb.edu.au\/~mums\/puzzlehunt\/2008\/puzzles\/puzzle51.pdf\" rel=\"noopener noreferrer nofollow\">\u00ab\u0422\u0440\u0435\u043a\u0438\u00bb<\/a> &#8212; \u043e\u0434\u043d\u0430 \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043e\u043a \u0435\u0436\u0435\u0433\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u0432\u0435\u0441\u0442\u0430 <a href=\"https:\/\/web.archive.org\/web\/20140401142721\/http:\/\/www.ms.unimelb.edu.au\/~mums\/puzzlehunt\/2008\/\" rel=\"noopener noreferrer nofollow\">Puzzle Hunt<\/a> \u041c\u0435\u043b\u044c\u0431\u0443\u0440\u043d\u0441\u043a\u043e\u0433\u043e \u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/64b\/4d5\/280\/64b4d52808ebd6f5976523fd3e2a0fef.png\" width=\"640\" height=\"486\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/64b\/4d5\/280\/64b4d52808ebd6f5976523fd3e2a0fef.png\"\/><\/figure>\n<p>\u042d\u0442\u0430 \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0432\u0430 \u043f\u043e\u043b\u044f \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043d\u0430 \u043a\u043b\u0435\u0442\u043a\u0438 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043b\u0438\u043d\u0438\u044f\u043c\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u043b\u0435 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 6 \u0440\u044f\u0434\u043e\u0432 \u0438 16 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, \u043e\u0431\u0430 \u043f\u043e\u043b\u044f \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043f\u043e\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u043d\u0430 \u0434\u0432\u0435 \u0440\u0430\u0432\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438.<\/p>\n<p>\u0412 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u043f\u043e\u043b\u0435 \u0435\u0441\u0442\u044c \u043a\u043b\u0435\u0442\u043a\u0430, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u0430\u044f \u043a\u0430\u043a start, \u0438 \u043a\u043b\u0435\u0442\u043a\u0430, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u0430\u044f \u043a\u0430\u043a finish. \u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432 \u043b\u0435\u0432\u043e\u0439 \u0438 \u043f\u0440\u0430\u0432\u043e\u0439 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0446\u0438\u0444\u0440\u0430.<\/p>\n<p>\u041d\u0438\u0436\u043d\u0435\u0435 \u043f\u043e\u043b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0446\u0438\u0444\u0440 \u043e\u0442 1 \u0434\u043e 9, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0445\u0430\u043e\u0442\u0438\u0447\u043d\u043e  \u0440\u0430\u0441\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0433\u043e \u043a\u043b\u0435\u0442\u043a\u0430\u0445.<\/p>\n<p>\u0421\u0443\u0442\u044c \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0439: \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u0443\u0442\u044c \u043e\u0442 \u043a\u043b\u0435\u0442\u043a\u0438 start \u0434\u043e \u043a\u043b\u0435\u0442\u043a\u0438 finish, \u0430 \u0446\u0438\u0444\u0440\u044b \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438 \u0441\u0442\u0440\u043e\u043a \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u0442\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u043f\u0443\u0442\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0438\u043b\u0438 \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f \u0443\u0436\u0435 \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0443\u0442\u0438 \u0438\u0437 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f \u0438\u0437 \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 6 \u0441\u0442\u0440\u043e\u043a \u0438 16 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0415\u0441\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u043a\u043b\u0435\u0442\u043a\u0443 \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0446\u0438\u0444\u0440\u0443, \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043f\u0443\u0442\u044c \u0438\u0437 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f, \u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043c\u0435\u0441\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u044d\u0442\u0430 \u0446\u0438\u0444\u0440\u0430. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043c\u0435\u0441\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c. \u041d\u0438\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">7<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">7<\/p>\n<\/td>\n<td>\n<p align=\"left\">8<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">8<\/p>\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">7<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">6<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">4<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0433\u0438\u0442\u0430\u0440\u043d\u044b\u0435 \u0442\u0430\u0431\u044b \u0438 \u0441\u044b\u0433\u0440\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0435.<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/663a426eaeb5569d7b7973d2\" data-style=\"\" id=\"663a426eaeb5569d7b7973d2\" width=\"\"><\/div>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u043e \u0437\u043d\u0430\u043c\u0435\u043d\u0438\u0442\u043e\u0433\u043e \u0442\u0440\u0435\u043a\u0430 Stairway to Heaven \u0433\u0440\u0443\u043f\u043f\u044b Led Zeppelin. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, <a href=\"https:\/\/web.archive.org\/web\/20140401201611\/http:\/\/www.ms.unimelb.edu.au\/~mums\/puzzlehunt\/2008\/answers.html?puzzle=5.1\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0432\u0435\u0442\u043e\u043c<\/a> \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f STAIRWAY TO HEAVEN.<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0430\u043f\u044b \u044d\u0442\u043e\u0439 \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u0438 (\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u0433\u0440\u044b \u043d\u0430 \u0433\u0438\u0442\u0430\u0440\u0435) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python.<\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0443\u0442\u0438 \u0434\u043b\u044f \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f. \u0412\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f: \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u043b\u0435\u0432\u043e\u0439 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0435 \u043f\u043e\u043b\u044f; 3 \u043a\u043e\u0440\u0442\u0435\u0436\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0441\u0442\u0440\u043e\u043a \u0432 \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u043b\u044f \u0438 \u0441\u0442\u0440\u043e\u043a \u0432 \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u043b\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e; \u043a\u043e\u0440\u0442\u0435\u0436 \u0438\u0437 2 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0438\u0439 \u043a\u043b\u0435\u0442\u043a\u0443 start, \u0438 \u043a\u043e\u0440\u0442\u0435\u0436 \u0438\u0437 2 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0438\u0439 \u043a\u043b\u0435\u0442\u043a\u0443 finish.<\/p>\n<pre><code class=\"python\"># number of cols in the left part of the grid cols_in_left_rows = 8  #constraints for cols of the grid cols_constr =(3,3,2,1,4,3,2,3,6,3,4,3,5,2,2,3)  #constraints for rows in the left part of the grid left_rows_constr = (1,1,4,5,6,4)  #constraints for rows in the right part of the grid right_rows_constr = (5,2,2,7,6,6)  # start cell start = (0,0)  # finish cell finish = (15,5)<\/code><\/pre>\n<p>\u0421\u0440\u0430\u0437\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0434\u0432\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043d\u0430\u043c \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c.<\/p>\n<pre><code class=\"python\">def satisfied(constr):     for value in constr:         if value != 0:             return False     return True<\/code><\/pre>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u044e satisfied \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0442\u0435\u0436 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043b\u0438 \u043e\u043d\u0438 \u0440\u0435\u0448\u0435\u043d\u043d\u044b\u043c\u0438. \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u0440\u0430\u0432\u043d\u044b \u043d\u0443\u043b\u044e, \u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 True. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 False.<\/p>\n<pre><code class=\"python\">def update_constr(constr, index):     updated_value = constr[index] - 1     updated_constr = constr[:index] + (updated_value,) + constr[index+1:]     return updated_constr<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f update_constr \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f. \u0415\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043e\u0440\u0442\u0435\u0436 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0438 \u0438\u043d\u0434\u0435\u043a\u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u044d\u0442\u043e\u043c \u043a\u043e\u0440\u0442\u0435\u0436\u0435. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 \u043a\u043e\u0440\u0442\u0435\u0436, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u043c, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443, \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u043d\u0430 \u043e\u0434\u043d\u0443 \u0435\u0434\u0438\u043d\u0438\u0446\u0443. <\/p>\n<p>\u0412\u0441\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e search.<\/p>\n<pre><code class=\"python\">def search(start, finish, cols_in_left_rows, cols_constr, left_rows_constr, right_rows_constr):     # compute number of cols and rows in the grid     num_cols, num_rows = len(cols_constr), len(left_rows_constr)     start_col, start_row = start[0], start[1]     # set active and inactive rows constraints for the start cell     if start_col &lt; cols_in_left_rows:         active_rows_constr = left_rows_constr         inactive_rows_constr = right_rows_constr     else:         active_rows_constr = right_rows_constr         inactive_rows_constr = left_rows_constr     # update constraints for the start cell     updated_cols_constr = update_constr(cols_constr, start_col)     updated_active_rows_constr = update_constr(active_rows_constr, start_row)     path = depth_first_search(start, finish, num_cols, num_rows, cols_in_left_rows,                               updated_cols_constr, updated_active_rows_constr, inactive_rows_constr, ())     return path<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f search \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438 \u0440\u044f\u0434\u043e\u0432 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u043b\u0435. \u0417\u0430\u0442\u0435\u043c, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u0438 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u043b\u044f, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043a\u0430\u043a\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c, \u0430 \u043a\u0430\u043a\u043e\u0439 \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c, \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0438\u0441\u043a\u0430. \u0414\u0430\u043b\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438 \u0441\u0442\u0440\u043e\u043a \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u0438. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<pre><code class=\"python\">def depth_first_search(current_cell, finish, num_cols, num_rows, cols_in_left_rows,                         cols_constr, active_rows_constr, inactive_rows_constr, current_path):     current_path += (current_cell,)     # if current cell is a finish cell and constraints satisfied, than path is found;     # it is sufficient to check only constraints for cols, because if they are satisfied, than constraints for rows are also satisfied     if current_cell == finish and satisfied(cols_constr):         return current_path     else:         # find adjacent cells for the current cell with corresponding constraints         adjacent_cells_with_constr = find_adjacent_cells_with_constr(current_cell, finish, num_cols, num_rows, cols_in_left_rows,                                                                      cols_constr, active_rows_constr, inactive_rows_constr)         for (adjacent_cell, next_cols_constr, next_active_rows_constr, next_inactive_rows_constr) in adjacent_cells_with_constr:             # we assume, that path is acyclic             if adjacent_cell not in current_path:                 path = depth_first_search(adjacent_cell, finish, num_cols, num_rows, cols_in_left_rows,                                           next_cols_constr, next_active_rows_constr, next_inactive_rows_constr, current_path)                 if path != False:                     return path     return False<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043a\u043b\u0435\u0442\u043a\u0443 \u043f\u043e\u0438\u0441\u043a\u0430 \u043a \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u0443\u0442\u0438. \u0417\u0430\u0442\u0435\u043c \u043e\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043a\u043b\u0435\u0442\u043a\u0430 \u0441 \u0444\u0438\u043d\u0438\u0448\u043d\u043e\u0439. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0430\u043a, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u044b \u043b\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f. \u041f\u0440\u0438 \u043f\u0440\u043e\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043d\u0438\u0438 \u043f\u0443\u0442\u0438 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432. \u0415\u0441\u043b\u0438 \u043e\u043d\u0438 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u044b, \u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u043d\u043e\u0439, \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u0443\u0442\u044c.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u0443\u0442\u044c \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c, \u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043a\u043b\u0435\u0442\u043a\u0443 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e find_adjacent_cells_with_constr. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043a\u043b\u0435\u0442\u043a\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0441\u043c\u0435\u0436\u043d\u044b\u0435 \u0441 \u043d\u0435\u0439 \u043a\u043b\u0435\u0442\u043a\u0438, \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u0432 \u044d\u0442\u0438 \u043a\u043b\u0435\u0442\u043a\u0438. \u041c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u043f\u0443\u0442\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043f\u043e\u0438\u0441\u043a\u0443 \u043f\u0443\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u043e\u0434\u043d\u0443 \u0438\u0437 \u0441\u043c\u0435\u0436\u043d\u044b\u0445 \u043a\u043b\u0435\u0442\u043e\u043a, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0435 \u0440\u0430\u043d\u0435\u0435. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0443\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u0441\u043c\u0435\u0436\u043d\u0443\u044e \u043a\u043b\u0435\u0442\u043a\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438, \u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0432\u0435\u0440\u043d\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043f\u0443\u0442\u044c.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 False.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e find_adjacent_cells_with_constr.<\/p>\n<pre><code class=\"python\">def find_adjacent_cells_with_constr(cell, finish, num_cols, num_rows, cols_in_left_rows,                                     cols_constr, active_rows_constr, inactive_rows_constr):     cell_col, cell_row = cell[0], cell[1]     adjacent_cells_with_constr = ()     for direction in ('horizontal','vertical'):         for move in (+1,-1):             active_rows_constr_for_move = active_rows_constr             inactive_rows_constr_for_move = inactive_rows_constr             if direction == 'horizontal':                 next_col = cell_col + move                 #next col is inside grid                 if next_col >= 0 and next_col &lt; num_cols:                     next_row = cell_row                 else:                     continue                 # we move from the left part of the grid to the right, or from right to the left;                 # so we should swap active and inactive constraints for rows                 if (cell_col == cols_in_left_rows - 1 and move == +1) or (cell_col == cols_in_left_rows and move == -1):                     active_rows_constr_for_move, inactive_rows_constr_for_move = inactive_rows_constr_for_move, active_rows_constr_for_move                                 elif direction == 'vertical':                 next_row = cell_row + move                 # next row is inside grid                 if next_row >=0 and next_row &lt; num_rows:                     next_col = cell_col                 else:                     continue             # extract values of constraints for the next col and next row             next_col_value = cols_constr[next_col]             next_row_value = active_rows_constr_for_move[next_row]             # check that constraints             if next_col_value > 0 and next_row_value > 0:                  # if value of constraints for the next col will be zero after update,                 # and there is some col on the direction, opposite to the finish cell from the next col, with non-zero value of constraints,                 # than this path can't led to solution and should be abandoned                 if next_col_value == 1:                     finish_col = finish[0]                     if (next_col &lt;= finish_col and not satisfied(cols_constr[:next_col])                          or                         (next_col >= finish_col and not satisfied(cols_constr[next_col+1:]))):                         continue                  # if value of active constraints for the next row will be zero after update,                 # and value of inactive constraints for that row is also equal to zero,                 # and there is some row on the direction, opposite to the finish cell from the next row, with non-zero value of active or inactive constraints,                 # than this path can't led to solution and should be abandoned                 if next_row_value == 1 and inactive_rows_constr_for_move[next_row] == 0:                     finish_row = finish[1]                     if ((next_row &lt;= finish_row and                         (not satisfied(active_rows_constr_for_move[:next_row]) or not satisfied(inactive_rows_constr_for_move[:next_row])))                         or                         (next_row >= finish_row and                         (not satisfied(active_rows_constr_for_move[next_row+1:]) or not satisfied(inactive_rows_constr_for_move[next_row+1:])))):                         continue                                      adjacent_cell = (next_col, next_row)                 updated_cols_constr = update_constr(cols_constr,next_col)                 updated_active_rows_constr_for_move = update_constr(active_rows_constr_for_move, next_row)                 adjacent_cells_with_constr += ((adjacent_cell, updated_cols_constr, updated_active_rows_constr_for_move, inactive_rows_constr_for_move),)     return adjacent_cells_with_constr<\/code><\/pre>\n<p>\u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 2 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f (\u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0438 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435) \u0438 2 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f (+1 \u0438 -1). \u0414\u043b\u044f \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0447\u0430\u0441\u0442\u044c\u044e \u043f\u043e\u043b\u044f. \u0414\u043b\u044f \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0447\u0430\u0441\u0442\u044c\u044e \u043f\u043e\u043b\u044f. \u0414\u043b\u044f \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442, \u043d\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c\u0441\u044f \u043b\u0438 \u043c\u044b \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u043b\u044f \u0432 \u0434\u0440\u0443\u0433\u0443\u044e. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0430\u043a, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0438 \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043b\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u043c\u0435\u0436\u043d\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c\u0441\u044f \u0432 \u043d\u0435\u0435 (\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0435\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f). <\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u0438\u0441\u043a, \u0435\u0441\u043b\u0438 \u0441\u0440\u0430\u0437\u0443 \u043e\u0442\u0441\u0435\u043a\u0430\u0442\u044c \u0441\u043c\u0435\u0436\u043d\u044b\u0435 \u043a\u043b\u0435\u0442\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u044c \u0438 \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439, \u043d\u043e \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0431\u0435\u0441\u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u044b. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u043c\u0435\u0436\u043d\u0443\u044e \u043a\u043b\u0435\u0442\u043a\u0443, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0435\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0441\u0442\u0430\u043d\u0435\u0442 \u0440\u0430\u0432\u043d\u044b\u043c \u043d\u0443\u043b\u044e. \u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u044d\u0442\u043e\u0439 \u0441\u043c\u0435\u0436\u043d\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u0438 \u043a\u0430\u043a N, \u0430 \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0444\u0438\u043d\u0438\u0448\u043d\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u0438 &#8212; \u043a\u0430\u043a F. \u0415\u0441\u043b\u0438 N &lt;= F \u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c K, \u0433\u0434\u0435 K &lt; N, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u043d\u044b\u043c\u0438, \u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0441\u0442\u0438 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0435\u0441\u043b\u0438 N >= F \u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c K, \u0433\u0434\u0435 K > N, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u043d\u044b\u043c\u0438, \u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0441\u0442\u0438 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>\u0414\u043b\u044f \u0441\u0442\u0440\u043e\u043a \u0438\u043c\u0435\u0435\u043c \u043f\u043e\u0445\u043e\u0436\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u043c\u0435\u0436\u043d\u0443\u044e \u043a\u043b\u0435\u0442\u043a\u0443, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0435\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u0442\u0430\u043d\u0435\u0442 \u0440\u0430\u0432\u043d\u044b\u043c \u043d\u0443\u043b\u044e. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0443\u043b\u044e. \u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u0442\u0440\u043e\u043a\u0438 \u044d\u0442\u043e\u0439 \u0441\u043c\u0435\u0436\u043d\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u0438 \u043a\u0430\u043a N, \u0430 \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u0442\u0440\u043e\u043a\u0438 \u0444\u0438\u043d\u0438\u0448\u043d\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u0438 &#8212; \u043a\u0430\u043a F. \u0415\u0441\u043b\u0438 N &lt;= F \u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c K, \u0433\u0434\u0435 K &lt; N, \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0438\u043b\u0438 \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u043d\u044b\u043c\u0438, \u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0441\u0442\u0438 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0435\u0441\u043b\u0438 N >= F \u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c K, \u0433\u0434\u0435 K > N, \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0438\u043b\u0438 \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u043d\u044b\u043c\u0438, \u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0441\u0442\u0438 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>\u041c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u0438 \u0431\u0435\u0441\u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0441\u043c\u0435\u0436\u043d\u044b\u0435 \u043a\u043b\u0435\u0442\u043a\u0438 \u0434\u043e \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0441\u043c\u0435\u0436\u043d\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u0438.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:<\/p>\n<pre><code class=\"python\">path = search(start, finish, cols_in_left_rows, cols_constr, left_rows_constr, right_rows_constr)<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0443\u0442\u044c:<\/p>\n<pre><code class=\"python\">((0, 0), (0, 1), (0, 2), (1, 2), (1, 3), (1, 4), (2, 4), (2, 5), (3, 5), (4, 5), (4, 4), (4, 3), (4, 2), (5, 2), (5, 3), (5, 4), (6, 4), (6, 3), (7, 3), (7, 4), (7, 5), (8, 5), (8, 4), (9, 4), (9, 3), (8, 3), (8, 2), (8, 1), (8, 0), (9, 0), (10, 0), (11, 0), (12, 0), (12, 1), (12, 2), (12, 3), (11, 3), (10, 3), (10, 4), (10, 5), (11, 5), (12, 5), (13, 5), (13, 4), (14, 4), (14, 3), (15, 3), (15, 4), (15, 5))<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438\u0437 \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0438\u0436\u043d\u0435\u0435 \u043f\u043e\u043b\u0435 \u043a\u0430\u043a \u043a\u043e\u0440\u0442\u0435\u0436 \u0438\u0437 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443. \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0443\u0441\u0442\u044b\u0445 \u043a\u043b\u0435\u0442\u043e\u043a \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c None.<\/p>\n<pre><code class=\"python\">bottom_grid = ((None,None,8,6,None,8,None,None,None,None,None,None,None,2,None,9),                (None,1,None,3,None,None,None,1,None,7,None,9,None,None,4,None),                (7,None,4,None,6,None,9,None,5,4,None,3,4,None,1,None),                (2,5,3,3,None,None,5,None,None,None,5,None,None,8,2,None),                (None,None,5,None,None,5,None,None,None,5,None,None,6,3,None,None),                (None,4,None,5,7,None,2,7,8,9,None,8,2,None,None,2))<\/code><\/pre>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e extract_message.<\/p>\n<pre><code class=\"python\">def extract_message(grid, path):     num_rows = len(grid)     num_cols = len(grid[0])     message = ''     # decremental loop for the number of rows     for row in range(num_rows-1,-1,-1):         for col in range(num_cols):             cell_value = grid[row][col]             if (col,row) in path and isinstance(cell_value, int):                 message += str(cell_value)             else:                 message += '-'         # add newline character after each row         message += '\\n'     return message<\/code><\/pre>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u043f\u043e\u043b\u044f. \u0414\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u043d\u0430 \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u043e\u043b\u044f \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435. \u0415\u0441\u043b\u0438 \u043a\u0430\u043a\u0430\u044f-\u043b\u0438\u0431\u043e \u043a\u043b\u0435\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043f\u0443\u0442\u0438 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0446\u0438\u0444\u0440\u0443, \u0442\u043e \u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u0442\u0430 \u0446\u0438\u0444\u0440\u0430. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0438\u043c\u0432\u043e\u043b &#8216;-&#8216;. \u041f\u043e\u0441\u043b\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u043e\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044e \u0441\u0438\u043c\u0432\u043e\u043b \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 (&#8216;\\n&#8217;).<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0434\u043b\u044f \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u0443\u0442\u0438, \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438 \u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430.<\/p>\n<pre><code class=\"python\">if __name__ == '__main__':     # find path in the upper grid and extract and print corresponding message from the bottom grid of the puzzle     path = search(start, finish, cols_in_left_rows, cols_constr, left_rows_constr, right_rows_constr)     message = extract_message(bottom_grid, path)     print(message)<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/github.com\/webwanderer2024\/wondrous_net\/blob\/main\/Tracks.py\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/813389\/\"> https:\/\/habr.com\/ru\/articles\/813389\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/web.archive.org\/web\/20140401201607\/http:\/\/www.ms.unimelb.edu.au\/~mums\/puzzlehunt\/2008\/puzzles\/puzzle51.pdf\" rel=\"noopener noreferrer nofollow\">\u00ab\u0422\u0440\u0435\u043a\u0438\u00bb<\/a> &#8212; \u043e\u0434\u043d\u0430 \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043e\u043a \u0435\u0436\u0435\u0433\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u0432\u0435\u0441\u0442\u0430 <a href=\"https:\/\/web.archive.org\/web\/20140401142721\/http:\/\/www.ms.unimelb.edu.au\/~mums\/puzzlehunt\/2008\/\" rel=\"noopener noreferrer nofollow\">Puzzle Hunt<\/a> \u041c\u0435\u043b\u044c\u0431\u0443\u0440\u043d\u0441\u043a\u043e\u0433\u043e \u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u042d\u0442\u0430 \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0432\u0430 \u043f\u043e\u043b\u044f \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043d\u0430 \u043a\u043b\u0435\u0442\u043a\u0438 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043b\u0438\u043d\u0438\u044f\u043c\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u043b\u0435 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 6 \u0440\u044f\u0434\u043e\u0432 \u0438 16 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, \u043e\u0431\u0430 \u043f\u043e\u043b\u044f \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043f\u043e\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u043d\u0430 \u0434\u0432\u0435 \u0440\u0430\u0432\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438.<\/p>\n<p>\u0412 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u043f\u043e\u043b\u0435 \u0435\u0441\u0442\u044c \u043a\u043b\u0435\u0442\u043a\u0430, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u0430\u044f \u043a\u0430\u043a start, \u0438 \u043a\u043b\u0435\u0442\u043a\u0430, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u0430\u044f \u043a\u0430\u043a finish. \u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432 \u043b\u0435\u0432\u043e\u0439 \u0438 \u043f\u0440\u0430\u0432\u043e\u0439 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0446\u0438\u0444\u0440\u0430.<\/p>\n<p>\u041d\u0438\u0436\u043d\u0435\u0435 \u043f\u043e\u043b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0446\u0438\u0444\u0440 \u043e\u0442 1 \u0434\u043e 9, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0445\u0430\u043e\u0442\u0438\u0447\u043d\u043e  \u0440\u0430\u0441\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0433\u043e \u043a\u043b\u0435\u0442\u043a\u0430\u0445.<\/p>\n<p>\u0421\u0443\u0442\u044c \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0439: \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u0443\u0442\u044c \u043e\u0442 \u043a\u043b\u0435\u0442\u043a\u0438 start \u0434\u043e \u043a\u043b\u0435\u0442\u043a\u0438 finish, \u0430 \u0446\u0438\u0444\u0440\u044b \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438 \u0441\u0442\u0440\u043e\u043a \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u0442\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u043f\u0443\u0442\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0438\u043b\u0438 \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f \u0443\u0436\u0435 \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0443\u0442\u0438 \u0438\u0437 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f \u0438\u0437 \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 6 \u0441\u0442\u0440\u043e\u043a \u0438 16 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0415\u0441\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u043a\u043b\u0435\u0442\u043a\u0443 \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0446\u0438\u0444\u0440\u0443, \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043f\u0443\u0442\u044c \u0438\u0437 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f, \u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043c\u0435\u0441\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u044d\u0442\u0430 \u0446\u0438\u0444\u0440\u0430. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043c\u0435\u0441\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u043c. \u041d\u0438\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">7<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">7<\/p>\n<\/td>\n<td>\n<p align=\"left\">8<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">8<\/p>\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">3<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">2<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">7<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">6<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">5<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">4<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td data-colwidth=\"50\" width=\"50\">\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8212;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0433\u0438\u0442\u0430\u0440\u043d\u044b\u0435 \u0442\u0430\u0431\u044b \u0438 \u0441\u044b\u0433\u0440\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0435.<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/663a426eaeb5569d7b7973d2\" data-style=\"\" id=\"663a426eaeb5569d7b7973d2\" width=\"\"><\/div>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u043e \u0437\u043d\u0430\u043c\u0435\u043d\u0438\u0442\u043e\u0433\u043e \u0442\u0440\u0435\u043a\u0430 Stairway to Heaven \u0433\u0440\u0443\u043f\u043f\u044b Led Zeppelin. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, <a href=\"https:\/\/web.archive.org\/web\/20140401201611\/http:\/\/www.ms.unimelb.edu.au\/~mums\/puzzlehunt\/2008\/answers.html?puzzle=5.1\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0432\u0435\u0442\u043e\u043c<\/a> \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f STAIRWAY TO HEAVEN.<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0430\u043f\u044b \u044d\u0442\u043e\u0439 \u0433\u043e\u043b\u043e\u0432\u043e\u043b\u043e\u043c\u043a\u0438 (\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u0433\u0440\u044b \u043d\u0430 \u0433\u0438\u0442\u0430\u0440\u0435) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python.<\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0443\u0442\u0438 \u0434\u043b\u044f \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u043f\u043e\u043b\u044f. \u0412\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f: \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u043b\u0435\u0432\u043e\u0439 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0435 \u043f\u043e\u043b\u044f; 3 \u043a\u043e\u0440\u0442\u0435\u0436\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0441\u0442\u0440\u043e\u043a \u0432 \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u043b\u044f \u0438 \u0441\u0442\u0440\u043e\u043a \u0432 \u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u043b\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e; \u043a\u043e\u0440\u0442\u0435\u0436 \u0438\u0437 2 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0438\u0439 \u043a\u043b\u0435\u0442\u043a\u0443 start, \u0438 \u043a\u043e\u0440\u0442\u0435\u0436 \u0438\u0437 2 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0438\u0439 \u043a\u043b\u0435\u0442\u043a\u0443 finish.<\/p>\n<pre><code class=\"python\"># number of cols in the left part of the grid cols_in_left_rows = 8  #constraints for cols of the grid cols_constr =(3,3,2,1,4,3,2,3,6,3,4,3,5,2,2,3)  #constraints for rows in the left part of the grid left_rows_constr = (1,1,4,5,6,4)  #constraints for rows in the right part of the grid right_rows_constr = (5,2,2,7,6,6)  # start cell start = (0,0)  # finish cell finish = (15,5)<\/code><\/pre>\n<p>\u0421\u0440\u0430\u0437\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0434\u0432\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043d\u0430\u043c \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c.<\/p>\n<pre><code class=\"python\">def satisfied(constr):     for value in constr:         if value != 0:             return False     return True<\/code><\/pre>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u044e satisfied \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0442\u0435\u0436 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043b\u0438 \u043e\u043d\u0438 \u0440\u0435\u0448\u0435\u043d\u043d\u044b\u043c\u0438. \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u0440\u0430\u0432\u043d\u044b \u043d\u0443\u043b\u044e, \u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 True. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 False.<\/p>\n<pre><code class=\"python\">def update_constr(constr, index):     updated_value = constr[index] - 1     updated_constr = constr[:index] + (updated_value,) + constr[index+1:]     return updated_constr<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f update_constr \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f. \u0415\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043e\u0440\u0442\u0435\u0436 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0438 \u0438\u043d\u0434\u0435\u043a\u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u044d\u0442\u043e\u043c \u043a\u043e\u0440\u0442\u0435\u0436\u0435. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 \u043a\u043e\u0440\u0442\u0435\u0436, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u043c, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443, \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u043d\u0430 \u043e\u0434\u043d\u0443 \u0435\u0434\u0438\u043d\u0438\u0446\u0443. <\/p>\n<p>\u0412\u0441\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e search.<\/p>\n<pre><code class=\"python\">def search(start, finish, cols_in_left_rows, cols_constr, left_rows_constr, right_rows_constr):     # compute number of cols and rows in the grid     num_cols, num_rows = len(cols_constr), len(left_rows_constr)     start_col, start_row = start[0], start[1]     # set active and inactive rows constraints for the start cell     if start_col &lt; cols_in_left_rows:         active_rows_constr = left_rows_constr         inactive_rows_constr = right_rows_constr     else:         active_rows_constr = right_rows_constr         inactive_rows_constr = left_rows_constr     # update constraints for the start cell     updated_cols_constr = update_constr(cols_constr, start_col)     updated_active_rows_constr = update_constr(active_rows_constr, start_row)     path = depth_first_search(start, finish, num_cols, num_rows, cols_in_left_rows,                               updated_cols_constr, updated_active_rows_constr, inactive_rows_constr, ())     return path<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f search \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438 \u0440\u044f\u0434\u043e\u0432 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u043b\u0435. \u0417\u0430\u0442\u0435\u043c, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u0438 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u043b\u044f, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043a\u0430\u043a\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c, \u0430 \u043a\u0430\u043a\u043e\u0439 \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c, \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0438\u0441\u043a\u0430. \u0414\u0430\u043b\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438 \u0441\u0442\u0440\u043e\u043a \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u0438. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<pre><code class=\"python\">def depth_first_search(current_cell, finish, num_cols, num_rows, cols_in_left_rows,                         cols_constr, active_rows_constr, inactive_rows_constr, current_path):     current_path += (current_cell,)     # if current cell is a finish cell and constraints satisfied, than path is found;     # it is sufficient to check only constraints for cols, because if they are satisfied, than constraints for rows are also satisfied     if current_cell == finish and satisfied(cols_constr):         return current_path     else:         # find adjacent cells for the current cell with corresponding constraints         adjacent_cells_with_constr = find_adjacent_cells_with_constr(current_cell, finish, num_cols, num_rows, cols_in_left_rows,                                                                      cols_constr, active_rows_constr, inactive_rows_constr)         for (adjacent_cell, next_cols_constr, next_active_rows_constr, next_inactive_rows_constr) in adjacent_cells_with_constr:             # we assume, that path is acyclic             if adjacent_cell not in current_path:                 path = depth_first_search(adjacent_cell, finish, num_cols, num_rows, cols_in_left_rows,                                           next_cols_constr, next_active_rows_constr, next_inactive_rows_constr, current_path)                 if path != False:                     return path     return False<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043a\u043b\u0435\u0442\u043a\u0443 \u043f\u043e\u0438\u0441\u043a\u0430 \u043a \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u0443\u0442\u0438. \u0417\u0430\u0442\u0435\u043c \u043e\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043a\u043b\u0435\u0442\u043a\u0430 \u0441 \u0444\u0438\u043d\u0438\u0448\u043d\u043e\u0439. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0430\u043a, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u044b \u043b\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f. \u041f\u0440\u0438 \u043f\u0440\u043e\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043d\u0438\u0438 \u043f\u0443\u0442\u0438 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432. \u0415\u0441\u043b\u0438 \u043e\u043d\u0438 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u044b, \u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u043d\u043e\u0439, \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u0443\u0442\u044c.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u0443\u0442\u044c \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c, \u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043a\u043b\u0435\u0442\u043a\u0443 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e find_adjacent_cells_with_constr. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043a\u043b\u0435\u0442\u043a\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0441\u043c\u0435\u0436\u043d\u044b\u0435 \u0441 \u043d\u0435\u0439 \u043a\u043b\u0435\u0442\u043a\u0438, \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u0432 \u044d\u0442\u0438 \u043a\u043b\u0435\u0442\u043a\u0438. \u041c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u043f\u0443\u0442\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043f\u043e\u0438\u0441\u043a\u0443 \u043f\u0443\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u043e\u0434\u043d\u0443 \u0438\u0437 \u0441\u043c\u0435\u0436\u043d\u044b\u0445 \u043a\u043b\u0435\u0442\u043e\u043a, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0435 \u0440\u0430\u043d\u0435\u0435. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0443\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u0441\u043c\u0435\u0436\u043d\u0443\u044e \u043a\u043b\u0435\u0442\u043a\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438, \u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0432\u0435\u0440\u043d\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043f\u0443\u0442\u044c.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 False.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e find_adjacent_cells_with_constr.<\/p>\n<pre><code class=\"python\">def find_adjacent_cells_with_constr(cell, finish, num_cols, num_rows, cols_in_left_rows,                                     cols_constr, active_rows_constr, inactive_rows_constr):     cell_col, cell_row = cell[0], cell[1]     adjacent_cells_with_constr = ()     for direction in ('horizontal','vertical'):         for move in (+1,-1):             active_rows_constr_for_move = active_rows_constr             inactive_rows_constr_for_move = inactive_rows_constr             if direction == 'horizontal':                 next_col = cell_col + move                 #next col is inside grid                 if next_col >= 0 and next_col &lt; num_cols:                     next_row = cell_row                 else:                     continue                 # we move from the left part of the grid to the right, or from right to the left;                 # so we should swap active and inactive constraints for rows                 if (cell_col == cols_in_left_rows - 1 and move == +1) or (cell_col == cols_in_left_rows and move == -1):                     active_rows_constr_for_move, inactive_rows_constr_for_move = inactive_rows_constr_for_move, active_rows_constr_for_move                                 elif direction == 'vertical':                 next_row = cell_row + move                 # next row is inside grid                 if next_row >=0 and next_row &lt; num_rows:                     next_col = cell_col                 else:                     continue             # extract values of constraints for the next col and next row             next_col_value = cols_constr[next_col]             next_row_value = active_rows_constr_for_move[next_row]             # check that constraints             if next_col_value > 0 and next_row_value > 0:                  # if value of constraints for the next col will be zero after update,                 # and there is some col on the direction, opposite to the finish cell from the next col, with non-zero value of constraints,                 # than this path can't led to solution and should be abandoned                 if next_col_value == 1:                     finish_col = finish[0]                     if (next_col &lt;= finish_col and not satisfied(cols_constr[:next_col])                          or                         (next_col >= finish_col and not satisfied(cols_constr[next_col+1:]))):                         continue                  # if value of active constraints for the next<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-375799","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/375799","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=375799"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/375799\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=375799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=375799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=375799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}