15
$\begingroup$

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.

$\endgroup$
2
  • 2
    $\begingroup$ Is it brainf**k. $\endgroup$
    – Numberknot
    Commented Sep 7, 2016 at 6:48
  • $\begingroup$ i dunno why but its ... beautiful . $\endgroup$
    – lois6b
    Commented Sep 7, 2016 at 6:48

2 Answers 2

14
$\begingroup$

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]
$\endgroup$
7
$\begingroup$

answer: (update)

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

$\endgroup$
7
  • $\begingroup$ 5 is the 3rd prime and the nth prime seems to be encoded as <n>, so 5 is <<<>>>. $\endgroup$
    – M Oehm
    Commented Sep 7, 2016 at 6:58
  • $\begingroup$ @MOehm That seems an awful lot like the (rest of the) answer to me. $\endgroup$
    – Will
    Commented Sep 7, 2016 at 7:06
  • $\begingroup$ @MOehm you are right but you are not counting 1 as the first prime , arent you? can I add it to my answer? $\endgroup$
    – lois6b
    Commented Sep 7, 2016 at 7:07
  • $\begingroup$ @lois6b: 2 is the first prime and its representation is nothing (or undefined, the value of 1) enclosed in brackets. $\endgroup$
    – M Oehm
    Commented Sep 7, 2016 at 7:09
  • 1
    $\begingroup$ @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.) $\endgroup$
    – M Oehm
    Commented Sep 7, 2016 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.