# 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. Sep 7 '16 at 6:48
• i dunno why but its ... beautiful . 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> -> <>

The even numbers are product of other numbers:
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 <<<>>>. Sep 7 '16 at 6:58
• @MOehm That seems an awful lot like the (rest of the) answer to me.
– Will
Sep 7 '16 at 7:06
• @MOehm you are right but you are not counting 1 as the first prime , arent you? can I add it to my answer? Sep 7 '16 at 7:07
• @lois6b: 2 is the first prime and its representation is nothing (or undefined, the value of 1) enclosed in brackets. Sep 7 '16 at 7:09
• @lois6b: Of course, otherwise I wouldn't have commented it. (But I'm currently writing up an answer of my own, if you don't mind.) Sep 7 '16 at 7:12