1. 9
ecalamia.com
1.

2. 8

My favorite abuse of prime numbers is to solve interview questions that ask you to detect whether two strings are palindromes: Assign a prime to each letter of the alphabet the strings are made out of and multiply. If the numbers you get are the same, the strings are palindromes.

1. 4

Do you mean anagrams? :p

1. 1

Oh I do! orz

2. 1

If numeric type in PostgreSQL can go up to 16383 digits after the decimal point, how many comments can I store this way?

1. 4

If we’re taking Postgres, might as well have `parents INTEGER[]` and save yourself a lot of messing about.

1. 2

Or just use a recursive CTE

2. 1

Interesting approach, but I’m curious about in which ways this is better than a prefix tree?

1. 2

This is just a fun approach. As another comment mentions, use `INTEGER[]`. Having to do factorization for every comment whose parents you want to display is perhaps not expensive, but definitely not free.

1. 2

Recursive CTE is the solution in this case. Solves both “would need N joins” and “can’t count(*) comfortably”.

2. 2

I don’t think it is better than a prefix tree. Using prime numbers is kind of funny and original, but I’ve never used this approach in a real product and I normally wouldn’t!

1. 1

Ah, okay. Sorry for being confused :o