Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,18 +0,0 @@
|
|||
with Ada.Containers.Vectors;
|
||||
|
||||
generic
|
||||
type Index_Type is range <>;
|
||||
type Element_Type is private;
|
||||
Zero : Element_Type;
|
||||
with function "+" (Left, Right : Element_Type) return Element_Type is <>;
|
||||
with function "-" (Left, Right : Element_Type) return Element_Type is <>;
|
||||
with function "=" (Left, Right : Element_Type) return Boolean is <>;
|
||||
type Array_Type is private;
|
||||
with function Element (From : Array_Type; Key : Index_Type) return Element_Type is <>;
|
||||
package Equilibrium is
|
||||
package Index_Vectors is new Ada.Containers.Vectors
|
||||
(Index_Type => Positive, Element_Type => Index_Type);
|
||||
|
||||
function Get_Indices (From : Array_Type) return Index_Vectors.Vector;
|
||||
|
||||
end Equilibrium;
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
package body Equilibrium is
|
||||
|
||||
function Get_Indices (From : Array_Type) return Index_Vectors.Vector is
|
||||
Result : Index_Vectors.Vector;
|
||||
Right_Sum, Left_Sum : Element_Type := Zero;
|
||||
begin
|
||||
for Index in Index_Type'Range loop
|
||||
Right_Sum := Right_Sum + Element (From, Index);
|
||||
end loop;
|
||||
for Index in Index_Type'Range loop
|
||||
Right_Sum := Right_Sum - Element (From, Index);
|
||||
if Left_Sum = Right_Sum then
|
||||
Index_Vectors.Append (Result, Index);
|
||||
end if;
|
||||
Left_Sum := Left_Sum + Element (From, Index);
|
||||
end loop;
|
||||
return Result;
|
||||
end Get_Indices;
|
||||
|
||||
end Equilibrium;
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
with Equilibrium;
|
||||
with Ada.Containers.Vectors;
|
||||
|
||||
procedure Main is
|
||||
subtype Index_Type is Positive range 1 .. 7;
|
||||
package Vectors is new Ada.Containers.Vectors
|
||||
(Element_Type => Integer, Index_Type => Index_Type);
|
||||
type Plain_Array is array (Index_Type) of Integer;
|
||||
function Element (From : Plain_Array; Key : Index_Type) return Integer is
|
||||
begin
|
||||
return From (Key);
|
||||
end Element;
|
||||
|
||||
package Vector_Equilibrium is new Equilibrium
|
||||
(Index_Type => Index_Type,
|
||||
Element_Type => Integer,
|
||||
Zero => 0,
|
||||
Array_Type => Vectors.Vector,
|
||||
Element => Vectors.Element);
|
||||
package Array_Equilibrium is new Equilibrium
|
||||
(Index_Type => Index_Type,
|
||||
Element_Type => Integer,
|
||||
Zero => 0,
|
||||
Array_Type => Plain_Array);
|
||||
|
||||
My_Vector : Vectors.Vector;
|
||||
My_Array : Plain_Array := (-7, 1, 5, 2, -4, 3, 0);
|
||||
Vector_Result : Vector_Equilibrium.Index_Vectors.Vector;
|
||||
Array_Result : Array_Equilibrium.Index_Vectors.Vector :=
|
||||
Array_Equilibrium.Get_Indices (My_Array);
|
||||
begin
|
||||
Vectors.Append (My_Vector, -7);
|
||||
Vectors.Append (My_Vector, 1);
|
||||
Vectors.Append (My_Vector, 5);
|
||||
Vectors.Append (My_Vector, 2);
|
||||
Vectors.Append (My_Vector, -4);
|
||||
Vectors.Append (My_Vector, 3);
|
||||
Vectors.Append (My_Vector, 0);
|
||||
Vector_Result := Vector_Equilibrium.Get_Indices (My_Vector);
|
||||
Ada.Text_IO.Put_Line ("Results:");
|
||||
Ada.Text_IO.Put ("Array: ");
|
||||
for I in Array_Result.First_Index .. Array_Result.Last_Index loop
|
||||
Ada.Text_IO.Put (Integer'Image (Array_Equilibrium.Index_Vectors.Element (Array_Result, I)));
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
Ada.Text_IO.Put ("Vector: ");
|
||||
for I in Vector_Result.First_Index .. Vector_Result.Last_Index loop
|
||||
Ada.Text_IO.Put (Integer'Image (Vector_Equilibrium.Index_Vectors.Element (Vector_Result, I)));
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
end Main;
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Equilibrium is
|
||||
|
||||
type Integer_Sequence is array (Positive range <>) of Integer;
|
||||
function Seq_Img (From : Integer_Sequence) return String is
|
||||
begin
|
||||
if From'First /= From'Last then
|
||||
return " " & Integer'Image (From (From'First)) &
|
||||
Seq_Img (From (From'First + 1 .. From'Last));
|
||||
else
|
||||
return " " & Integer'Image (From (From'First));
|
||||
end if;
|
||||
end Seq_Img;
|
||||
|
||||
type Boolean_Sequence is array (Positive range <>) of Boolean;
|
||||
function Seq_Img (From : Boolean_Sequence) return String is
|
||||
begin
|
||||
if From'First > From'Last then
|
||||
return "";
|
||||
end if;
|
||||
if From (From'First) then
|
||||
return Integer'Image (From'First) &
|
||||
Seq_Img (From (From'First + 1 .. From'Last));
|
||||
else
|
||||
return Seq_Img (From (From'First + 1 .. From'Last));
|
||||
end if;
|
||||
end Seq_Img;
|
||||
|
||||
function Get_Indices (From : Integer_Sequence) return Boolean_Sequence is
|
||||
Result : Boolean_Sequence (From'Range) := (others => False);
|
||||
Left_Sum, Right_Sum : Integer := 0;
|
||||
begin
|
||||
for Index in From'Range loop
|
||||
Right_Sum := Right_Sum + From (Index);
|
||||
end loop;
|
||||
for Index in From'Range loop
|
||||
Right_Sum := Right_Sum - From (Index);
|
||||
Result (Index) := Left_Sum = Right_Sum;
|
||||
Left_Sum := Left_Sum + From (Index);
|
||||
end loop;
|
||||
return Result;
|
||||
end Get_Indices;
|
||||
|
||||
X1 : Integer_Sequence := (-7, 1, 5, 2, -4, 3, 0);
|
||||
X1_Result : Boolean_Sequence := Get_Indices (X1);
|
||||
X2 : Integer_Sequence := ( 2, 4, 6);
|
||||
X2_Result : Boolean_Sequence := Get_Indices (X2);
|
||||
X3 : Integer_Sequence := ( 2, 9, 2);
|
||||
X3_Result : Boolean_Sequence := Get_Indices (X3);
|
||||
X4 : Integer_Sequence := ( 1, -1, 1, -1, 1 ,-1, 1);
|
||||
X4_Result : Boolean_Sequence := Get_Indices (X4);
|
||||
|
||||
begin
|
||||
Ada.Text_IO.Put_Line ("Results:");
|
||||
Ada.Text_IO.New_Line;
|
||||
Ada.Text_IO.Put_Line ("X1:" & Seq_Img (X1));
|
||||
Ada.Text_IO.Put_Line ("Eqs:" & Seq_Img (X1_Result));
|
||||
Ada.Text_IO.New_Line;
|
||||
Ada.Text_IO.Put_Line ("X2:" & Seq_Img (X2));
|
||||
Ada.Text_IO.Put_Line ("Eqs:" & Seq_Img (X2_Result));
|
||||
Ada.Text_IO.New_Line;
|
||||
Ada.Text_IO.Put_Line ("X3:" & Seq_Img (X3));
|
||||
Ada.Text_IO.Put_Line ("Eqs:" & Seq_Img (X3_Result));
|
||||
Ada.Text_IO.New_Line;
|
||||
Ada.Text_IO.Put_Line ("X4:" & Seq_Img (X4));
|
||||
Ada.Text_IO.Put_Line ("Eqs:" & Seq_Img (X4_Result));
|
||||
end Equilibrium;
|
||||
|
|
@ -2,7 +2,7 @@ eqIndex: function [row][
|
|||
suml: 0
|
||||
delayed: 0
|
||||
sumr: sum row
|
||||
result: new []
|
||||
result: []
|
||||
loop.with:'i row 'r [
|
||||
suml: suml + delayed
|
||||
sumr: sumr - r
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
func[] equind a[] .
|
||||
for v in a[]
|
||||
sumr += v
|
||||
.
|
||||
for v in a[] : sumr += v
|
||||
for i to len a[]
|
||||
sumr -= a[i]
|
||||
if suml = sumr
|
||||
r[] &= i
|
||||
.
|
||||
if suml = sumr : r[] &= i
|
||||
suml += a[i]
|
||||
.
|
||||
return r[]
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class EquilibriumEnumerator : Enumerator
|
|||
enumerable() => en;
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
EquilibriumEnumerator.new(new int[]{ -7, 1, 5, 2, -4, 3, 0 })
|
||||
.forEach(PrintingLn)
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
function equilibrium(sequence s)
|
||||
integer lower_sum, higher_sum
|
||||
sequence indices
|
||||
lower_sum = 0
|
||||
higher_sum = 0
|
||||
for i = 1 to length(s) do
|
||||
higher_sum += s[i]
|
||||
end for
|
||||
indices = {}
|
||||
for i = 1 to length(s) do
|
||||
higher_sum -= s[i]
|
||||
if lower_sum = higher_sum then
|
||||
indices &= i
|
||||
end if
|
||||
lower_sum += s[i]
|
||||
end for
|
||||
return indices
|
||||
end function
|
||||
|
||||
? equilibrium({-7,1,5,2,-4,3,0})
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
function equindex2pass(data::Array)
|
||||
rst = Vector{Int}(0)
|
||||
rst = Int[]
|
||||
suml, sumr, ddelayed = 0, sum(data), 0
|
||||
for (i, d) in enumerate(data)
|
||||
suml += ddelayed
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
fun equilibriumIndices(a: IntArray): MutableList<Int> {
|
||||
val ei = mutableListOf<Int>()
|
||||
if (a.isEmpty()) return ei // empty list
|
||||
val sumAll = a.sumBy { it }
|
||||
val sumAll = a.sumOf { it }
|
||||
var sumLeft = 0
|
||||
var sumRight: Int
|
||||
for (i in 0 until a.size) {
|
||||
|
|
|
|||
|
|
@ -1,18 +1,23 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">equilibrium</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">lower_sum</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">higher_sum</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">higher_sum</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">lower_sum</span><span style="color: #0000FF;">=</span><span style="color: #000000;">higher_sum</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000000;">res</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">i</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #000000;">lower_sum</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">s</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>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
with javascript_semantics
|
||||
function equilibrium(sequence s)
|
||||
atom lower_sum = 0,
|
||||
higher_sum = sum(s)
|
||||
sequence res = {}
|
||||
for i,si in s do
|
||||
higher_sum -= si
|
||||
if lower_sum=higher_sum then
|
||||
res &= i
|
||||
end if
|
||||
lower_sum += si
|
||||
end for
|
||||
return res
|
||||
end function
|
||||
|
||||
<span style="color: #0000FF;">?</span><span style="color: #000000;">equilibrium</span><span style="color: #0000FF;">({-</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">})</span>
|
||||
<!--
|
||||
constant tests = {{-7,1,5,2,-4,3,0},
|
||||
{2,4,6},{2,9,2},
|
||||
{1,-1,1,-1,1,-1,1},
|
||||
{1},{}}
|
||||
printf(1,"The equilibrium indices for the following sequences are:\n")
|
||||
for t in tests do
|
||||
printf(1,"%24v -> %v\n", {t,equilibrium(t)})
|
||||
end for
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
function Get-EquilibriumIndex ( $Sequence )
|
||||
{
|
||||
$Indexes = 0..($Sequence.Count - 1)
|
||||
$EqulibriumIndex = @()
|
||||
|
||||
ForEach ( $TestIndex in $Indexes )
|
||||
{
|
||||
$Left = 0
|
||||
$Right = 0
|
||||
ForEach ( $Index in $Indexes )
|
||||
{
|
||||
If ( $Index -lt $TestIndex ) { $Left += $Sequence[$Index] }
|
||||
ElseIf ( $Index -gt $TestIndex ) { $Right += $Sequence[$Index] }
|
||||
}
|
||||
|
||||
If ( $Left -eq $Right )
|
||||
{
|
||||
$EqulibriumIndex += $TestIndex
|
||||
}
|
||||
}
|
||||
return $EqulibriumIndex
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
Get-EquilibriumIndex -7, 1, 5, 2, -4, 3, 0
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
let arr = [-7, 1, 5, 2, -4, 3, 0]
|
||||
let sum = Js.Array2.reduce(arr, \"+", 0)
|
||||
let len = Js.Array.length(arr)
|
||||
|
||||
let rec aux = (acc, i, left, right) => {
|
||||
if (i >= len) { acc } else {
|
||||
let x = arr[i]
|
||||
let right = right - x
|
||||
if (left == right) {
|
||||
let _ = Js.Array2.push(acc, i)
|
||||
}
|
||||
aux(acc, i+1, (left + x), right)
|
||||
}
|
||||
}
|
||||
let res = aux([], 0, 0, sum)
|
||||
Js.log("Results:")
|
||||
Js.Array2.forEach(res, Js.log)
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
arr = Array(-7,1,5,2,-4,3,0)
|
||||
WScript.StdOut.Write equilibrium(arr,UBound(arr))
|
||||
WScript.StdOut.WriteLine
|
||||
|
||||
Function equilibrium(arr,n)
|
||||
sum = 0
|
||||
leftsum = 0
|
||||
'find the sum of the whole array
|
||||
For i = 0 To UBound(arr)
|
||||
sum = sum + arr(i)
|
||||
Next
|
||||
For i = 0 To UBound(arr)
|
||||
sum = sum - arr(i)
|
||||
If leftsum = sum Then
|
||||
equilibrium = equilibrium & i & ", "
|
||||
End If
|
||||
leftsum = leftsum + arr(i)
|
||||
Next
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue