From 5dba324368d526b878978f60d55ae1db3b795804 Mon Sep 17 00:00:00 2001
From: Luca Ferrari <fluca1978@gmail.com>
Date: Mon, 22 Apr 2024 12:10:47 +0200
Subject: PWC 266

Task 1 Raku done
Task 2 Raku done

Task 1 PL/Perl done
Task 2 PL/Perl done

Task 1 PL/PgSQL done
Task 2 PL/PgSQL done

Task 1 PL/Java done
Task 2 PL/Java done

Task 1 Python done
Task 2 Python done
---
 challenge-266/luca-ferrari/plpgsql/ch-2.sql | 38 +++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 challenge-266/luca-ferrari/plpgsql/ch-2.sql

(limited to 'challenge-266/luca-ferrari/plpgsql/ch-2.sql')

diff --git a/challenge-266/luca-ferrari/plpgsql/ch-2.sql b/challenge-266/luca-ferrari/plpgsql/ch-2.sql
new file mode 100644
index 0000000000..95f6ac6c8c
--- /dev/null
+++ b/challenge-266/luca-ferrari/plpgsql/ch-2.sql
@@ -0,0 +1,38 @@
+--
+-- Perl Weekly Challenge 266
+-- Task 2
+-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-266>
+--
+
+CREATE SCHEMA IF NOT EXISTS pwc266;
+
+CREATE OR REPLACE FUNCTION
+pwc266.task2_plpgsql( s int, matrix int[] )
+RETURNS boolean
+AS $CODE$
+DECLARE
+	w int := 0;
+BEGIN
+
+
+	FOR r IN 1 .. s LOOP
+	    FOR c IN 1 .. s LOOP
+	    	w = ( r - 1 ) * s + c;
+	    	IF r = c OR c = s - r + 1 THEN
+		   IF matrix[ w ] = 0 THEN
+		      RETURN false;
+		   END IF;
+		ELSE
+		   IF matrix[ w ] <> 0 THEN
+		      RETURN false;
+		   END IF;
+		END IF;
+
+	    END LOOP;
+	END LOOP;
+
+	RETURN true;
+
+END
+$CODE$
+LANGUAGE plpgsql;
-- 
cgit 

