Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Scala - <strike>467</strike> <strike>364</strike> 339 chars</strong></p> <pre><code>object G{def main(a:Array[String]){val l=io.Source.fromFile(new java.io.File(a(0)))getLines("\n")map(_.toSeq)toSeq val f=new java.io.FileWriter("out.txt") f.write((1 to a(1).toInt).foldLeft(l){(t,_)=&gt;(for(y&lt;-0 to 39)yield(for(x&lt;-0 to 79)yield{if(x%79==0|y%39==0)'.'else{val m=t(y-1) val p=t(y+1);val s=Seq(m(x-1),m(x),m(x+1),t(y)(x-1),t(y)(x+1),p(x-1),p(x),p(x+1)).count('X'==_) if(s==3|(s==2&amp;t(y)(x)=='X'))'X'else'.'}})toSeq)toSeq}map(_.mkString)mkString("\n")) f.close}} </code></pre> <p>I think there is much room for improvement...</p> <p><strong>[Edit]</strong> Yes, it is:</p> <pre><code>object G{def main(a:Array[String]){var l=io.Source.fromFile(new java.io.File(a(0))).mkString val f=new java.io.FileWriter("out.txt") var i=a(1).toInt while(i&gt;0){l=l.zipWithIndex.map{case(c,n)=&gt;if(c=='\n')'\n'else{val s=Seq(-83,-82,-81,-1,1,81,82,83).map(_+n).filter(k=&gt;k&gt;=0&amp;k&lt;l.size).count(l(_)=='X') if(s==3|(s==2&amp;c=='X'))'X'else'.'}}.mkString i-=1} f.write(l) f.close}} </code></pre> <p><strong>[Edit]</strong> And I have the feeling there is still more to squeeze out...</p> <pre><code>object G{def main(a:Array[String]){val f=new java.io.FileWriter("out.txt") f.write(((1 to a(1).toInt):\(io.Source.fromFile(new java.io.File(a(0))).mkString)){(_,m)=&gt;m.zipWithIndex.map{case(c,n)=&gt; val s=Seq(-83,-82,-81,-1,1,81,82,83)count(k=&gt;k+n&gt;=0&amp;k+n&lt;m.size&amp;&amp;m(k+n)=='X') if(c=='\n')c else if(s==3|s==2&amp;c=='X')'X'else'.'}.mkString}) f.close}} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload