-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathgenome.rb
35 lines (26 loc) · 1.54 KB
/
genome.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# A 240-bit super "sekretoooo" integer genome
# hexadecimal (base 16)
genome = 0x00004a52931ce4085c14bdce014a0318846a0c808c60294a6314a34a1295b9ce
# decimal (base 10)
genome = 512955438081049600613224346938352058409509756310147795204209859701881294
# binary (base 2)
genome = 0b010010100101001010010011000111001110010000001000010111000001010010111101110011100000000101001010000000110001100010000100011010100000110010000000100011000110000000101001010010100110001100010100101000110100101000010010100101011011100111001110
p genome # printed as decimal (base 10) by default
#=> 512955438081049600613224346938352058409509756310147795204209859701881294
p genome.to_s(16)
#=> "4a52931ce4085c14bdce014a0318846a0c808c60294a6314a34a1295b9ce"
p genome.to_s(2)
#=> "10010100101001010010011000111001110010000001000010111000001010010111101110011100000000101001010000000110001100010000100\
# 011010100000110010000000100011000110000000101001010010100110001100010100101000110100101000010010100101011011100111001110"
bin = '%0240b' % genome # note: adds leading zeros - to_s(2) does not
p bin.size
#=> 240
p bin
#=> "010010100101001010010011000111001110010000001000010111000001010010111101110011100000000101001010000000110001100010000100\
# 011010100000110010000000100011000110000000101001010010100110001100010100101000110100101000010010100101011011100111001110"
hex = '%060x' % genome # note: adds leading zeros - to_s(16) does not
p hex.size
#=> 60
p hex
#=> 60
#=> "4a52931ce4085c14bdce014a0318846a0c808c60294a6314a34a1295b9ce"