Free polyominoes enumeration: Difference between revisions
m
syntax highlighting fixup automation
(→{{header|Phix}}: complete rewrite (previous was broken under pwa/p2js)) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 48:
{{trans|D}}
Turns out the source for the counting only version of the D code example could be tweaked to show solutions as well. The max rank can be changed by supplying a command line parameter. The free polyominos of any rank can be displayed by changing the variable named '''target''' to a reasonable number. This program will also indicate the estimated times for larger ranks.
<
using System.Collections.Generic;
using System.Linq;
Line 295:
}
}
</syntaxhighlight>
{{out}}
<pre>Counting polyominoes to rank 11...
Line 334:
=={{header|D}}==
{{trans|Haskell}}
<
alias Coord = byte;
Line 415:
foreach (const poly; n.rank)
writefln("%-(%s\n%)\n", poly.textRepresentation);
}</
{{out}}
<pre>[1, 1, 2, 5, 12, 35, 108, 369, 1285, 4655]
Line 476:
Translated and modified from C code: http://www.geocities.jp/tok12345/countomino.txt
<
import core.stdc.stdlib: atoi;
Line 644:
return 0;
}</
{{out}}
<pre>1
Line 676:
=={{header|Elixir}}==
{{trans|Ruby}}
<
defp translate2origin(poly) do
# Finds the min x and y coordiate of a Polyomino.
Line 750:
IO.puts "\nAll free polyominoes of rank #{n}:"
Enum.sort(Polyominoes.rank(n))
|> Enum.each(fn poly -> IO.puts "#{Polyominoes.text_representation(poly)}\n" end)</
{{out}}
Line 801:
=={{header|Go}}==
{{trans|Kotlin}}
<
import (
Line 975:
}
fmt.Println()
}</
{{out}}
Line 1,002:
Code updated and slightly improved from: http://www.haskell.org/haskellwiki/The_Monad.Reader/Issue5/Generating_Polyominoes
<
import Control.Arrow ((***), first)
import Data.Set (toList, fromList)
Line 1,098:
let n = bool (read $ head args :: Int) 5 (null args)
putStrLn ("\nAll free polyominoes of rank " ++ show n ++ ":")
mapM_ (putStrLn . textRepresentation) (rank n)</
{{out}}
<pre>[1,1,2,5,12,35,108,369,1285,4655]
Line 1,160:
Generating polyominoes as ascii art:
<
if. 1>y do. i.0 0 0 return.end.
if. 1=y do. 1 1 1$'#' return.end.
Line 1,198:
trim=:verb define&|:^:2
y#~+./"1 y~:' '
)</
Example use (boxing each pentomino for display purposes):
<
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│#####│## │# │### │## │## │### │ ## │ # │ # │ # │ ## │
Line 1,208:
│ │# │# │# │# │## │ │## │## │### │ # │# │
│ │# │# │ │ │ │ │ │ │ │ │ │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘</
=={{header|Java}}==
Translation of [[Free_polyominoes_enumeration#Haskell|Haskell]] via [[Free_polyominoes_enumeration#D|D]]
{{works with|Java|8}}
<
import java.util.*;
import static java.util.Arrays.asList;
Line 1,316:
}
}
}</
<pre>(0,0) (0,1) (1,1) (1,2) (2,1)
Line 1,333:
=={{header|Julia}}==
{{trans|Haskell}}
<
struct Point x::Float64; y::Float64 end
Line 1,422:
testpolys()
</
<pre>
[1, 1, 2, 5, 12, 35, 108, 369, 1285, 4655]
Line 1,471:
=={{header|Kotlin}}==
{{trans|Python}}
<
class Point(val x: Int, val y: Int) : Comparable<Point> {
Line 1,551:
for (i in 1..k) print("${rank(i).size} ")
println()
}</
{{out}}
Line 1,576:
=={{header|Nim}}==
{{trans|Kotlin}}
<
type Point = tuple[x, y: int]
Line 1,645:
echo "\nNumber of free polyominoes of ranks 1 to $#:".format(k)
for i in 1..k: stdout.write rank(i).len, ' '
echo()</
{{out}}
Line 1,668:
=={{header|Perl}}==
Only shows the polyominoes up to rank 5.
<
use strict;
Line 1,747:
}
keys %new;
}</
{{out}}
<pre>
Line 1,784:
=={{header|Phix}}==
Written for clarity over raw speed.
<!--<
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Polyominoes.exw</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 1,881:
<span style="color: #008080;">if</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">></span><span style="color: #000000;">0</span> <span style="color: #008080;">and</span> <span style="color: #000000;">i</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">5</span> <span style="color: #008080;">then</span> <span style="color: #000000;">print_polys</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 1,923:
=={{header|Python}}==
{{trans|Haskell}}
<
from operator import itemgetter
from sys import argv
Line 2,001:
print text_representation(poly), "\n"
main()</
{{out}}
<pre>[1, 1, 2, 5, 12, 35, 108, 369, 1285, 4655]
Line 2,060:
not included in code below). But I think it's interesting nonetheless.
<
;; Inspired by C code in http://www.geocities.jp/tok12345/countomino.txt
;; but tries to take advantage of arbitrary width integers
Line 2,273:
(when (< n 6) (draw-polynominoes p))
(printf "count: ~a~%~%" (length (polynominoes-shapes p)))
(flush-output))))</
{{out}}
Line 2,353:
=={{header|Ruby}}==
{{trans|Python}}
<
def translate2origin(poly)
Line 2,424:
n = ARGV[0] ? ARGV[0].to_i : 5
puts "\nAll free polyominoes of rank %d:" % n
rank(n).sort.each{|poly| puts text_representation(poly),""}</
{{out}}
Line 2,476:
Translation of [[Free_polyominoes_enumeration#Haskell|Haskell]] via [[Free_polyominoes_enumeration#D|Java]]
{{works with|Scala|2.12}}
<
type Point = (Int, Int)
type Polyomino = List[Point]
Line 2,544:
}
}
}</
<pre>(0,0) (0,1) (1,1) (1,2) (2,1)
Line 2,561:
=={{header|Sidef}}==
{{trans|Ruby}}
<
# Finds the min x and y coordiate of a Polyomino.
var minx = poly.map(:head).min
Line 2,636:
var n = (ARGV[0] ? ARGV[0].to_i : 5)
say ("\nAll free polyominoes of rank %d:" % n)
rank(n).sort.each{|poly| say text_representation(poly).join("\n")+"\n" }</
{{out}}
<pre style="height:250px">
Line 2,690:
{{libheader|Wren-sort}}
{{libheader|Wren-seq}}
<
import "/math" for Nums
import "/sort" for Sort, Cmp
Line 2,816:
Stdout.flush()
}
System.print()</
{{out}}
|