Friday, July 1, 2016

Bash: Collatz Conjecture

Command:

$ cat ./collatz.sh

Result:

#!/bin/bash

collatz () {
        echo $1

        if (($1 != 1)) ; then
                if (($1 % 2 == 0)) ; then

                        collatz $(($1 / 2))
                else
                        collatz $((3 * $1 + 1))
                fi
        fi
}

collatz $1


Command:

$ ./collatz.sh 123

Result:

123
370
185
556
278
139
418
209
628
314
157
472
236
118
59
178
89
268
134
67
202
101
304
152
76
38
19
58
29
88
44
22
11
34
17
52
26
13
40
20
10
5
16
8
4
2
1


Edward Frenkel: Numbers and Free Will (extra footage)

Edward Frenkel

Edward Frenkel: Numbers and Free Will

Edward Frenkel

Maryna Viazovska: The solution to the sphere packing problem in 24 dimensions

Maryna Viazovska

  • Analytic number theory (解析的整数論)
  • Sphere packing (球充填)

Solar FREAKIN' Roadways!

Collatz conjecture: The Simplest Impossible Problem