Heronian triangles: Difference between revisions

m
syntax highlighting fixup automation
No edit summary
m (syntax highlighting fixup automation)
Line 39:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F gcd(=u, =v)
L v != 0
(u, v) = (v, u % v)
Line 70:
print(h[0.<10].map3((x, y, z) -> ‘ #14 perim: #3 area: #.’.format(String((x, y, z)), x + y + z, hero(x, y, z))).join("\n"))
print("\nAll with area 210 subject to the previous ordering:")
print(h.filter3((x, y, z) -> hero(x, y, z) == 210).map3((x, y, z) -> ‘ #14 perim: #3 area: #.’.format(String((x, y, z)), x + y + z, hero(x, y, z))).join("\n"))</langsyntaxhighlight>
 
{{out}}
Line 98:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
Line 228:
end loop;
end;
end Heronian;</langsyntaxhighlight>
{{out}}
<pre> 517 heronian triangles found :
Line 257:
=={{header|ALGOL 68}}==
{{Trans|Lua}}
<langsyntaxhighlight lang="algol68"># mode to hold details of a Heronian triangle #
MODE HERONIAN = STRUCT( INT a, b, c, area, perimeter );
# returns the details of the Heronian Triangle with sides a, b, c or nil if it isn't one #
Line 339:
OD
END
END</langsyntaxhighlight>
{{out}}
<pre>
Line 369:
=={{header|ALGOL W}}==
{{Trans|Lua}}
<langsyntaxhighlight lang="algolw">begin
% record to hold details of a Heronian triangle %
record Heronian ( integer a, b, c, area, perimeter );
Line 465:
end
end
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 498:
 
{{Trans|JavaScript}}
<langsyntaxhighlight AppleScriptlang="applescript">use framework "Foundation"
 
-- HERONIAN TRIANGLES --------------------------------------------------------
Line 774:
((ca's NSString's stringWithString:(str))'s ¬
capitalizedStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toTitle</langsyntaxhighlight>
{{Out}}
<pre>Number of triangles found (with sides <= 200): 517
Line 803:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
Line 821:
x := StrSplit(x, "`t"), y := StrSplit(y, "`t")
return x.1 > y.1 ? 1 : x.1 < y.1 ? -1 : x.2 > y.2 ? 1 : x.2 < y.2 ? -1 : 0
}</langsyntaxhighlight>
Examples:<langsyntaxhighlight AutoHotkeylang="autohotkey">res := Primitive_Heronian_triangles(200)
loop, parse, res, `n, `r
{
Line 837:
. "`nResults for Area = 210:"
. "`n" "Area`tPerimeter`tSides`n" res3
return</langsyntaxhighlight>
Outputs:<pre>517 results found
 
Line 867:
----
'''IMPORTANT''': This is a C99 compatible implementation. May result in errors on earlier compilers.
<syntaxhighlight lang="c">
<lang C>
#include<stdlib.h>
#include<stdio.h>
Line 988:
return 0;
}
</syntaxhighlight>
</lang>
Invocation and output :
<pre>
Line 1,018:
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight Csharplang="csharp">using System;
using System.Collections.Generic;
 
Line 1,075:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>Number of primitive Heronian triangles with sides up to 200: 517
Line 1,103:
=={{header|C++}}==
{{Works with|C++11}}
<langsyntaxhighlight lang="cpp">#include <algorithm>
#include <cmath>
#include <iostream>
Line 1,188:
std::cout << area(*it) << '\t' << perimeter(*it) << "\t\t" <<
it->a << 'x' << it->b << 'x' << it->c << '\n';
}</langsyntaxhighlight>
{{out}}
<pre>There are 517 primitive Heronian triangles with sides up to 200
Line 1,216:
=={{header|CoffeeScript}}==
{{trans|JavaScript}}
<langsyntaxhighlight lang="coffeescript">heronArea = (a, b, c) ->
s = (a + b + c) / 2
Math.sqrt s * (s - a) * (s - b) * (s - c)
Line 1,262:
for i in list
if i[4] == 210
console.log i[0..2].join(' x ') + ', p = ' + i[3]</langsyntaxhighlight>
{{out}}
<pre>primitive Heronian triangles with sides up to 200: 517
Line 1,287:
=={{header|D}}==
{{trans|Python}}
<langsyntaxhighlight lang="d">import std.stdio, std.math, std.range, std.algorithm, std.numeric, std.traits, std.typecons;
 
double hero(in uint a, in uint b, in uint c) pure nothrow @safe @nogc {
Line 1,331:
"\nAll with area 210 subject to the previous ordering:".writeln;
showTriangles(h.filter!(t => t[].hero == 210));
}</langsyntaxhighlight>
{{out}}
<pre>Primitive Heronian triangles with sides up to 200: 517
Line 1,360:
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang="scheme">
;; returns quintuple (A s a b c)
;; or #f if not hero
Line 1,386:
(define (print-laurels H)
(writeln '🌿🌿 (length H) 'heroes '🌿🌿))
</syntaxhighlight>
</lang>
{{out}}
<pre>(define H (heroes))
Line 1,416:
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">defmodule Heronian do
def triangle?(a,b,c) when a+b <= c, do: false
def triangle?(a,b,c) do
Line 1,451:
|> Enum.each(fn {a, b, c} ->
IO.puts "#{a}\t#{b}\t#{c}\t#{a+b+c}\t#{area_size}"
end)</langsyntaxhighlight>
 
{{out}}
Line 1,476:
 
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
<lang ERRE>
PROGRAM HERON
 
Line 1,544:
END FOR
END PROGRAM
</syntaxhighlight>
</lang>
<pre>Number of triangles: 517
3 4 5 12 6
Line 1,565:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: accessors assocs backtrack combinators.extras
combinators.short-circuit formatting io kernel locals math
math.functions math.order math.parser math.ranges mirrors qw
Line 1,626:
[ first10 nl ] [ area210= ] bi ;
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 1,658:
=={{header|Fortran}}==
Earlier Fortran doesn't offer special functions such as SUM, PRODUCT and MAXVAL of arrays, nor the ability to create compound data aggregates such as STASH to store a triangle's details. Simple code would have to be used in the absence of such conveniences, and multiple ordinary arrays rather than an array of a compound data entity. Rather than attempt to create the candidate triangles in the desired order, the simple approach is to sort a list of triangles, and using an XNDX array evades tossing compound items about. Rather than create a procedure to do the sorting, a comb sort is not too much trouble to place in-line once. Further, since the ordering is based on a compound key, having only one comparison to code is a boon. The three-way-if statement is central to the expedient evaluation of a compound sort key, but this facility is deprecated by the modernists, with no alternative offered that avoids re-comparison of parts.
<syntaxhighlight lang="fortran">
<lang Fortran>
MODULE GREEK MATHEMATICIANS !Two millenia back and more.
CONTAINS
Line 1,766:
END DO !Just thump through the lot.
END
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,791:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' version 02-05-2016
' compile with: fbc -s console
 
Line 1,937:
Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre>There are 517 Heronian triangles with sides <= 200
Line 1,969:
 
=={{header|FutureBasic}}==
<langsyntaxhighlight lang="futurebasic">
include "ConsoleWindow"
 
Line 2,056:
end if
next
</syntaxhighlight>
</lang>
 
Output:
Line 2,087:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 2,156:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>Number of primitive Heronian triangles with sides up to 200: 517
Line 2,183:
 
=={{header|Haskell}}==
<langsyntaxhighlight Haskelllang="haskell">import qualified Data.List as L
import Data.Maybe
import Data.Ord
Line 2,245:
mapM_ printTri $ take 10 tris
putStrLn ""
mapM_ printTri $ filter ((== 210) . fifth) tris</langsyntaxhighlight>
{{out}}
<pre>Heronian triangles found: 517
Line 2,272:
'''Hero's formula Implementation'''
 
<langsyntaxhighlight Jlang="j">a=: 0&{"1
b=: 1&{"1
c=: 2&{"1
Line 2,278:
area=: 2 %: s*(s-a)*(s-b)*(s-c) NB. Hero's formula
perim=: +/"1
isPrimHero=: (0&~: * (= <.@:+))@area * 1 = a +. b +. c</langsyntaxhighlight>
 
We exclude triangles with zero area, triangles with complex area, non-integer area, and triangles whose sides share a common integer multiple.
Line 2,286:
The implementation above uses the symbols as given in the formula at the top of the page, making it easier to follow along as well as spot any errors. That formula distinguishes between the individual sides of the triangles but J could easily treat these sides as a single entity or array. The implementation below uses this "typical J" approach:
 
<langsyntaxhighlight Jlang="j">perim=: +/"1
s=: -:@:perim
area=: [: %: s * [: */"1 s - ] NB. Hero's formula
isNonZeroInt=: 0&~: *. (= <.@:+)
isPrimHero=: isNonZeroInt@area *. 1 = +./&.|:</langsyntaxhighlight>
 
'''Required examples'''
 
<langsyntaxhighlight Jlang="j"> Tri=:(1-i.3)+"1]3 comb 202 NB. distinct triangles with sides <= 200
HeroTri=: (#~ isPrimHero) Tri NB. all primitive Heronian triangles with sides <= 200
 
Line 2,320:
17 28 39 _ 84 210
7 65 68 _ 140 210
3 148 149 _ 300 210</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">import java.util.ArrayList;
 
public class Heron {
Line 2,399:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>Number of primitive Heronian triangles with sides up to 200: 517
Line 2,429:
===Imperative===
 
<syntaxhighlight lang="javascript">
<lang JavaScript>
window.onload = function(){
var list = [];
Line 2,480:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>Primitive Heronian triangles with sides up to 200: 517
Line 2,517:
ES6 JavaScript introduces syntactic sugar for list comprehensions, but the list monad pattern can already be used in ES5 – indeed in any language which supports the use of higher-order functions.
 
<langsyntaxhighlight JavaScriptlang="javascript">(function (n) {
var chain = function (xs, f) { // Monadic bind/chain
Line 2,598:
) + '\n\n';
})(200);</langsyntaxhighlight>
 
{{out}}
Line 2,653:
=={{header|jq}}==
{{works with|jq|1.4}}
<langsyntaxhighlight lang="jq"># input should be an array of the lengths of the sides
def hero:
(add/2) as $s
Line 2,692:
( .[] | select( hero == 210 ) | "\(rjust(11)) \(add|rjust(3)) \(hero|rjust(4))" ) ;
 
task(200)</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang="sh">$ time jq -n -r -f heronian.jq
The number of primitive Heronian triangles with sides up to 200: 517
The first ten when ordered by increasing area, then perimeter, then maximum sides:
Line 2,715:
[17,28,39] 84 210
[7,65,68] 140 210
[3,148,149] 300 210</langsyntaxhighlight>
 
=={{header|Julia}}==
Line 2,721:
 
'''Types and Functions'''
<syntaxhighlight lang="julia">
<lang Julia>
type IntegerTriangle{T<:Integer}
a::T
Line 2,748:
σ^2 == t
end
</syntaxhighlight>
</lang>
 
'''Main'''
<syntaxhighlight lang="julia">
<lang Julia>
slim = 200
 
Line 2,785:
println(@sprintf "%6d %3d %3d %4d %4d" t.a t.b t.c t.σ t.p)
end
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,814:
=={{header|Kotlin}}==
{{trans|Scala}}
<langsyntaxhighlight lang="scala">import java.util.ArrayList
 
object Heron {
Line 2,877:
}
 
fun main(args: Array<String>) = Heron.run()</langsyntaxhighlight>
{{out}}
<pre>Number of primitive Heronian triangles with sides up to 200: 517
Line 2,904:
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">-- Returns the details of the Heronian Triangle with sides a, b, c or nil if it isn't one
local function tryHt( a, b, c )
local result
Line 2,964:
local t = ht[ htPos ];
if t.area == 210 then htPrint( t ) end
end</langsyntaxhighlight>
{{out}}
<pre>
Line 2,993:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
Line 3,015:
results // Length
Take[results, 10] // Dataset
Select[results, #["Area"] == 210 &] // Dataset</langsyntaxhighlight>
{{out}}
<pre>517
Line 3,040:
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import math, algorithm, lenientops, strformat, sequtils
 
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
Line 3,096:
echo Header
for t in list.filterIt(it.area == 210): echo t
</syntaxhighlight>
</lang>
{{out}}
<pre>Number of Heronian triangles: 517
Line 3,126:
=={{header|ooRexx}}==
Derived from REXX with some changes
<langsyntaxhighlight lang="rexx">/*REXX pgm generates primitive Heronian triangles by side length & area.*/
Call time 'R'
Numeric Digits 12
Line 3,263:
::requires rxmath library
::routine sqrt
Return rxCalcSqrt(arg(1),14)</langsyntaxhighlight>
{{out}}
<pre>517 primitive Heronian triangles found with side length up to 200 (inclusive).
Line 3,290:
=={{header|PARI/GP}}==
 
<langsyntaxhighlight lang="parigp">Heron(v)=my([a,b,c]=v); (a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c) \\ returns 16 times the squared area
is(a,b,c)=(a+b+c)%2==0 && gcd(a,gcd(b,c))==1 && issquare(Heron([a,b,c]))
v=List(); for(a=1,200,for(b=a+1,200,for(c=b+1,200, if(is(a,b,c),listput(v, [a,b,c])))));
Line 3,300:
vecsort(u, (a,b)->Heron(a)-Heron(b))
vecsort(u, (a,b)->vecsum(a)-vecsum(b))
vecsort(u, 3) \\ shortcut: order by third component</langsyntaxhighlight>
{{out}}
<pre>%1 = [[1, 2, 3], [1, 3, 4], [1, 4, 5], [1, 5, 6], [1, 6, 7], [1, 7, 8], [1, 8, 9], [1, 9, 10], [1, 10, 11], [1, 11, 12]]
Line 3,311:
=={{header|Pascal}}==
{{Trans|Lua}}
<langsyntaxhighlight lang="pascal">program heronianTriangles ( input, output );
type
(* record to hold details of a Heronian triangle *)
Line 3,411:
if t^.area = 210 then htPrint( t )
end
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 3,441:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use List::Util qw(max);
Line 3,503:
}
 
&main();</langsyntaxhighlight>
{{out}}
<pre>Primitive Heronian triangles with sides up to 200: 517
Line 3,528:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #008080;">function</span> <span style="color: #000000;">heroArea</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">+</span><span style="color: #000000;">b</span><span style="color: #0000FF;">+</span><span style="color: #000000;">c</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">2</span>
Line 3,567:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 3,596:
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">
function Get-Gcd($a, $b){
if($a -ge $b){
Line 3,644:
}
}
</syntaxhighlight>
</lang>
{{out}}
<syntaxhighlight lang="text">
Primitive Heronian triangles with sides up to 200: 517
 
Line 3,670:
7 65 68 140 210
3 148 149 300 210
</syntaxhighlight>
</lang>
 
=={{header|Python}}==
 
<langsyntaxhighlight lang="python">from __future__ import division, print_function
from math import gcd, sqrt
 
Line 3,718:
% (sides, sum(sides), hero(*sides)) for sides in h
if hero(*sides) == 210))
</syntaxhighlight>
</lang>
{{out}}
<pre>Primitive Heronian triangles with sides up to 200: 517
Line 3,746:
Mostly adopted from Python implementation:
 
<syntaxhighlight lang="r">
<lang R>
area <- function(a, b, c) {
s = (a + b + c) / 2
Line 3,783:
cat("Showing the first ten ordered first by perimeter, then by area:\n")
print(head(r[order(x=r[,"perimeter"],y=r[,"area"]),],n=10))
</syntaxhighlight>
</lang>
 
{{out}}
 
<syntaxhighlight lang="text">There are 517 Heronian triangles up to a maximal side length of 200.
Showing the first ten ordered first by perimeter, then by area:
a b c perimeter area
Line 3,799:
[8,] 8 15 17 40 60
[9,] 7 15 20 42 42
[10,] 13 14 15 42 84</langsyntaxhighlight>
 
=={{header|Racket}}==
 
<syntaxhighlight lang="text">#lang at-exp racket
(require data/order scribble/html)
 
Line 3,847:
@; Show a similar ordered table for those triangles with area = 210
@(triangles->table (tri-sort (filter (λ(t) (eq? 210 (car t))) ts)))
}))</langsyntaxhighlight>
 
This program generates HTML, so the output is inline with the page, not in a <code>&lt;pre></code> block.
Line 3,880:
(formerly Perl 6)
{{works with|Rakudo|2018.09}}
<syntaxhighlight lang="raku" perl6line>sub hero($a, $b, $c) {
my $s = ($a + $b + $c) / 2;
($s * ($s - $a) * ($s - $b) * ($s - $c)).sqrt;
Line 3,922:
say "\nArea $witharea:";
show @h.grep: *[0] == $witharea;
}</langsyntaxhighlight>
{{out}}
<pre>Primitive Heronian triangles with sides up to 200: 517
Line 3,978:
This REXX version doesn't need to explicitly sort the triangles as they are listed in the proper order.
<langsyntaxhighlight lang="rexx">/*REXX program generates & displays primitive Heronian triangles by side length and area*/
parse arg N first area . /*obtain optional arguments from the CL*/
if N=='' | N=="," then N= 200 /*Not specified? Then use the default.*/
Line 4,030:
end /*k*/
end /*j*/ /* [↑] use the known perimeters. */
end /*i*/; return /* [↑] show any found triangles. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 4,065:
 
It is about eight times faster than the 1<sup>st</sup> REXX version.
<langsyntaxhighlight lang="rexx">/*REXX program generates & displays primitive Heronian triangles by side length and area*/
parse arg N first area . /*obtain optional arguments from the CL*/
if N=='' | N=="," then N= 200 /*Not specified? Then use the default.*/
Line 4,110:
end /*k*/
end /*j*/ /* [↑] use the known perimeters. */
end /*i*/; return /* [↑] show any found triangles. */</langsyntaxhighlight>
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version.}} <br><br>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Heronian triangles
 
Line 4,155:
end
return gcd
</syntaxhighlight>
</lang>
Output:
<pre>
Line 4,183:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">class Triangle
def self.valid?(a,b,c) # class method
short, middle, long = [a, b, c].sort
Line 4,228:
puts sorted.first(10).map(&:to_s)
puts "\nTriangles with an area of: #{area}"
sorted.each{|tr| puts tr if tr.area == area}</langsyntaxhighlight>
{{out}}
<pre>
Line 4,255:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">
use num_integer::Integer;
use std::{f64, usize};
Line 4,323:
}
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,350:
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">object Heron extends scala.collection.mutable.MutableList[Seq[Int]] with App {
private final val n = 200
for (c <- 1 to n; b <- 1 to c; a <- 1 to b if gcd(gcd(a, b), c) == 1) {
Line 4,384:
private final val header = "\nSides Perimeter Area"
private def format: Seq[Int] => String = "\n%3d x %3d x %3d %5d %10d".format
}</langsyntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="ruby">class Triangle(a, b, c) {
 
has (sides, perimeter, area)
Line 4,435:
say sorted.first(10).join("\n")
say "\nTriangles with an area of: #{area}"
sorted.each{|tr| say tr if (tr.area == area)}</langsyntaxhighlight>
{{out}}
<pre>
Line 4,463:
=={{header|Smalltalk}}==
Works with Squeak 5.x
<langsyntaxhighlight Smalltalklang="smalltalk">perimeter := [:triangle | triangle reduce: #+].
 
squaredArea := [:triangle |
Line 4,503:
area210 do: tabulate.
 
Transcript flush.</langsyntaxhighlight>
{{out}}
<pre>
Line 4,532:
 
=={{header|SPL}}==
<langsyntaxhighlight lang="spl">h,t = getem(200)
#.sort(h,4,5,1,2,3)
#.output("There are ",t," Heronian triangles")
Line 4,564:
s = (a+b+c)/2
<= (s*(s-a)*(s-b)*(s-c))^0.5, s*2
.</langsyntaxhighlight>
{{out}}
<pre>
Line 4,591:
=={{header|Swift}}==
Works with Swift 1.2
<langsyntaxhighlight Swiftlang="swift">import Foundation
 
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
Line 4,644:
for t in triangles[0...9] {
println("\(t.s1)\t\(t.s2)\t\(t.s3)\t\t\(t.p)\t\t\(t.a)")
}</langsyntaxhighlight>
 
{{out}}
Line 4,667:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">
if {[info commands let] eq ""} {
 
Line 4,759:
sqlite3 db :memory:
main db
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,787:
 
=={{header|VBA}}==
{{trans|Phix}}<langsyntaxhighlight lang="vb">Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
Line 4,838:
End If
Next i
End Sub</langsyntaxhighlight>{{out}}
<pre>Primitive Heronian triangles with sides up to 200: 517 (of 1353400 tested)
 
Line 4,867:
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "/math" for Int, Nums
import "/sort" for Sort
import "/fmt" for Fmt
Line 4,916:
var sides = Fmt.swrite("$2d x $3d x $3d", t[0][0], t[0][1], t[0][2])
Fmt.print("$-14s $3d $3d $3d", sides, t[1], t[2], t[3])
}</langsyntaxhighlight>
 
{{out}}
Line 4,947:
=={{header|zkl}}==
{{trans|Python}}
<langsyntaxhighlight lang="zkl">fcn hero(a,b,c){ //--> area (float)
s,a2:=(a + b + c).toFloat()/2, s*(s - a)*(s - b)*(s - c);
(a2 > 0) and a2.sqrt() or 0.0
Line 4,954:
A:=hero(a,b,c);
(A>0) and A.modf()[1].closeTo(0.0,1.0e-6) and A //--> area or False
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">const MAX_SIDE=200;
heros:=Sink(List);
foreach a,b,c in ([1..MAX_SIDE],[a..MAX_SIDE],[b..MAX_SIDE]){
Line 4,976:
println("Area Perimeter Sides");
heros.filter(fcn([(h,_)]){ h==210 })
.pump(fcn(phabc){ "%3s %8d %3dx%dx%d".fmt(phabc.xplode()).println() });</langsyntaxhighlight>
{{out}}
<pre>
10,333

edits