# Numbers to brackets sequences

Find the rule between these numbers and their brackets sequences.

1 = not defined
2 = <>
3 = <<>>
4 = <><>
5 = <<<>>>
6 = <><<>>
7 = <<><>>
8 = <><><>
9 = <<>><<>>
10 = <><<<>>>
11 = <<<<>>>>
12 = <><><<>>
13 = <<><<>>>
14 = <><<><>>
15 = <<>><<<>>>
16 = <><><><>
17 = <<<><>>>
18 = <><<>><<>>
19 = <<><><>>
20 = <><><<<>>>
...

Note: Every number bigger than 1 can be written like this.

I got this puzzle from my friend.

• Is it brainf**k. – Numberknot Sep 7 '16 at 6:48
• i dunno why but its ... beautiful . – lois6b Sep 7 '16 at 6:48

As @lois6b has already found out, numbers can be multiplied by juxtaposing their bracket representations: 6 = 2×3, so the bracket representation is the representation of 2 next the representation of 3, <> <<>>. The first factor is the smallest factor, usually a small prime.

Primes cannot be gerenated in that fashion, so there is a special rule for them: The nth prime is represented by <n>, that is the bracket representation of n enclosed in brackets.

Here's a small Python program that prints the list above:

rep = ["", ""]
primes = []

def smallfact(n):
for p in primes:
if n % p == 0:
return p
return 1

for n in range(2, 21):
s = smallfact(n)

if s == 1:
primes.append(n)
rep.append("<" + rep[len(primes)] + ">")

else:
rep.append(rep[s] + rep[n / s])

print n, '=', rep[-1]


The prime numbers are nth prime seems to be encoded as <n>, so 5, which is the 3rd prime number is <<<>>> (thanks to M Oehm :* )
2 is <n> -> <1> -> <>
10 = <><<<>>> -> because <>(2) * <<<>>> (5) = 10
20 = <><><<<>>> -> because <><> (4) * <<<>>> (5) = 20
• 5 is the 3rd prime and the nth prime seems to be encoded as <n>, so 5 is <<<>>>. – M Oehm Sep 7 '16 at 6:58