Skip to main content
Commonmark migration
Source Link

#PostgreSQL, 176 bytes #

PostgreSQL, 176 bytes

WITH c AS(SELECT * FROM(SELECT 6v)t,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT string_agg(r::text,',' ORDER BY r)
FROM(SELECT r FROM c UNION SELECT v/r FROM c)s

SqlFiddleDemo

Input: (SELECT ...v)

How it works:

  • (SELECT ...v) - input
  • generate_series(1, sqrt(v)::int) - numbers from 1 to sqrt(n)
  • WHERE v%r=0 -filter divisors
  • wrap with common table expression to refer twice
  • SELECT r FROM c UNION SELECT v/r FROM c generete rest of divisors and combine
  • SELECT string_agg(r::text,',' ORDER BY r) produce final comma separated result

Input as table:

WITH c AS(SELECT * FROM i,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT v,string_agg(r::text,',' ORDER BY r)
FROM(SELECT v,r FROM c UNION SELECT v,v/r FROM c)s
GROUP BY v

SqlFiddleDemo

Output:

╔═════╦════════════════╗
║ v   ║   string_agg   ║
╠═════╬════════════════╣
║  1  ║ 1              ║
║  2  ║ 1,2            ║
║  6  ║ 1,2,3,6        ║
║  9  ║ 1,3,9          ║
║ 99  ║ 1,3,9,11,33,99 ║
╚═════╩════════════════╝

#PostgreSQL, 176 bytes #

WITH c AS(SELECT * FROM(SELECT 6v)t,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT string_agg(r::text,',' ORDER BY r)
FROM(SELECT r FROM c UNION SELECT v/r FROM c)s

SqlFiddleDemo

Input: (SELECT ...v)

How it works:

  • (SELECT ...v) - input
  • generate_series(1, sqrt(v)::int) - numbers from 1 to sqrt(n)
  • WHERE v%r=0 -filter divisors
  • wrap with common table expression to refer twice
  • SELECT r FROM c UNION SELECT v/r FROM c generete rest of divisors and combine
  • SELECT string_agg(r::text,',' ORDER BY r) produce final comma separated result

Input as table:

WITH c AS(SELECT * FROM i,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT v,string_agg(r::text,',' ORDER BY r)
FROM(SELECT v,r FROM c UNION SELECT v,v/r FROM c)s
GROUP BY v

SqlFiddleDemo

Output:

╔═════╦════════════════╗
║ v   ║   string_agg   ║
╠═════╬════════════════╣
║  1  ║ 1              ║
║  2  ║ 1,2            ║
║  6  ║ 1,2,3,6        ║
║  9  ║ 1,3,9          ║
║ 99  ║ 1,3,9,11,33,99 ║
╚═════╩════════════════╝

PostgreSQL, 176 bytes

WITH c AS(SELECT * FROM(SELECT 6v)t,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT string_agg(r::text,',' ORDER BY r)
FROM(SELECT r FROM c UNION SELECT v/r FROM c)s

SqlFiddleDemo

Input: (SELECT ...v)

How it works:

  • (SELECT ...v) - input
  • generate_series(1, sqrt(v)::int) - numbers from 1 to sqrt(n)
  • WHERE v%r=0 -filter divisors
  • wrap with common table expression to refer twice
  • SELECT r FROM c UNION SELECT v/r FROM c generete rest of divisors and combine
  • SELECT string_agg(r::text,',' ORDER BY r) produce final comma separated result

Input as table:

WITH c AS(SELECT * FROM i,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT v,string_agg(r::text,',' ORDER BY r)
FROM(SELECT v,r FROM c UNION SELECT v,v/r FROM c)s
GROUP BY v

SqlFiddleDemo

Output:

╔═════╦════════════════╗
║ v   ║   string_agg   ║
╠═════╬════════════════╣
║  1  ║ 1              ║
║  2  ║ 1,2            ║
║  6  ║ 1,2,3,6        ║
║  9  ║ 1,3,9          ║
║ 99  ║ 1,3,9,11,33,99 ║
╚═════╩════════════════╝
added 654 characters in body
Source Link
lad2025
  • 409
  • 3
  • 7

#PostgreSQL, 170176 bytes #

WITH c AS(SELECT * FROM(SELECT 6v)t,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT string_agg(r::text,',' ORDER BY r)
FROM(SELECT r FROM c UNION SELECT v/r FROM c)s

SqlFiddleDemo

Input: (SELECT ...v)

How it works:

  • (SELECT ...v) - input
  • generate_series(1, sqrt(v)::int) - numbers from 1 to sqrt(n)
  • WHERE v%r=0 -filter divisors
  • wrap with common table expression to refer twice
  • SELECT r FROM c UNION SELECT v/r FROM c generete rest of divisors and combine
  • SELECT string_agg(r::text,',' ORDER BY r) produce final comma separated result

Input as table:

WITH c AS(SELECT * FROM i,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT v,string_agg(r::text,',' ORDER BY r)
FROM(SELECT v,r FROM c UNION SELECT v,v/r FROM c)s
GROUP BY v

SqlFiddleDemo

Output:

╔═════╦════════════════╗
║ v   ║   string_agg   ║
╠═════╬════════════════╣
║  1  ║ 1              ║
║  2  ║ 1,2            ║
║  6  ║ 1,2,3,6        ║
║  9  ║ 1,3,9          ║
║ 99  ║ 1,3,9,11,33,99 ║
╚═════╩════════════════╝

#PostgreSQL, 170 bytes #

WITH c AS(SELECT * FROM(SELECT 6v)t,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT string_agg(r::text,',' ORDER BY r)
FROM(SELECT r FROM c UNION SELECT v/r FROM c)s

SqlFiddleDemo

Input: (SELECT ...v)

How it works:

  • (SELECT ...v) - input
  • generate_series(1, sqrt(v)::int) - numbers from 1 to sqrt(n)
  • WHERE v%r=0 -filter divisors
  • wrap with common table expression to refer twice
  • SELECT r FROM c UNION SELECT v/r FROM c generete rest of divisors and combine
  • SELECT string_agg(r::text,',' ORDER BY r) produce final comma separated result

#PostgreSQL, 176 bytes #

WITH c AS(SELECT * FROM(SELECT 6v)t,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT string_agg(r::text,',' ORDER BY r)
FROM(SELECT r FROM c UNION SELECT v/r FROM c)s

SqlFiddleDemo

Input: (SELECT ...v)

How it works:

  • (SELECT ...v) - input
  • generate_series(1, sqrt(v)::int) - numbers from 1 to sqrt(n)
  • WHERE v%r=0 -filter divisors
  • wrap with common table expression to refer twice
  • SELECT r FROM c UNION SELECT v/r FROM c generete rest of divisors and combine
  • SELECT string_agg(r::text,',' ORDER BY r) produce final comma separated result

Input as table:

WITH c AS(SELECT * FROM i,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT v,string_agg(r::text,',' ORDER BY r)
FROM(SELECT v,r FROM c UNION SELECT v,v/r FROM c)s
GROUP BY v

SqlFiddleDemo

Output:

╔═════╦════════════════╗
║ v   ║   string_agg   ║
╠═════╬════════════════╣
║  1  ║ 1              ║
║  2  ║ 1,2            ║
║  6  ║ 1,2,3,6        ║
║  9  ║ 1,3,9          ║
║ 99  ║ 1,3,9,11,33,99 ║
╚═════╩════════════════╝
added 366 characters in body
Source Link
lad2025
  • 409
  • 3
  • 7

#PostgreSQL, 170 bytes #

WITH c AS(SELECT * FROM(SELECT 6v)t,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT string_agg(r::text,',' ORDER BY r)
FROM(SELECT r FROM c UNION SELECT v/r FROM c)s

SqlFiddleDemo

Input: (SELECT ...v)

How it works:

  • (SELECT ...v) - input
  • generate_series(1, sqrt(v)::int) - numbers from 1 to sqrt(n)
  • WHERE v%r=0 -filter divisors
  • wrap with common table expression to refer twice
  • SELECT r FROM c UNION SELECT v/r FROM c generete rest of divisors and combine
  • SELECT string_agg(r::text,',' ORDER BY r) produce final comma separated result

#PostgreSQL, 170 bytes #

WITH c AS(SELECT * FROM(SELECT 6v)t,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT string_agg(r::text,',' ORDER BY r)
FROM(SELECT r FROM c UNION SELECT v/r FROM c)s

SqlFiddleDemo

Input: (SELECT ...v)

#PostgreSQL, 170 bytes #

WITH c AS(SELECT * FROM(SELECT 6v)t,generate_series(1,sqrt(v)::int)s(r)WHERE v%r=0)
SELECT string_agg(r::text,',' ORDER BY r)
FROM(SELECT r FROM c UNION SELECT v/r FROM c)s

SqlFiddleDemo

Input: (SELECT ...v)

How it works:

  • (SELECT ...v) - input
  • generate_series(1, sqrt(v)::int) - numbers from 1 to sqrt(n)
  • WHERE v%r=0 -filter divisors
  • wrap with common table expression to refer twice
  • SELECT r FROM c UNION SELECT v/r FROM c generete rest of divisors and combine
  • SELECT string_agg(r::text,',' ORDER BY r) produce final comma separated result
Source Link
lad2025
  • 409
  • 3
  • 7
Loading