Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 386 characters in body
Source Link
Anders Kaseorg
  • 40.7k
  • 3
  • 76
  • 149

Python 3, 2·267 +たす 510193 = 510727

Predictor

def p():
 d={};s=b''
 while 1:
 p={0:1};r=range(len(s)+1)
 for i in r:
 for c,n in d.setdefault(s[:i],{}).items():p[c]=p.get(c,1)*n**b'1円6円\f36円AcWuvY_v`270円~333円~'[i]
 c=yield max(sorted(p),key=p.get)
 for i in r:e=d[s[:i]];e[c]=e.get(c,1)+1
 s=b'%c'%c+s[:15]

This uses a weighted Bayesian combination of the order 0, ..., 16 Markov models, with weights [1, 6, 12, 30, 65, 99, 87, 117, 118, 89, 95, 118, 96, 184, 126, 219, 126].

The result is not very sensitive to the selection of these weights, but I optimized them because I could, using the same late acceptance hill-climbing algorithm that I used in my answer to "Put together a Senate majority" , where each candidate mutation is just a ±1 increment to a single weight.

Test code

with open('whale2.txt', 'rb') as f:
 g = p()
 wrong = 0
 a = next(g)
 for b in f.read():
 wrong += a != b
 a = g.send(b)
 print(wrong)

Python 3, 2·267 +たす 510193 = 510727

Predictor

def p():
 d={};s=b''
 while 1:
 p={0:1};r=range(len(s)+1)
 for i in r:
 for c,n in d.setdefault(s[:i],{}).items():p[c]=p.get(c,1)*n**b'1円6円\f36円AcWuvY_v`270円~333円~'[i]
 c=yield max(sorted(p),key=p.get)
 for i in r:e=d[s[:i]];e[c]=e.get(c,1)+1
 s=b'%c'%c+s[:15]

This uses a weighted Bayesian combination of the order 0, ..., 16 Markov models, with weights [1, 6, 12, 30, 65, 99, 87, 117, 118, 89, 95, 118, 96, 184, 126, 219, 126].

Test code

with open('whale2.txt', 'rb') as f:
 g = p()
 wrong = 0
 a = next(g)
 for b in f.read():
 wrong += a != b
 a = g.send(b)
 print(wrong)

Python 3, 2·267 +たす 510193 = 510727

Predictor

def p():
 d={};s=b''
 while 1:
 p={0:1};r=range(len(s)+1)
 for i in r:
 for c,n in d.setdefault(s[:i],{}).items():p[c]=p.get(c,1)*n**b'1円6円\f36円AcWuvY_v`270円~333円~'[i]
 c=yield max(sorted(p),key=p.get)
 for i in r:e=d[s[:i]];e[c]=e.get(c,1)+1
 s=b'%c'%c+s[:15]

This uses a weighted Bayesian combination of the order 0, ..., 16 Markov models, with weights [1, 6, 12, 30, 65, 99, 87, 117, 118, 89, 95, 118, 96, 184, 126, 219, 126].

The result is not very sensitive to the selection of these weights, but I optimized them because I could, using the same late acceptance hill-climbing algorithm that I used in my answer to "Put together a Senate majority" , where each candidate mutation is just a ±1 increment to a single weight.

Test code

with open('whale2.txt', 'rb') as f:
 g = p()
 wrong = 0
 a = next(g)
 for b in f.read():
 wrong += a != b
 a = g.send(b)
 print(wrong)
−94
Source Link
Anders Kaseorg
  • 40.7k
  • 3
  • 76
  • 149

Python 3, 2·2652·267 + 510291510193 = 510821510727

Predictor

def p():
 d={};s=b''
 while 1:
 p={0:1};r=range(len(s)+1)
 for i in r:
 for c,n in d.setdefault(s[:i],{}).items():p[c]=p.get(c,1)*n**b'1円6円\r#Ihb~jzS177円M210円o{5'[i]*n**b'1円6円\f36円AcWuvY_v`270円~333円~'[i]
 c=yield max(sorted(p),key=p.get)
 for i in r:e=d[s[:i]];e[c]=e.get(c,1)+1
 s=b'%c'%c+s[:15]

This uses a weighted Bayesian combination of the order 0, ..., 16 Markov models, with weights [1, 6, 1312, 3530, 7365, 10499, 9887, 126117, 106118, 12289, 8395, 127118, 7796, 136184, 111126, 123219, 53]126].

Test code

with open('whale'whale2.txt', 'rb') as f:
 g = p()
 wrong = 0
 a = next(g)
 for b in f.read():
 wrong += a != b
 a = g.send(b)
 print(wrong)

Python 3, 2·265 + 510291 = 510821

Predictor

def p():
 d={};s=b''
 while 1:
 p={0:1};r=range(len(s)+1)
 for i in r:
 for c,n in d.setdefault(s[:i],{}).items():p[c]=p.get(c,1)*n**b'1円6円\r#Ihb~jzS177円M210円o{5'[i]
 c=yield max(sorted(p),key=p.get)
 for i in r:e=d[s[:i]];e[c]=e.get(c,1)+1
 s=b'%c'%c+s[:15]

This uses a weighted Bayesian combination of the order 0, ..., 16 Markov models, with weights [1, 6, 13, 35, 73, 104, 98, 126, 106, 122, 83, 127, 77, 136, 111, 123, 53].

Test code

with open('whale.txt', 'rb') as f:
 g = p()
 wrong = 0
 a = next(g)
 for b in f.read():
 wrong += a != b
 a = g.send(b)
 print(wrong)

Python 3, 2·267 + 510193 = 510727

Predictor

def p():
 d={};s=b''
 while 1:
 p={0:1};r=range(len(s)+1)
 for i in r:
 for c,n in d.setdefault(s[:i],{}).items():p[c]=p.get(c,1)*n**b'1円6円\f36円AcWuvY_v`270円~333円~'[i]
 c=yield max(sorted(p),key=p.get)
 for i in r:e=d[s[:i]];e[c]=e.get(c,1)+1
 s=b'%c'%c+s[:15]

This uses a weighted Bayesian combination of the order 0, ..., 16 Markov models, with weights [1, 6, 12, 30, 65, 99, 87, 117, 118, 89, 95, 118, 96, 184, 126, 219, 126].

Test code

with open('whale2.txt', 'rb') as f:
 g = p()
 wrong = 0
 a = next(g)
 for b in f.read():
 wrong += a != b
 a = g.send(b)
 print(wrong)
Update for whale2.txt
Source Link
Anders Kaseorg
  • 40.7k
  • 3
  • 76
  • 149

Python 3, 2·2602·265 + 532465510291 = 532985510821

Predictor

def p():
 d={};s=b''
 while 1:
 p={0:1};r=range(len(s)+1)
 for i in r:
 for c,n in d.setdefault(s[:i],{}).items():p[c]=p.get(c,1)*n**b'1円6円16円$I`nnb_YqDrlfG'[i]*n**b'1円6円\r#Ihb~jzS177円M210円o{5'[i]
 c=yield max(sorted(p),key=p.get)
 for i in r:e=d[s[:i]];e[c]=e.get(c,1)+1
 s=b'%c'%c+s[:15]

This uses a weighted Bayesian combination of the order 0, ..., 16 Markov models, with weights [1, 6, 1413, 3635, 73, 96104, 11098, 110126, 98106, 95122, 8983, 113127, 6877, 114136, 108111, 102123, 71]53].

Test code

with open('whale.txt', 'rb') as f:
 g = p()
 wrong = 0
 a = next(g)
 for b in f.read():
 wrong += a != b
 a = g.send(b)
 print(wrong)

Python 3, 2·260 + 532465 = 532985

Predictor

def p():
 d={};s=b''
 while 1:
 p={0:1};r=range(len(s)+1)
 for i in r:
 for c,n in d.setdefault(s[:i],{}).items():p[c]=p.get(c,1)*n**b'1円6円16円$I`nnb_YqDrlfG'[i]
 c=yield max(sorted(p),key=p.get)
 for i in r:e=d[s[:i]];e[c]=e.get(c,1)+1
 s=b'%c'%c+s[:15]

This uses a weighted Bayesian combination of the order 0, ..., 16 Markov models, with weights [1, 6, 14, 36, 73, 96, 110, 110, 98, 95, 89, 113, 68, 114, 108, 102, 71].

Test code

with open('whale.txt', 'rb') as f:
 g = p()
 wrong = 0
 a = next(g)
 for b in f.read():
 wrong += a != b
 a = g.send(b)
 print(wrong)

Python 3, 2·265 + 510291 = 510821

Predictor

def p():
 d={};s=b''
 while 1:
 p={0:1};r=range(len(s)+1)
 for i in r:
 for c,n in d.setdefault(s[:i],{}).items():p[c]=p.get(c,1)*n**b'1円6円\r#Ihb~jzS177円M210円o{5'[i]
 c=yield max(sorted(p),key=p.get)
 for i in r:e=d[s[:i]];e[c]=e.get(c,1)+1
 s=b'%c'%c+s[:15]

This uses a weighted Bayesian combination of the order 0, ..., 16 Markov models, with weights [1, 6, 13, 35, 73, 104, 98, 126, 106, 122, 83, 127, 77, 136, 111, 123, 53].

Test code

with open('whale.txt', 'rb') as f:
 g = p()
 wrong = 0
 a = next(g)
 for b in f.read():
 wrong += a != b
 a = g.send(b)
 print(wrong)
−12
Source Link
Anders Kaseorg
  • 40.7k
  • 3
  • 76
  • 149
Loading
−42
Source Link
Anders Kaseorg
  • 40.7k
  • 3
  • 76
  • 149
Loading
−192
Source Link
Anders Kaseorg
  • 40.7k
  • 3
  • 76
  • 149
Loading
−3330
Source Link
Anders Kaseorg
  • 40.7k
  • 3
  • 76
  • 149
Loading
Sort for better determinism
Source Link
Anders Kaseorg
  • 40.7k
  • 3
  • 76
  • 149
Loading
deleted 17 characters in body
Source Link
Anders Kaseorg
  • 40.7k
  • 3
  • 76
  • 149
Loading
deleted 14 characters in body; deleted 17 characters in body
Source Link
Anders Kaseorg
  • 40.7k
  • 3
  • 76
  • 149
Loading
Source Link
Anders Kaseorg
  • 40.7k
  • 3
  • 76
  • 149
Loading

AltStyle によって変換されたページ (->オリジナル) /