Unicode polynomial equation: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Phix}}: syntax coloured, made p2js compatible)
m (syntax highlighting fixup automation)
Line 60:
=={{header|Go}}==
Although this program provides full support for Unicode vulgar fractions, note that there is no guarantee that they (or arithmetic on them) will successfully 'round trip' due to floating point arithmetic being used in the underlying calculations and some of them being recurring rather than exact decimals in any case.
<langsyntaxhighlight lang="go">package main
 
import (
Line 316:
printEquation(coefs)
}
}</langsyntaxhighlight>
 
{{out}}
Line 371:
=={{header|Julia}}==
The task allows the "polynomials" to be parsed to have negative exponents. This makes them <em>Laurent</em> polynomials, not ordinary polynomials.
<langsyntaxhighlight lang="julia">import Base.print
 
struct LaurentPolynomial{T}
Line 505:
println(lpad(s, 48), " => ", topoly(s, 'x'))
end
</langsyntaxhighlight>{{out}}
<pre>
1x⁵ - 2x⁴ + 42x³ + 0x² + 40x + 1 => x⁵ - 2x⁴ + 42x³ + 40x + 1
Line 524:
=={{header|Nim}}==
{{trans|Go}}
<langsyntaxhighlight Nimlang="nim">import re, sequtils, strutils, tables
from unicode import toRunes
 
Line 675:
if c != 0: coefs[p] = coefs.getOrDefault(p) + c
 
printEquation(coefs)</langsyntaxhighlight>
 
{{out}}
Line 728:
=={{header|Phix}}==
To simplify this task I first created a test file (save as utf8, Unicode_polynomial_equation.e):
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">raw_text</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
-0.00x⁺¹⁰ + 1.0·x ** 5 + -2e0x^4 + +0,042.00 × x ⁺³ + +.0x² + 20.000 000 000x¹ - -1x⁺⁰ + .0x⁻¹ + 20.x¹
Line 773:
<span style="color: #008080;">return</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #000000;">raw_text</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<!--</langsyntaxhighlight>-->
Explanation: <br>
On finding a line beginning with "==> ", parse the previous line and check that the output matches the rest of the line.<br>
Line 790:
bytes happen to be less than 255, which would not necessarily be valid utf8/32.
 
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Unicode_polynomial_equation.exw</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">uni_frac</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">WINDOWS</span> <span style="color: #000080;font-style:italic;">-- if true output unicode superscripts and vulgar fractions</span>
Line 1,132:
<span style="color: #0000FF;">?</span><span style="color: #008000;">"done"</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
{{out}}
uni_frac = false (ie windows)
Line 1,180:
{{trans|Go}}
{{libheader|Wren-pattern}}
<langsyntaxhighlight lang="ecmascript">import "/pattern" for Pattern
 
var powers = [
Line 1,396:
}
printEquation.call(coefs)
}</langsyntaxhighlight>
 
{{out}}
10,327

edits