From 6e11131ca35e6963e110add882b55c648e20d9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Mon, 30 Dec 2024 10:25:10 +0100 Subject: [PATCH 01/19] Create loopy Add PL/I code identical to the COBOL pendant. --- loops/PL1/loopy | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 loops/PL1/loopy diff --git a/loops/PL1/loopy b/loops/PL1/loopy new file mode 100644 index 00000000..2637c17a --- /dev/null +++ b/loops/PL1/loopy @@ -0,0 +1,37 @@ + loopy: proc options(main); + + declare input_number fixed dec(5) init(0); + declare random_number fixed dec(6) init(0); + declare 1 array(1:10000), + element fixed bin(31) init(0); + declare i fixed dec(5) init(1); + declare j fixed dec(6) init(1); + declare modulo_result fixed bin(15); + declare element_result fixed bin(31); + + /* Get an input number from the standard input */ + get list(input_number); + + /* Get a random number 0 <= r < 10k */ + random_number = random() * 10000; + + /* 10k outer loop iterations */ + do i = 1 to 10000; + /* 100k inner loop iterations, per outer loop iteration */ + do j = 1 to 100000; + /* Simple sum */ + array(i).element = mod(j, input_number); + end; + /* Add a random value to each element in array */ + array(i).element = array(i).element + random_number; + end; + + /* Move an element from the array to a variable */ + element_result = array(random_number + 1).element; + + /* Print out a single element from the array */ + put skip data(element_result); + + stop; + + end loopy; From 9f89bd64bb914297852ee88b14177d25571b11fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Thu, 9 Jan 2025 15:41:01 +0100 Subject: [PATCH 02/19] Update loopy This version was compiled and tested by the "official" compile and run scripts. --- loops/PL1/loopy | 70 +++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/loops/PL1/loopy b/loops/PL1/loopy index 2637c17a..86b304d2 100644 --- a/loops/PL1/loopy +++ b/loops/PL1/loopy @@ -1,37 +1,33 @@ - loopy: proc options(main); - - declare input_number fixed dec(5) init(0); - declare random_number fixed dec(6) init(0); - declare 1 array(1:10000), - element fixed bin(31) init(0); - declare i fixed dec(5) init(1); - declare j fixed dec(6) init(1); - declare modulo_result fixed bin(15); - declare element_result fixed bin(31); - - /* Get an input number from the standard input */ - get list(input_number); - - /* Get a random number 0 <= r < 10k */ - random_number = random() * 10000; - - /* 10k outer loop iterations */ - do i = 1 to 10000; - /* 100k inner loop iterations, per outer loop iteration */ - do j = 1 to 100000; - /* Simple sum */ - array(i).element = mod(j, input_number); - end; - /* Add a random value to each element in array */ - array(i).element = array(i).element + random_number; - end; - - /* Move an element from the array to a variable */ - element_result = array(random_number + 1).element; - - /* Print out a single element from the array */ - put skip data(element_result); - - stop; - - end loopy; +loopy: proc(parms) options(main); + dcl parms char(100) var; + dcl u fixed bin(31); /*parameter value in fixed bin*/ + dcl r fixed bin(31); /* a random value 0001-9999 */ + dcl (i,j,m) fixed bin(31); + dcl a(10000) fixed bin(31); + dcl sysprint file stream output; + + u = parms; + r = randomm(); + do i = 1 to 10000; + a(i) = 0; + do j = 1 to 100000; + m = mod(j,u); + a(i) = a(i) + m; + end; + a(i) = a(i) + r; + end; + put file(sysprint) skip edit(a(r))(f(8)); + close file(sysprint); + + randomm: proc; + /* a somewhat dummy random number generator */ + dcl ts char(15) var; + dcl rand char(4); + dcl randi fixed bin(15); + + ts = time(); + rand = substr(ts,6,4); + randi = rand; + return(randi); + end randomm; +end; From 66a44bba2b89011c34069528392b7f871479fd57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Thu, 9 Jan 2025 17:35:31 +0100 Subject: [PATCH 03/19] Update and rename loopy to code.pli --- loops/PL1/{loopy => code.pli} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename loops/PL1/{loopy => code.pli} (96%) diff --git a/loops/PL1/loopy b/loops/PL1/code.pli similarity index 96% rename from loops/PL1/loopy rename to loops/PL1/code.pli index 86b304d2..51d11a17 100644 --- a/loops/PL1/loopy +++ b/loops/PL1/code.pli @@ -1,4 +1,4 @@ -loopy: proc(parms) options(main); +code: proc(parms) options(main); dcl parms char(100) var; dcl u fixed bin(31); /*parameter value in fixed bin*/ dcl r fixed bin(31); /* a random value 0001-9999 */ From a1310380ed1fa3fb537fe4376c0c571c252614d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Thu, 9 Jan 2025 17:50:47 +0100 Subject: [PATCH 04/19] Create hello.pli --- loops/PL1/hello.pli | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 loops/PL1/hello.pli diff --git a/loops/PL1/hello.pli b/loops/PL1/hello.pli new file mode 100644 index 00000000..bb6defa7 --- /dev/null +++ b/loops/PL1/hello.pli @@ -0,0 +1,3 @@ +hello: proc options(main); + put skip list("Hello World!"); +end hello; From 208dc693d8ff01aaedb7d1792fd3dd783a7fc032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Fri, 10 Jan 2025 18:26:58 +0100 Subject: [PATCH 05/19] Create code.pli --- hello-world/PL1/code.pli | 1 + 1 file changed, 1 insertion(+) create mode 100644 hello-world/PL1/code.pli diff --git a/hello-world/PL1/code.pli b/hello-world/PL1/code.pli new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/hello-world/PL1/code.pli @@ -0,0 +1 @@ + From 8ed7f6b57eae455fe04e067f91147689ed518408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Fri, 10 Jan 2025 18:29:15 +0100 Subject: [PATCH 06/19] Create code.pli --- hello-world/PL1/code.pli | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hello-world/PL1/code.pli b/hello-world/PL1/code.pli index 8b137891..289a2594 100644 --- a/hello-world/PL1/code.pli +++ b/hello-world/PL1/code.pli @@ -1 +1,3 @@ - +hello: proc options(main); + put skip list("Hello World!"); +end hello; From 742fbb9eb98db9e7143614a7152f60444cd86547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Fri, 10 Jan 2025 18:35:15 +0100 Subject: [PATCH 07/19] Delete loops/PL1/hello.pli Removed to hello-world --- loops/PL1/hello.pli | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 loops/PL1/hello.pli diff --git a/loops/PL1/hello.pli b/loops/PL1/hello.pli deleted file mode 100644 index bb6defa7..00000000 --- a/loops/PL1/hello.pli +++ /dev/null @@ -1,3 +0,0 @@ -hello: proc options(main); - put skip list("Hello World!"); -end hello; From 2cabb706198a93c43b04accab042d9a8254d8380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Mon, 13 Jan 2025 09:29:32 +0100 Subject: [PATCH 08/19] Update code.pli Single apostrophes are more common as delimiter. --- hello-world/PL1/code.pli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hello-world/PL1/code.pli b/hello-world/PL1/code.pli index 289a2594..45707a25 100644 --- a/hello-world/PL1/code.pli +++ b/hello-world/PL1/code.pli @@ -1,3 +1,3 @@ hello: proc options(main); - put skip list("Hello World!"); + put skip list('Hello World!'); end hello; From 40ec95ca3afeadb0f1828278d84e45bbd0e7cf9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Sun, 26 Jan 2025 16:32:55 +0100 Subject: [PATCH 09/19] Create code.pli = PL/I code to execute the Levenshtein algorithm --- levenshtein/pl1/code.pli | 1 + 1 file changed, 1 insertion(+) create mode 100644 levenshtein/pl1/code.pli diff --git a/levenshtein/pl1/code.pli b/levenshtein/pl1/code.pli new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/levenshtein/pl1/code.pli @@ -0,0 +1 @@ + From 9e519caf2a9befa6e2ec28898e4b8254e2dfb064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Sun, 26 Jan 2025 16:37:14 +0100 Subject: [PATCH 10/19] Create leven1 PL/I code under filename code.pli --- levenshtein/pl1/code.pli | 155 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/levenshtein/pl1/code.pli b/levenshtein/pl1/code.pli index 8b137891..2bb92cee 100644 --- a/levenshtein/pl1/code.pli +++ b/levenshtein/pl1/code.pli @@ -1 +1,156 @@ + leven1: procedure(parm1) options(main); + dcl parm1 char(100) varying; /* for future use */ + dcl (s1, s2) char(300) varying; /*adjust lngt as needed*/ + dcl (m, n, i, j, k, ctr) fixed bin(31) init(0); + dcl (cost, min_distance, act_distance) + fixed bin(31); + dcl distance(0:256,0:256) fixed bin(31); + dcl comparisons fixed bin(31); + dcl prev(0:300) fixed bin(31); + dcl curr(0:300) fixed bin(31); + dcl arg(100) char(300) varying; + dcl arg_count fixed bin(31) init(0); + dcl (in_string,eof) bit(1) init('0'b); + dcl sysprint file stream output; + + /* declarations to read parameter from input file */ + dcl infil file record input env(v recsize(3000) lf); + dcl parm char(3000); + dcl (pos, + start, + len, + index, + char_len) fixed bin(31); + + on subscriptrange begin; + on error system; + put skip list('subrg error!'); + put skip list('-----------'); + end; + + on error begin; + on error system; + put skip list('ONCODE value: ', oncode); + put list(''); + end; + + on endfile(infil) begin; + put skip list('EOF input,no parm defined!'); + stop; + end; + + /* get command line arguments: cut substrings from parm */ + open file(infil) title('input.txt'); + read file(infil) into(parm); + close file(infil); + parm = trim(parm); + index = 1; + pos = 1; + char_len = length(parm); + do while (pos < char_len); + /* skip leading spaces */ + do while (substr(parm, pos, 1) = ' ' & pos <= char_len); + pos = pos + 1; + end; + /* find the next substring */ + start = pos; + do while (substr(parm, pos, 1) > ' ' & pos <= char_len); + pos = pos + 1; + end; + /* extract the substring */ + len = pos - start; + if len > 0 then do; + arg(index) = substr(parm, start, len); + index = index + 1; + end; + /* skip trailing spaces before the next substring */ + do while (substr(parm, pos, 1) = ' ' & pos <= char_len); + pos = pos + 1; + end; + end; + + arg_count = index - 1; + /* check if enough input parameters */ + if arg_count < 2 then do; + put skip list('usage: program_name ...'); + return; + end; + + /* execute the algorithm for the input strings */ + min_distance = 2**30; /* equivalent to long.max_value */ + comparisons = 0; + do i = 1 to arg_count; + do j = 1 to arg_count; + if i = j + then + ; + else do; + s1 = arg(i); + s2 = arg(j); + act_distance = levendis(s1, s2); + min_distance = min(min_distance, act_distance); + comparisons = comparisons + 1; + end; + end; + end; + + /* print results in the form required by check.sh */ + put edit ('times: ' || trim(comparisons) || '0a'x || ' min_distance: ' || trim(min_distance)) + (a(30)); + + return; + + /* this function returns the levenshtein distance for two strings */ + levendis: procedure(s1, s2) returns (fixed bin(31)); + dcl (s1, s2) char(*) varying; + dcl temp char(100) varying; + dcl (m, n) fixed bin(31); + dcl (i, j, del, ins, sub) fixed bin(31); + dcl cost fixed bin(31); + dcl (prev(0:256), curr(0:256)) fixed bin(31); + dcl tempi fixed bin(31); + + /* Optimize by ensuring s1 is the shorter string */ + if length(s1) > length(s2) then do; + temp = s1; + s1 = s2; + s2 = temp; + end; + + m = length(s1); + n = length(s2); + + /* Initialize the first row */ + do j = 0 to m; + prev(j) = j; + end; + + /* Fill the matrix row by row */ + do i = 1 to n; + curr(0) = i; + do j = 1 to m; + /* Calculate cost */ + if substr(s1, j, 1) = substr(s2, i, 1) then + cost = 0; + else + cost = 1; + + del = prev(j); + ins = curr(j - 1); + sub = prev(j - 1); + curr(j) = min(min(del + 1, ins + 1), sub + cost); + end; + + /* Swap rows */ + do j = 0 to m; + tempi = prev(j); + prev(j) = curr(j); + curr(j) = tempi; + end; + end; + return(prev(m)); + end levendis; + + end leven1; + From 9ff2d0f1bed75dfe6b4d27615dc70ca00318bd68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Sun, 26 Jan 2025 16:50:18 +0100 Subject: [PATCH 11/19] Create code.pli in the pl1 subfolder --- hello-world/pl1/code.pli | 1 + 1 file changed, 1 insertion(+) create mode 100644 hello-world/pl1/code.pli diff --git a/hello-world/pl1/code.pli b/hello-world/pl1/code.pli new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/hello-world/pl1/code.pli @@ -0,0 +1 @@ + From 0755583a0ffe87453121952b1cf70fe42cb3187c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Sun, 26 Jan 2025 16:51:20 +0100 Subject: [PATCH 12/19] Update code.pli: create hello PL/I code --- hello-world/pl1/code.pli | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hello-world/pl1/code.pli b/hello-world/pl1/code.pli index 8b137891..45707a25 100644 --- a/hello-world/pl1/code.pli +++ b/hello-world/pl1/code.pli @@ -1 +1,3 @@ - +hello: proc options(main); + put skip list('Hello World!'); +end hello; From 855ea69c5787bb2c3d0b3626e47b423192c68ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Sun, 26 Jan 2025 16:52:15 +0100 Subject: [PATCH 13/19] Delete hello-world/PL1/code.pli New directory "pl1" created for the PL/I code --- hello-world/PL1/code.pli | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 hello-world/PL1/code.pli diff --git a/hello-world/PL1/code.pli b/hello-world/PL1/code.pli deleted file mode 100644 index 45707a25..00000000 --- a/hello-world/PL1/code.pli +++ /dev/null @@ -1,3 +0,0 @@ -hello: proc options(main); - put skip list('Hello World!'); -end hello; From 6b46cf9a2ae74afba136885b2f90ddcf0cfb1fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Sun, 26 Jan 2025 16:54:22 +0100 Subject: [PATCH 14/19] Create code.pli: create the loopy PL/I code --- loops/pl1/code.pli | 1 + 1 file changed, 1 insertion(+) create mode 100644 loops/pl1/code.pli diff --git a/loops/pl1/code.pli b/loops/pl1/code.pli new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/loops/pl1/code.pli @@ -0,0 +1 @@ + From 3aaa4a97fb924cdce425e6a8e172b37938c447eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Sun, 26 Jan 2025 16:55:17 +0100 Subject: [PATCH 15/19] Update code.pli: loopy PL/I code copied from the PL1 directory --- loops/pl1/code.pli | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/loops/pl1/code.pli b/loops/pl1/code.pli index 8b137891..51d11a17 100644 --- a/loops/pl1/code.pli +++ b/loops/pl1/code.pli @@ -1 +1,33 @@ - +code: proc(parms) options(main); + dcl parms char(100) var; + dcl u fixed bin(31); /*parameter value in fixed bin*/ + dcl r fixed bin(31); /* a random value 0001-9999 */ + dcl (i,j,m) fixed bin(31); + dcl a(10000) fixed bin(31); + dcl sysprint file stream output; + + u = parms; + r = randomm(); + do i = 1 to 10000; + a(i) = 0; + do j = 1 to 100000; + m = mod(j,u); + a(i) = a(i) + m; + end; + a(i) = a(i) + r; + end; + put file(sysprint) skip edit(a(r))(f(8)); + close file(sysprint); + + randomm: proc; + /* a somewhat dummy random number generator */ + dcl ts char(15) var; + dcl rand char(4); + dcl randi fixed bin(15); + + ts = time(); + rand = substr(ts,6,4); + randi = rand; + return(randi); + end randomm; +end; From e871904d0f959baa388841e6c2b75f3d5f97b86b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Sun, 26 Jan 2025 16:55:48 +0100 Subject: [PATCH 16/19] Delete loops/PL1/code.pli code copied to new directory "pl1" --- loops/PL1/code.pli | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 loops/PL1/code.pli diff --git a/loops/PL1/code.pli b/loops/PL1/code.pli deleted file mode 100644 index 51d11a17..00000000 --- a/loops/PL1/code.pli +++ /dev/null @@ -1,33 +0,0 @@ -code: proc(parms) options(main); - dcl parms char(100) var; - dcl u fixed bin(31); /*parameter value in fixed bin*/ - dcl r fixed bin(31); /* a random value 0001-9999 */ - dcl (i,j,m) fixed bin(31); - dcl a(10000) fixed bin(31); - dcl sysprint file stream output; - - u = parms; - r = randomm(); - do i = 1 to 10000; - a(i) = 0; - do j = 1 to 100000; - m = mod(j,u); - a(i) = a(i) + m; - end; - a(i) = a(i) + r; - end; - put file(sysprint) skip edit(a(r))(f(8)); - close file(sysprint); - - randomm: proc; - /* a somewhat dummy random number generator */ - dcl ts char(15) var; - dcl rand char(4); - dcl randi fixed bin(15); - - ts = time(); - rand = substr(ts,6,4); - randi = rand; - return(randi); - end randomm; -end; From 7801ebec4edce4cb876af4f2b7e70d7503a6123d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Mon, 27 Jan 2025 15:56:34 +0100 Subject: [PATCH 17/19] Create code.pli for the Fibonacci algorithm --- fibonacci/pl1/code.pli | 1 + 1 file changed, 1 insertion(+) create mode 100644 fibonacci/pl1/code.pli diff --git a/fibonacci/pl1/code.pli b/fibonacci/pl1/code.pli new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/fibonacci/pl1/code.pli @@ -0,0 +1 @@ + From e97746d77556bc5a4e79d664954d5919e00f59f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Mon, 27 Jan 2025 15:57:31 +0100 Subject: [PATCH 18/19] Update code.pli Load source code --- fibonacci/pl1/code.pli | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fibonacci/pl1/code.pli b/fibonacci/pl1/code.pli index 8b137891..12afac50 100644 --- a/fibonacci/pl1/code.pli +++ b/fibonacci/pl1/code.pli @@ -1 +1,26 @@ +code: proc(parm) options(main); + dcl parm char(100) var; + dcl (i,u,r) fixed bin(31); + dcl sysprint file stream output; + + u = trim(parm); + r = 0; + + do i = 1 by 1 while(i < u); + r = r + fibonacci(i); + end; + put skip data(r); + + fibonacci: procedure(n) recursive returns(fixed bin(31)); + dcl n fixed bin(31); + if n = 0 + then + return(0); + if n = 1 + then + return(1); + return(fibonacci(n - 1) + fibonacci(n - 2)); + end fibonacci; + +end code; From 9c789ea686c2f60ac9d0f0fad03a7ba84178969d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20M=C3=A1rkon?= Date: Wed, 12 Mar 2025 15:46:50 +0100 Subject: [PATCH 19/19] Update code.pli formatting issue --- fibonacci/pl1/code.pli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fibonacci/pl1/code.pli b/fibonacci/pl1/code.pli index 12afac50..a79143aa 100644 --- a/fibonacci/pl1/code.pli +++ b/fibonacci/pl1/code.pli @@ -18,7 +18,7 @@ code: proc(parm) options(main); then return(0); if n = 1 - then + then return(1); return(fibonacci(n - 1) + fibonacci(n - 2)); end fibonacci;