Last active
November 30, 2017 21:54
-
-
Save Goryudyuma/199c98a5b8831e29c37143bb98bfe01b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with recursive | |
limitxy AS (SELECT * FROM (VALUES(20, 20)) AS t (x,y)), | |
formula(n, x, y, c) AS ( | |
VALUES(0, 0, 0, '') | |
UNION ALL | |
SELECT n+1, | |
(SELECT x FROM (SELECT n % (SELECT x FROM limitxy) AS x, n / (SELECT x FROM limitxy) AS y) AS xy), | |
(SELECT y FROM (SELECT n % (SELECT x FROM limitxy) AS x, n / (SELECT x FROM limitxy) AS y) AS xy), | |
CASE WHEN ( | |
SELECT ( | |
((point.x = 5 OR point.x = -5) AND -5 <= point.y AND point.y <= 5) OR | |
((point.y = 5 OR point.y = -5) AND -5 <= point.x AND point.x <= 5) | |
) | |
FROM ( | |
SELECT x - (SELECT x/2 FROM limitxy) AS x, y - (SELECT y/2 FROM limitxy) AS y | |
FROM (SELECT n % (SELECT x FROM limitxy) AS x, n / (SELECT y FROM limitxy) AS y) AS xy | |
) AS point | |
) | |
then '#' | |
ELSE ' ' | |
END | |
FROM formula WHERE n < (SELECT x * y FROM limitxy) | |
), | |
mkstring(num, s) AS( | |
VALUES(0, '') | |
UNION ALL | |
SELECT num + 1, (SELECT ARRAY_TO_STRING(ARRAY_AGG(c), '') FROM formula WHERE num = formula.y) FROM mkstring WHERE num < (SELECT y FROM limitxy) | |
) | |
SELECT s FROM mkstring WHERE num != 0; | |
s | |
---------------------- | |
########### | |
# # | |
# # | |
# # | |
# # | |
# # | |
# # | |
# # | |
# # | |
# # | |
########### | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment