Jump to content

Faces from a mesh: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 80:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F perim_equal(p1, =p2)
I p1.len != p2.len | Set(p1) != Set(p2)
R 0B
Line 127:
‘H’ = [(1, 3), (9, 11), (3, 11), (1, 11)]]
L(name, edges) edge_d
print(‘ ’name‘: ’edges"\n -> "edge_to_periphery(edges))</langsyntaxhighlight>
 
{{out}}
Line 147:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 291:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 307:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.List (find, delete, (\\))
import Control.Applicative ((<|>))
 
Line 349:
p <- find ((x ==) . fst) rs <|> find ((x ==) . snd) rs
let next = if fst p == x then snd p else fst p
(x :) <$> go next (delete p rs)</langsyntaxhighlight>
 
First task.
Line 402:
</pre>
Secondly:
<syntaxhighlight lang="j">
<lang J>
edge_to_node=: 3 :0
assert. 2 = #/.~ , y [ 'expect each node to appear twice'
Line 415:
~. , oel
)
</syntaxhighlight>
</lang>
 
<pre>
Line 450:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">iseq(f, g) = any(n -> f == circshift(g, n), 1:length(g))
 
function toface(evec)
Line 485:
println(toface(face))
end
</langsyntaxhighlight>{{out}}
<pre>
Faces are equivalent.
Line 496:
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">-- support
function T(t) return setmetatable(t, {__index=table}) end
table.eql = function(t,u) if #t~=#u then return false end for i=1,#t do if t[i]~=u[i] then return false end end return true end
Line 552:
print("ef2pf(F): ", ef2pf(F):concat(","))
print("ef2pf(G): ", ef2pf(G):concat(","))
print("ef2pf(H): ", ef2pf(H):concat(","))</langsyntaxhighlight>
{{out}}
<pre>pfeq(Q,R): true
Line 562:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import algorithm, strutils
 
type
Line 652:
for (faceName, edges) in FE:
let perimeter = edges.toPerimeter()
echo faceName, ": ", if perimeter.len == 0: "Invalid edge list" else: $perimeter</langsyntaxhighlight>
 
{{out}}
Line 667:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 723:
[[1, 3], [9, 11], [3, 11], [1, 11]]) {
say show($_) . ' ==> (' . (join ' ', edge_to_periphery(@$_) or 'Invalid edge format') . ')'
}</langsyntaxhighlight>
{{out}}
<pre>Perimeter format equality checks:
Line 736:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">perequiv</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">)</span>
Line 814:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%v\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">edge2peri</span><span style="color: #0000FF;">(</span><span style="color: #000000;">etests</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
(second part matches Julia/Perl: un-comment that sort above to match Go/Python/zkl)
Line 829:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">def perim_equal(p1, p2):
# Cheap tests first
if len(p1) != len(p2) or set(p1) != set(p2):
Line 878:
}
for name, edges in edge_d.items():
print(f" {name}: {edges}\n -> {edge_to_periphery(edges)}")</langsyntaxhighlight>
 
{{out}}
Line 899:
{{works with|Rakudo|2019.11}}
 
<syntaxhighlight lang="raku" perl6line>sub check-equivalence ($a, $b) { so $a.Bag eqv $b.Bag }
 
sub edge-to-periphery (@a is copy) {
Line 939:
.gist.print;
say " ==> ({.&edge-to-periphery || 'Invalid edge format'})";
}</langsyntaxhighlight>
{{out}}
<pre>Perimeter format equality checks:
Line 956:
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "./sort" for Sort
import "./seq" for Lst
import "./fmt" for Fmt
Line 1,060:
Fmt.print(" $c => $n", i + 69, perim)
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,077:
=={{header|zkl}}==
{{trans|Python}}
<langsyntaxhighlight lang="zkl">fcn perimSame(p1, p2){
if(p1.len() != p2.len()) return(False);
False == p1.filter1('wrap(p){ (not p2.holds(p)) })
Line 1,093:
}
p[0,-1] // last element not part of result
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">println("Perimeter format equality checks:");
ps:=T( T( T(8,1,3), T(1,3,8) ),
T( T(18, 8, 14, 10, 12, 17, 19), T(8, 14, 10, 12, 17, 19, 18) ) );
Line 1,111:
 
fcn pp(a){ a.concat(", ","(",")") }
fcn ppp(edges){ pp(edges.apply(pp)) }</langsyntaxhighlight>
{{out}}
<pre>
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.