{"id":202766,"date":"2013-11-19T16:02:03","date_gmt":"2013-11-19T12:02:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=202766"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=202766","title":{"rendered":"<span class=\"post_title\">\u0418\u0433\u0440\u0430 \u0416\u0438\u0437\u043d\u044c \u043d\u0430 LiveScript \u0432 30 \u0441\u0442\u0440\u043e\u043a<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 30-\u0442\u0438 \u0441\u0442\u0440\u043e\u0447\u043d\u043e\u0433\u043e \u043c\u0435\u043c\u0430, \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u0438\u0433\u0440\u044b \u0416\u0438\u0437\u043d\u044c \u043d\u0430 <a href=\"http:\/\/livescript.net\/\">LiveScript<\/a> (\u044f\u0437\u044b\u043a, \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0432 Javascript).<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0441\u0430\u043c \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"javascript\">stopped=true  document.body.onkeyup = (e) -&gt; e.keyCode==32 && stopped := !stopped  change = (div, a) -&gt;      div.setAttribute(\\class, a  and &quot;cell active&quot; or &quot;cell&quot;)     div.ac=a      window.activate = (div) -&gt;     div.ac ?= false     change div, !div.ac      setInterval -&gt;     unless stopped         arr=document.getElementById(&quot;board&quot;).children         newarr=[[false for _ to arr[0].children.length-1] for _ to arr.length-1]         c=0                  for i in [0 to arr.length-1]             for j in [0 to arr[i].children.length-1]                 for sx in [i-1 to i+1]                     for sy in [j-1 to j+1] when not (sy == j and sx ==i)                         arr[(sx+20)%20].children[(sy+25)%25].ac and ++c                 (c == 3 or (c == 2 and arr[i].children[j].ac)) and newarr[i][j]=true                 c=0                          for i in [0 to newarr.length-1]             for j in [0 to newarr[i].length-1]                     change arr[i].children[j], newarr[i][j]  , 1000\/15 <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043a\u043e\u0434 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439. \u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0445 \u0441\u043a\u043e\u0431\u043e\u043a \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0434\u0430.<br \/>  \u0418 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 <a href=\"http:\/\/jsfiddle.net\/Yb2cT\/\">jsfiddle<\/a><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0410 \u0432\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">\/\/ Generated by LiveScript 1.2.0 (function(){   var stopped, change;   stopped = true;   document.body.onkeyup = function(e){     return e.keyCode === 32 && (stopped = !stopped);   };   change = function(div, a){     div.setAttribute('class', a && &quot;cell active&quot; || &quot;cell&quot;);     return div.ac = a;   };   window.activate = function(div){     div.ac == null && (div.ac = false);     return change(div, !div.ac);   };   setInterval(function(){     var arr, newarr, res$, i$, to$, _, lresult$, j$, to1$, c, ref$, len$, i, ref1$, len1$, j, k$, ref2$, len2$, sx, l$, ref3$, len3$, sy, lresult1$, results$ = [];     if (!stopped) {       arr = document.getElementById(&quot;board&quot;).children;       res$ = [];       for (i$ = 0, to$ = arr.length - 1; i$ &lt;= to$; ++i$) {         _ = i$;         lresult$ = [];         for (j$ = 0, to1$ = arr[0].children.length - 1; j$ &lt;= to1$; ++j$) {           _ = j$;           lresult$.push(false);         }         res$.push(lresult$);       }       newarr = res$;       c = 0;       for (i$ = 0, len$ = (ref$ = (fn$())).length; i$ &lt; len$; ++i$) {         i = ref$[i$];         for (j$ = 0, len1$ = (ref1$ = (fn1$())).length; j$ &lt; len1$; ++j$) {           j = ref1$[j$];           for (k$ = 0, len2$ = (ref2$ = (fn2$())).length; k$ &lt; len2$; ++k$) {             sx = ref2$[k$];             for (l$ = 0, len3$ = (ref3$ = (fn3$())).length; l$ &lt; len3$; ++l$) {               sy = ref3$[l$];               if (!(sy === j && sx === i)) {                 arr[(sx + 20) % 20].children[(sy + 25) % 25].ac && ++c;               }             }           }           (c === 3 || (c === 2 && arr[i].children[j].ac)) && (newarr[i][j] = true);           c = 0;         }       }       for (i$ = 0, len$ = (ref$ = (fn4$())).length; i$ &lt; len$; ++i$) {         i = ref$[i$];         lresult1$ = [];         for (j$ = 0, len1$ = (ref1$ = (fn5$())).length; j$ &lt; len1$; ++j$) {           j = ref1$[j$];           lresult1$.push(change(arr[i].children[j], newarr[i][j]));         }         results$.push(lresult1$);       }       return results$;     }     function fn$(){       var i$, to$, results$ = [];       for (i$ = 0, to$ = arr.length - 1; i$ &lt;= to$; ++i$) {         results$.push(i$);       }       return results$;     }     function fn1$(){       var i$, to$, results$ = [];       for (i$ = 0, to$ = arr[i].children.length - 1; i$ &lt;= to$; ++i$) {         results$.push(i$);       }       return results$;     }     function fn2$(){       var i$, to$, results$ = [];       for (i$ = i - 1, to$ = i + 1; i$ &lt;= to$; ++i$) {         results$.push(i$);       }       return results$;     }     function fn3$(){       var i$, to$, results$ = [];       for (i$ = j - 1, to$ = j + 1; i$ &lt;= to$; ++i$) {         results$.push(i$);       }       return results$;     }     function fn4$(){       var i$, to$, results$ = [];       for (i$ = 0, to$ = newarr.length - 1; i$ &lt;= to$; ++i$) {         results$.push(i$);       }       return results$;     }     function fn5$(){       var i$, to$, results$ = [];       for (i$ = 0, to$ = newarr[i].length - 1; i$ &lt;= to$; ++i$) {         results$.push(i$);       }       return results$;     }   }, 1000 \/ 15); }).call(this); <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0434\u0443 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u0431\u0437\u043e\u0440 \u044f\u0437\u044b\u043a\u0430, \u043c\u043e\u0436\u0435\u0442 \u043a\u0442\u043e \u0438 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0441\u044f.<br \/>  LiveScript \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0443\u0436\u0435 \u0441\u0442\u0430\u0432\u0448\u0438\u0439 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c CoffeeScript, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432, \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439.<br \/>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430:<\/p>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:  <\/p>\n<pre><code class=\"javascript\">add = (x, y) -&gt; x+y <\/code><\/pre>\n<p>  \u0412\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:  <\/p>\n<pre><code class=\"javascript\">add 5 6 add(5, 6) add 5, 6 <\/code><\/pre>\n<p>  \u0426\u0438\u043a\u043b\u044b:  <\/p>\n<pre><code class=\"javascript\">for i in [0 to 10]     console.log i <\/code><\/pre>\n<p>  \u0421\u0442\u0440\u043e\u043a\u0438 \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435:  <\/p>\n<pre><code class=\"javascript\">a = \\string alert \\str <\/code><\/pre>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430:  <\/p>\n<pre><code class=\"javascript\">class Accumulator   (num) -&gt;     @acc = num   sum:8   add: (n) -&gt;     @acc+=n     @acc+@sum  #returns  a = new Accumulator 1 a.sum # 8 a.acc  # 1 a.add 9 # @acc now 10; return 18 <\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/202766\/\"> http:\/\/habrahabr.ru\/post\/202766\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 30-\u0442\u0438 \u0441\u0442\u0440\u043e\u0447\u043d\u043e\u0433\u043e \u043c\u0435\u043c\u0430, \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u0438\u0433\u0440\u044b \u0416\u0438\u0437\u043d\u044c \u043d\u0430 <a href=\"http:\/\/livescript.net\/\">LiveScript<\/a> (\u044f\u0437\u044b\u043a, \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0432 Javascript).  <\/p>\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-202766","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/202766","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=202766"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/202766\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=202766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=202766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=202766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}