32
12
The Kolmogorov complexity of a string s is defined as the length of the shortest program P that outputs s. If the length of P is shorter than the length of s, then s is said to be compressible, otherwise s is incompressible. Most strings are incompressible ...
Write the shortest program that outputs this string (without spaces and without newlines):
d9 a6 b6 33 56 a7 95 4b 29 b0 ac 7f 2a aa 6d 19 b8 4b 4c f8 b6 2a ac 95
a1 4b 4e a5 9d b3 e7 c9 4c 49 59 ec 94 b3 aa 6c 93 8f 11 5a 4d 39 75 82
ec ea 24 cc d3 2d c3 93 38 4e b7 a6 0d d2 b5 37 23 54 ad 1b 79 aa 6e 49
55 52 94 5a a7 3a 6a e9 e4 52 cd 2d 79 ad c6 12 b5 99 5b b4 76 51 17 4e
94 f3 9a a2 e7 15 6a 55 14 4d 4e 4a a3 5c 2f ab 63 cc b5 a6 a4 92 96 8a
2e c3 d8 88 9b 8c a9 16 f5 33 22 5b a2 e2 cc 1b 27 d4 e8 db 17 a4 39 85
ca aa 5b 4f 36 24 d3 c6 f6 94 ad d7 0f 71 24 e1 b1 c5 ef 65 35 6c 8d d7
1a 87 1e 25 df 5d c0 13 b2 6f 5a 57 28 98 bd 41 66 04 ed a2 52 c9 ac 83
b3 6c 56 7e d1 c6 cc 53 4a 62 c5 59 a9 b2 d4 af 22 a5 a9 f4 b2 99 23 32
f8 fb ae 48 6a 8a 9a b5 46 7a 36 59 9f 92 d3 25 b5 19 bd 8a 4a 49 62 a5
e4 59 fb e5 ba a2 35 dd a9 36 1d a9 c9 69 89 77 6a b2 34 2d 1d 22 61 c5
c2 66 1c e2 76 74 52 a5 d9 84 b9 8a a6 b5 14 ec 29 58 b2 bc 96 16 16 48
f5 c5 bd 2f 32 1b 3d 4f 4b 2e b2 6b 9a d9 32 a4 4b 5c bc 92 b7 b3 26 39
fa 42 2d 64 ed 1a 79 49 4c a3 b7 85 b2 a6 e2 8c d9 55 90 e1 a8 87 4b 60
a6 e1 ba c4 bb ec 32 39 76 90 a6 b4 c6 65 79 61 91 aa 3d 54 b7 18 3d 15
4b 06 db 30 8a 4d 4a a1 35 75 5d 3b d9 98 ac 55 5b 10 dd b3 e2 cc f1 5e
b3 2b 53 90 b6 ee 2b ac 8f 88 8d 95 5a 75 df 59 2d 1c 5a 4c e8 f4 ea 48
b9 56 de a0 92 91 a9 15 4c 55 d5 e9 3a 76 8e 04 ba e7 b2 aa e9 ab 2a d6
23 33 45 3d c4 e9 52 e3 6a 47 50 ba af e4 e5 91 a3 14 63 95 26 b3 8b 4c
bc aa 5a 92 7a ab ad a6 db 53 2e 97 06 6d ba 3a 66 49 4d 95 d7 65 c2 aa
c3 1a 92 93 3f ca c2 6c 2b 37 55 13 c9 88 4a 5c 62 6b a6 ae cc de 72 94
The output should look like:
d9a6b63356a7954b29b0ac7f2aaa6d19b84b4cf8b62aac95a14b4e...7294
Note: no user input is allowed, nor web access, nor libraries (except the one required for printing the output).
Edit I: the sequence seems random ... but it turns out to be highly compressible handling a little bit of prime numbers ...
Edit II: Well done! I'll review the answers in the next hours, then assign the bounty. This is my idea on how it could be solved:
- If you try to compress the data you don't go far away ...
- In internet you can find the (well-known?) On-Line Encyclopedia of Integer Sequences (OEIS) ;
- trying the first hexadecimal digits
d9, a6, b6, 33, ...
(or their decimal representation) give no result; - but if you convert the numbers to binary (
1,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0
) and searching them on OEIS, you get this result. - As noted by Claudiu, I also gave a little hint in the question (Edit I above) ... :-)
The winner is: Peter Taylor (GolfScript, 50), with a special mention for Claudiu (Python, 92), the first who "solved" it.
2How is this more interesting than other [tag:komogorov-complexity] questions? – Doorknob – 2014-03-26T12:07:59.547
2@Doorknob: perhaps nothing ... at least until someone will post an answer :-) – Marzio De Biasi – 2014-03-26T12:13:06.533
Do I understand correctly we are allowed internet access? – John Dvorak – 2014-03-26T12:18:38.657
@JanDvorak I think implicitly standard loopholes apply here. And for the asker: link this in the question
– mniip – 2014-03-26T12:19:04.227Note: googling the first few bytes finds nothing but this question. – John Dvorak – 2014-03-26T12:24:17.460
5Is this supposed to be a game of "Guess the constant"? – Peter Taylor – 2014-03-26T12:26:45.367
Funny thing...I can't copy+paste this string properly when all the spaces and newlines are removed – David Wilkins – 2014-03-26T13:11:48.933
why this string in particular? is it random? – xem – 2014-03-26T13:20:47.427
@xem presumable because it isn't very compressable...I can get it to 744 characters using
gzdeflate
– David Wilkins – 2014-03-26T13:25:22.633also, "shortest program", in bytes or in characters? – xem – 2014-03-26T13:33:23.473
@xem: I assume 1 character = 1 byte. – Marzio De Biasi – 2014-03-26T13:37:10.827
1This still seems like a hide-and-seek kind of challenge...."Do you see what I did there?" isn't really the same as code-golf – David Wilkins – 2014-03-26T14:21:46.317
@DavidWilkins: do you suggest to reveal how to generate the sequence? – Marzio De Biasi – 2014-03-26T14:22:39.347
2
@MarzioDeBiasi wouldn't that change the challenge to "write this code shorter than I did" ? I'm not sure what I'd recommend, other than using the meta sandbox (http://meta.codegolf.stackexchange.com/questions/1303/proposed-question-sandbox-mark-xi) to proof your challenge before posting it
– David Wilkins – 2014-03-26T14:26:31.873The obvious standard tool is the inverse symbolic calculator, but that draws a complete blank for 0.8502000689828988668429023263735528272644799. – Peter Taylor – 2014-03-26T14:29:11.383
1Don't give in the the peer pressure. This challenge has prompted me to learn something about cryptography. For that, I gave you an upvote. – Rainbolt – 2014-03-26T14:31:27.727
1Too bad you just changed the question... I had it in 139 with
import re,urllib.request as r;print(re.split('</?code>',r.urlopen('http://codegolf.stackexchange.com/questions/24909').read().decode())[1])
– Mathieu Rodic – 2014-03-26T14:31:52.303@MathieuRodic: "no web access" was one of the first edit :-) – Marzio De Biasi – 2014-03-26T14:32:52.017
@Rusher: don't worry, even if I give the solution it can be interesting; however I think that this is not the right place for mind-juggling puzzles :-) – Marzio De Biasi – 2014-03-26T14:34:16.657
7Don't give the solution! People are working on it :-) – Mau – 2014-03-26T14:37:12.647
Has anyone tried converting this number from Hex to Decimal, then calculating prime factors? It's a 1200 digit number, so it shouldn't be that difficult, it just requires a decent computer and an app which can handle such huge numbers. – Nzall – 2014-03-26T15:46:51.690
@NateKerkhofs I'm more in the way of
print f(prime[i])%255
– Antonio Ragagnin – 2014-03-26T16:08:11.5231I got the answer in 92 characters, but as soon as I post it the cat's out of the bag... what should I do? I could provide the sha-256 of the code and offer the code once an answer is accepted. – Claudiu – 2014-03-26T17:52:44.560
@Claudiu: yeah, I think you should post the hash and then wait a little. Maybe the OP can set a deadline! – rubik – 2014-03-26T17:54:23.470
2I recommend a deadline as well – Claudiu – 2014-03-26T17:54:41.917
I have the answer in 98 characters in Python and 106 characters in Haskell. Should I still post them (well, their hashes) even though there's a shorter solution already? – user253751 – 2014-03-27T08:52:27.323
@immibis: IMO you can post the Haskell one ... if you found "how to do it" you deserve some upvotes :-) – Marzio De Biasi – 2014-03-27T09:15:07.267
of course, if I only post the hash, there's no evidence that I didn't just post a random hex string – user253751 – 2014-03-27T09:27:36.223
3I think the contest should be in two parts. First part is a prize given to those who found the answer. Second part is a prize given to those who really know how to compress the code and generate the smallest. Right now, it's more of a "guess my algorithm" question, which excludes dullards like me, but also real code golfing pros, (which I'm not either), and those who know APL and the other terse languages (still not me). – None – 2014-03-27T14:10:02.970
@NateKerkhofs - Factoring only has a real benefit if you express the number as products of powers of primes with a substantial number of powers > 1. The number (which we'll call N) has a few small factors, but then ends up with a 1152 digit composite which is way beyond our current capabilities of about 220 digits. You can also express N as p(n1)p(n2)... with p the prime function and n the ordinal (e.g. first prime p(1) = 2, second prime p(2) = 3, nth prime p(n)). This will compress to log(N/ln(N)) characters which is actually not much smaller than log(N) characters, so minimal compression! – None – 2014-03-27T14:24:59.627
2@immibis: True but what'd be the point of that? Some ill-gotten rep points? This is supposed to be for fun =) – Claudiu – 2014-03-27T16:11:20.207
Is base conversion included under "the [library] required for printing the output"? – Peter Taylor – 2014-03-31T16:09:54.050
1@PeterTaylor: no, sorry. The only library function allowed is the one used to print the output. – Marzio De Biasi – 2014-03-31T16:10:55.107
That is what I was wondering. Using libraries (and interpreters for that matter) is code being used to generate output. It all has to be counted I think. – philcolbourn – 2014-04-01T13:35:04.817
PS. looking at answers so far, and ignoring machine code and microcode, it could be argued that only language constructs can be allowed - no libraries can be used unless their source code is counted as well. So richer languages are at an advantage. Even better if your chosen language has a print statement that supports hashing - which just isn't cricket. – philcolbourn – 2014-04-01T13:46:53.253
@what do you mean with "print statement that support hashing?" – Marzio De Biasi – 2014-04-01T13:58:30.140
@MarzioDeBiasi: Oh I didn't realize that I can't use base-conversion functions.. I use
hex
, for example, which is a built-in (I don't import anything), but I also userange
andall
, which are the same status (also built-in functions).. my program won't win anyway but should I technically not have used any of those? – Claudiu – 2014-04-01T15:47:06.690@philcolbourn: Hashing has nothing to do with solving the problem. It's just a proof to avoid releasing the code prior to the end of the contest. – rubik – 2014-04-01T19:24:55.813
@Claudiu: Well
hex
isn't a "library function", it's just built-in. So I think you're ok. – rubik – 2014-04-01T19:26:05.440@Claudiu I really misunderstood these answers then, didn't I. I read them as finding a small message that when hashed gave resulting long string. But have I misunderstood Kolmogorov complexity as well? – philcolbourn – 2014-04-02T05:31:05.580
@MarzioDeBiasi - My error. I thought all these hash functions were part of answers so I thought that only way to not count hashing code was for some language to include it in print function. I feel a bit silly now. – philcolbourn – 2014-04-02T05:40:08.593
It was that easy to find in OEIS?! Aaargh. I converted to indexes
– Peter Taylor – 2014-04-02T23:04:50.6370,1,3,4,7,8,10,13,14,...
, tried simple linear transforms of that, tried working from the other end, tried inverting the mask (2,5,6,9,11,12,15,...
) and finally found A138970... and then realised that my very first search on OEIS would have turned up A138971 if I'd omitted the0
.@MarzioDeBiasi Now that you've picked the winner, you should click the green tick on Peter Taylor's solution. – Chris Jester-Young – 2014-04-03T20:22:45.903
@ChrisJester-Young: I accepted his answer; should I click on the +100, too or does the bounty automatically get assigend to the accepted answer? – Marzio De Biasi – 2014-04-03T20:35:43.747