Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
64
Task/Sort-three-variables/Ada/sort-three-variables.adb
Normal file
64
Task/Sort-three-variables/Ada/sort-three-variables.adb
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
with Ada.Text_IO;
|
||||
with Ada.Strings.Unbounded;
|
||||
|
||||
procedure Sort_Three is
|
||||
|
||||
generic
|
||||
type Element_Type is private;
|
||||
with function "<" (Left, Right : in Element_Type) return Boolean;
|
||||
procedure Generic_Sort (X, Y, Z : in out Element_Type);
|
||||
|
||||
procedure Generic_Sort (X, Y, Z : in out Element_Type)
|
||||
is
|
||||
procedure Swap (Left, Right : in out Element_Type) is
|
||||
T : constant Element_Type := Left;
|
||||
begin
|
||||
Left := Right;
|
||||
Right := T;
|
||||
end Swap;
|
||||
begin
|
||||
if Y < X then Swap (X, Y); end if;
|
||||
if Z < Y then Swap (Y, Z); end if;
|
||||
if Y < X then Swap (X, Y); end if;
|
||||
end Generic_Sort;
|
||||
|
||||
procedure Test_Unbounded_Sort is
|
||||
use Ada.Text_IO;
|
||||
use Ada.Strings.Unbounded;
|
||||
|
||||
X : Unbounded_String := To_Unbounded_String ("lions, tigers, and");
|
||||
Y : Unbounded_String := To_Unbounded_String ("bears, oh my!");
|
||||
Z : Unbounded_String := To_Unbounded_String ("(from the ""Wizard of OZ"")");
|
||||
|
||||
procedure Sort is
|
||||
new Generic_Sort (Unbounded_String, "<");
|
||||
begin
|
||||
Sort (X, Y, Z);
|
||||
Put_Line (To_String (X));
|
||||
Put_Line (To_String (Y));
|
||||
Put_Line (To_String (Z));
|
||||
New_Line;
|
||||
End Test_Unbounded_Sort;
|
||||
|
||||
procedure Test_Integer_Sort is
|
||||
|
||||
use Ada.Text_IO;
|
||||
|
||||
procedure Sort is
|
||||
new Generic_Sort (Integer, "<");
|
||||
|
||||
X : Integer := 77444;
|
||||
Y : Integer := -12;
|
||||
Z : Integer := 0;
|
||||
begin
|
||||
Sort (X, Y, Z);
|
||||
Put_Line (X'Image);
|
||||
Put_Line (Y'Image);
|
||||
Put_Line (Z'Image);
|
||||
New_Line;
|
||||
end Test_Integer_Sort;
|
||||
|
||||
begin
|
||||
Test_Unbounded_Sort;
|
||||
Test_Integer_Sort;
|
||||
end Sort_Three;
|
||||
43
Task/Sort-three-variables/COBOL/sort-three-variables.cob
Normal file
43
Task/Sort-three-variables/COBOL/sort-three-variables.cob
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
program-id. 3var.
|
||||
data division.
|
||||
working-storage section.
|
||||
1 n binary pic 9(4).
|
||||
1 num pic -(7)9.
|
||||
1 a1 pic x(32) value "lions, tigers, and".
|
||||
1 a2 pic x(32) value "bears, oh my!".
|
||||
1 a3 pic x(32) value "(from the ""Wizard of OZ"")".
|
||||
1 n1 pic x(8) value "77444".
|
||||
1 n2 pic x(8) value "-12".
|
||||
1 n3 pic x(8) value "0".
|
||||
1 alpha-table.
|
||||
2 alpha-entry occurs 3 pic x(32).
|
||||
1 numeric-table.
|
||||
2 numeric-entry occurs 3 pic s9(8).
|
||||
1 filler value "x = y = z = ".
|
||||
2 lead-in occurs 3 pic x(4).
|
||||
procedure division.
|
||||
begin.
|
||||
move a1 to alpha-entry (1)
|
||||
move a2 to alpha-entry (2)
|
||||
move a3 to alpha-entry (3)
|
||||
sort alpha-entry ascending alpha-entry
|
||||
perform varying n from 1 by 1
|
||||
until n > 3
|
||||
display lead-in (n) alpha-entry (n)
|
||||
end-perform
|
||||
|
||||
display space
|
||||
|
||||
compute numeric-entry (1) = function numval (n1)
|
||||
compute numeric-entry (2) = function numval (n2)
|
||||
compute numeric-entry (3) = function numval (n3)
|
||||
sort numeric-entry ascending numeric-entry
|
||||
perform varying n from 1 by 1
|
||||
until n > 3
|
||||
move numeric-entry (n) to num
|
||||
display lead-in (n) num
|
||||
end-perform
|
||||
|
||||
stop run
|
||||
.
|
||||
end program 3var.
|
||||
31
Task/Sort-three-variables/Logo/sort-three-variables.logo
Normal file
31
Task/Sort-three-variables/Logo/sort-three-variables.logo
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
;;; Sort 3 variables
|
||||
|
||||
to gt? :a :b
|
||||
if (and word? :a word? :b) [output before? :b :a]
|
||||
if (and number? :a number? :b) [output :a > :b]
|
||||
throw "ERROR
|
||||
end
|
||||
|
||||
to swap :v1 :v2 ; swaps the values of the variables whose names are :v1 and :v2
|
||||
make "t thing :v1
|
||||
make :v1 thing :v2
|
||||
make :v2 :t
|
||||
end
|
||||
|
||||
to sort3 :v1 :v2 :v3 ; sorts the variables whose names are :v1, :v2 and :v3
|
||||
if gt? thing :v1 thing :v2 [swap :v1 :v2]
|
||||
if gt? thing :v1 thing :v3 [swap :v1 :v3]
|
||||
if gt? thing :v2 thing :v3 [swap :v2 :v3]
|
||||
end
|
||||
|
||||
make "a "lions,\ tigers,\ and
|
||||
make "b "bears,\ oh\ my!
|
||||
make "c "\(from\ the\ \"Wizard\ of\ OZ\"\)
|
||||
sort3 "a "b "c
|
||||
print :a print :b print :c
|
||||
|
||||
make "a 77444
|
||||
make "b -12
|
||||
make "c 0
|
||||
sort3 "a "b "c
|
||||
print :a print :b print :c
|
||||
14
Task/Sort-three-variables/R/sort-three-variables.r
Normal file
14
Task/Sort-three-variables/R/sort-three-variables.r
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
assignVec <- Vectorize("assign", c("x", "value"))
|
||||
`%<<-%` <- function(x, value) invisible(assignVec(x, value, envir = .GlobalEnv)) # define multiple global assignments operator
|
||||
|
||||
x <- 'lions, tigers, and'
|
||||
y <- 'bears, oh my!'
|
||||
z <- '(from the "Wizard of OZ")'
|
||||
|
||||
c("x", "y", "z") %<<-% sort(c(x, y, z))
|
||||
|
||||
x <- 77444
|
||||
y <- -12
|
||||
z <- 0
|
||||
|
||||
c("x", "y", "z") %<<-% sort(c(x, y, z))
|
||||
Loading…
Add table
Add a link
Reference in a new issue