Setup¶

In [1]:
import matplotlib.pyplot as plt
import seaborn as sns

Constants and Functions¶

In [2]:
#Probabilty that the character index is a space.
space_p = {1 : 0,
           2 : 0,
           3 : 0,
           4 : 0.5,
           5 : 0.5,
           6 : 0,
           7 : 0,
           11 : 0}



#Make the line very, very, long.
for i in range(4, 501) :
    p = space_p[i]
    
    #If it has a space
    if p != 0 :
        #Half the time 4 characters away will be a space,
        #half the time 5 characters away will be a space.
        for j in (4,5) :
            #Exists already.
            if (i+j) in space_p.keys() :
                space_p[i+j] += 0.5*p
            #New.
            else :
                space_p[i+j] = 0.5*p
                

                
#Expected length.
EL = 0
ELs = {}
#Current probability.
P = 1

#Where does the river stop?
for i in range(12, 501):
    
    #length
    L = i-11
    
    #Next
    N = space_p[i+1]
    
    #EL increases by current length * current probability * probability of letter for this character.
    EL += L*P*(1-N)
    #Dict
    ELs[i] = EL
    #Or this character is a space, update probability.
    P *= N              
In [3]:
ELs 
Out[3]:
{12: 0.625,
 13: 1.09375,
 14: 1.462890625,
 15: 1.52880859375,
 16: 1.532928466796875,
 17: 1.5339584350585938,
 18: 1.534499168395996,
 19: 1.5346858501434326,
 20: 1.5347041813656688,
 21: 1.5347067745169625,
 22: 1.5347076659127197,
 23: 1.5347080319559154,
 24: 1.5347081039703099,
 25: 1.5347081124527746,
 26: 1.5347081143655024,
 27: 1.5347081150682849,
 28: 1.5347081152715,
 29: 1.5347081153022673,
 30: 1.534708115307436,
 31: 1.5347081153089157,
 32: 1.5347081153093955,
 33: 1.5347081153094975,
 34: 1.5347081153095137,
 35: 1.5347081153095172,
 36: 1.5347081153095183,
 37: 1.5347081153095186,
 38: 1.5347081153095186,
 39: 1.5347081153095186,
 40: 1.5347081153095186,
 41: 1.5347081153095186,
 42: 1.5347081153095186,
 43: 1.5347081153095186,
 44: 1.5347081153095186,
 45: 1.5347081153095186,
 46: 1.5347081153095186,
 47: 1.5347081153095186,
 48: 1.5347081153095186,
 49: 1.5347081153095186,
 50: 1.5347081153095186,
 51: 1.5347081153095186,
 52: 1.5347081153095186,
 53: 1.5347081153095186,
 54: 1.5347081153095186,
 55: 1.5347081153095186,
 56: 1.5347081153095186,
 57: 1.5347081153095186,
 58: 1.5347081153095186,
 59: 1.5347081153095186,
 60: 1.5347081153095186,
 61: 1.5347081153095186,
 62: 1.5347081153095186,
 63: 1.5347081153095186,
 64: 1.5347081153095186,
 65: 1.5347081153095186,
 66: 1.5347081153095186,
 67: 1.5347081153095186,
 68: 1.5347081153095186,
 69: 1.5347081153095186,
 70: 1.5347081153095186,
 71: 1.5347081153095186,
 72: 1.5347081153095186,
 73: 1.5347081153095186,
 74: 1.5347081153095186,
 75: 1.5347081153095186,
 76: 1.5347081153095186,
 77: 1.5347081153095186,
 78: 1.5347081153095186,
 79: 1.5347081153095186,
 80: 1.5347081153095186,
 81: 1.5347081153095186,
 82: 1.5347081153095186,
 83: 1.5347081153095186,
 84: 1.5347081153095186,
 85: 1.5347081153095186,
 86: 1.5347081153095186,
 87: 1.5347081153095186,
 88: 1.5347081153095186,
 89: 1.5347081153095186,
 90: 1.5347081153095186,
 91: 1.5347081153095186,
 92: 1.5347081153095186,
 93: 1.5347081153095186,
 94: 1.5347081153095186,
 95: 1.5347081153095186,
 96: 1.5347081153095186,
 97: 1.5347081153095186,
 98: 1.5347081153095186,
 99: 1.5347081153095186,
 100: 1.5347081153095186,
 101: 1.5347081153095186,
 102: 1.5347081153095186,
 103: 1.5347081153095186,
 104: 1.5347081153095186,
 105: 1.5347081153095186,
 106: 1.5347081153095186,
 107: 1.5347081153095186,
 108: 1.5347081153095186,
 109: 1.5347081153095186,
 110: 1.5347081153095186,
 111: 1.5347081153095186,
 112: 1.5347081153095186,
 113: 1.5347081153095186,
 114: 1.5347081153095186,
 115: 1.5347081153095186,
 116: 1.5347081153095186,
 117: 1.5347081153095186,
 118: 1.5347081153095186,
 119: 1.5347081153095186,
 120: 1.5347081153095186,
 121: 1.5347081153095186,
 122: 1.5347081153095186,
 123: 1.5347081153095186,
 124: 1.5347081153095186,
 125: 1.5347081153095186,
 126: 1.5347081153095186,
 127: 1.5347081153095186,
 128: 1.5347081153095186,
 129: 1.5347081153095186,
 130: 1.5347081153095186,
 131: 1.5347081153095186,
 132: 1.5347081153095186,
 133: 1.5347081153095186,
 134: 1.5347081153095186,
 135: 1.5347081153095186,
 136: 1.5347081153095186,
 137: 1.5347081153095186,
 138: 1.5347081153095186,
 139: 1.5347081153095186,
 140: 1.5347081153095186,
 141: 1.5347081153095186,
 142: 1.5347081153095186,
 143: 1.5347081153095186,
 144: 1.5347081153095186,
 145: 1.5347081153095186,
 146: 1.5347081153095186,
 147: 1.5347081153095186,
 148: 1.5347081153095186,
 149: 1.5347081153095186,
 150: 1.5347081153095186,
 151: 1.5347081153095186,
 152: 1.5347081153095186,
 153: 1.5347081153095186,
 154: 1.5347081153095186,
 155: 1.5347081153095186,
 156: 1.5347081153095186,
 157: 1.5347081153095186,
 158: 1.5347081153095186,
 159: 1.5347081153095186,
 160: 1.5347081153095186,
 161: 1.5347081153095186,
 162: 1.5347081153095186,
 163: 1.5347081153095186,
 164: 1.5347081153095186,
 165: 1.5347081153095186,
 166: 1.5347081153095186,
 167: 1.5347081153095186,
 168: 1.5347081153095186,
 169: 1.5347081153095186,
 170: 1.5347081153095186,
 171: 1.5347081153095186,
 172: 1.5347081153095186,
 173: 1.5347081153095186,
 174: 1.5347081153095186,
 175: 1.5347081153095186,
 176: 1.5347081153095186,
 177: 1.5347081153095186,
 178: 1.5347081153095186,
 179: 1.5347081153095186,
 180: 1.5347081153095186,
 181: 1.5347081153095186,
 182: 1.5347081153095186,
 183: 1.5347081153095186,
 184: 1.5347081153095186,
 185: 1.5347081153095186,
 186: 1.5347081153095186,
 187: 1.5347081153095186,
 188: 1.5347081153095186,
 189: 1.5347081153095186,
 190: 1.5347081153095186,
 191: 1.5347081153095186,
 192: 1.5347081153095186,
 193: 1.5347081153095186,
 194: 1.5347081153095186,
 195: 1.5347081153095186,
 196: 1.5347081153095186,
 197: 1.5347081153095186,
 198: 1.5347081153095186,
 199: 1.5347081153095186,
 200: 1.5347081153095186,
 201: 1.5347081153095186,
 202: 1.5347081153095186,
 203: 1.5347081153095186,
 204: 1.5347081153095186,
 205: 1.5347081153095186,
 206: 1.5347081153095186,
 207: 1.5347081153095186,
 208: 1.5347081153095186,
 209: 1.5347081153095186,
 210: 1.5347081153095186,
 211: 1.5347081153095186,
 212: 1.5347081153095186,
 213: 1.5347081153095186,
 214: 1.5347081153095186,
 215: 1.5347081153095186,
 216: 1.5347081153095186,
 217: 1.5347081153095186,
 218: 1.5347081153095186,
 219: 1.5347081153095186,
 220: 1.5347081153095186,
 221: 1.5347081153095186,
 222: 1.5347081153095186,
 223: 1.5347081153095186,
 224: 1.5347081153095186,
 225: 1.5347081153095186,
 226: 1.5347081153095186,
 227: 1.5347081153095186,
 228: 1.5347081153095186,
 229: 1.5347081153095186,
 230: 1.5347081153095186,
 231: 1.5347081153095186,
 232: 1.5347081153095186,
 233: 1.5347081153095186,
 234: 1.5347081153095186,
 235: 1.5347081153095186,
 236: 1.5347081153095186,
 237: 1.5347081153095186,
 238: 1.5347081153095186,
 239: 1.5347081153095186,
 240: 1.5347081153095186,
 241: 1.5347081153095186,
 242: 1.5347081153095186,
 243: 1.5347081153095186,
 244: 1.5347081153095186,
 245: 1.5347081153095186,
 246: 1.5347081153095186,
 247: 1.5347081153095186,
 248: 1.5347081153095186,
 249: 1.5347081153095186,
 250: 1.5347081153095186,
 251: 1.5347081153095186,
 252: 1.5347081153095186,
 253: 1.5347081153095186,
 254: 1.5347081153095186,
 255: 1.5347081153095186,
 256: 1.5347081153095186,
 257: 1.5347081153095186,
 258: 1.5347081153095186,
 259: 1.5347081153095186,
 260: 1.5347081153095186,
 261: 1.5347081153095186,
 262: 1.5347081153095186,
 263: 1.5347081153095186,
 264: 1.5347081153095186,
 265: 1.5347081153095186,
 266: 1.5347081153095186,
 267: 1.5347081153095186,
 268: 1.5347081153095186,
 269: 1.5347081153095186,
 270: 1.5347081153095186,
 271: 1.5347081153095186,
 272: 1.5347081153095186,
 273: 1.5347081153095186,
 274: 1.5347081153095186,
 275: 1.5347081153095186,
 276: 1.5347081153095186,
 277: 1.5347081153095186,
 278: 1.5347081153095186,
 279: 1.5347081153095186,
 280: 1.5347081153095186,
 281: 1.5347081153095186,
 282: 1.5347081153095186,
 283: 1.5347081153095186,
 284: 1.5347081153095186,
 285: 1.5347081153095186,
 286: 1.5347081153095186,
 287: 1.5347081153095186,
 288: 1.5347081153095186,
 289: 1.5347081153095186,
 290: 1.5347081153095186,
 291: 1.5347081153095186,
 292: 1.5347081153095186,
 293: 1.5347081153095186,
 294: 1.5347081153095186,
 295: 1.5347081153095186,
 296: 1.5347081153095186,
 297: 1.5347081153095186,
 298: 1.5347081153095186,
 299: 1.5347081153095186,
 300: 1.5347081153095186,
 301: 1.5347081153095186,
 302: 1.5347081153095186,
 303: 1.5347081153095186,
 304: 1.5347081153095186,
 305: 1.5347081153095186,
 306: 1.5347081153095186,
 307: 1.5347081153095186,
 308: 1.5347081153095186,
 309: 1.5347081153095186,
 310: 1.5347081153095186,
 311: 1.5347081153095186,
 312: 1.5347081153095186,
 313: 1.5347081153095186,
 314: 1.5347081153095186,
 315: 1.5347081153095186,
 316: 1.5347081153095186,
 317: 1.5347081153095186,
 318: 1.5347081153095186,
 319: 1.5347081153095186,
 320: 1.5347081153095186,
 321: 1.5347081153095186,
 322: 1.5347081153095186,
 323: 1.5347081153095186,
 324: 1.5347081153095186,
 325: 1.5347081153095186,
 326: 1.5347081153095186,
 327: 1.5347081153095186,
 328: 1.5347081153095186,
 329: 1.5347081153095186,
 330: 1.5347081153095186,
 331: 1.5347081153095186,
 332: 1.5347081153095186,
 333: 1.5347081153095186,
 334: 1.5347081153095186,
 335: 1.5347081153095186,
 336: 1.5347081153095186,
 337: 1.5347081153095186,
 338: 1.5347081153095186,
 339: 1.5347081153095186,
 340: 1.5347081153095186,
 341: 1.5347081153095186,
 342: 1.5347081153095186,
 343: 1.5347081153095186,
 344: 1.5347081153095186,
 345: 1.5347081153095186,
 346: 1.5347081153095186,
 347: 1.5347081153095186,
 348: 1.5347081153095186,
 349: 1.5347081153095186,
 350: 1.5347081153095186,
 351: 1.5347081153095186,
 352: 1.5347081153095186,
 353: 1.5347081153095186,
 354: 1.5347081153095186,
 355: 1.5347081153095186,
 356: 1.5347081153095186,
 357: 1.5347081153095186,
 358: 1.5347081153095186,
 359: 1.5347081153095186,
 360: 1.5347081153095186,
 361: 1.5347081153095186,
 362: 1.5347081153095186,
 363: 1.5347081153095186,
 364: 1.5347081153095186,
 365: 1.5347081153095186,
 366: 1.5347081153095186,
 367: 1.5347081153095186,
 368: 1.5347081153095186,
 369: 1.5347081153095186,
 370: 1.5347081153095186,
 371: 1.5347081153095186,
 372: 1.5347081153095186,
 373: 1.5347081153095186,
 374: 1.5347081153095186,
 375: 1.5347081153095186,
 376: 1.5347081153095186,
 377: 1.5347081153095186,
 378: 1.5347081153095186,
 379: 1.5347081153095186,
 380: 1.5347081153095186,
 381: 1.5347081153095186,
 382: 1.5347081153095186,
 383: 1.5347081153095186,
 384: 1.5347081153095186,
 385: 1.5347081153095186,
 386: 1.5347081153095186,
 387: 1.5347081153095186,
 388: 1.5347081153095186,
 389: 1.5347081153095186,
 390: 1.5347081153095186,
 391: 1.5347081153095186,
 392: 1.5347081153095186,
 393: 1.5347081153095186,
 394: 1.5347081153095186,
 395: 1.5347081153095186,
 396: 1.5347081153095186,
 397: 1.5347081153095186,
 398: 1.5347081153095186,
 399: 1.5347081153095186,
 400: 1.5347081153095186,
 401: 1.5347081153095186,
 402: 1.5347081153095186,
 403: 1.5347081153095186,
 404: 1.5347081153095186,
 405: 1.5347081153095186,
 406: 1.5347081153095186,
 407: 1.5347081153095186,
 408: 1.5347081153095186,
 409: 1.5347081153095186,
 410: 1.5347081153095186,
 411: 1.5347081153095186,
 412: 1.5347081153095186,
 413: 1.5347081153095186,
 414: 1.5347081153095186,
 415: 1.5347081153095186,
 416: 1.5347081153095186,
 417: 1.5347081153095186,
 418: 1.5347081153095186,
 419: 1.5347081153095186,
 420: 1.5347081153095186,
 421: 1.5347081153095186,
 422: 1.5347081153095186,
 423: 1.5347081153095186,
 424: 1.5347081153095186,
 425: 1.5347081153095186,
 426: 1.5347081153095186,
 427: 1.5347081153095186,
 428: 1.5347081153095186,
 429: 1.5347081153095186,
 430: 1.5347081153095186,
 431: 1.5347081153095186,
 432: 1.5347081153095186,
 433: 1.5347081153095186,
 434: 1.5347081153095186,
 435: 1.5347081153095186,
 436: 1.5347081153095186,
 437: 1.5347081153095186,
 438: 1.5347081153095186,
 439: 1.5347081153095186,
 440: 1.5347081153095186,
 441: 1.5347081153095186,
 442: 1.5347081153095186,
 443: 1.5347081153095186,
 444: 1.5347081153095186,
 445: 1.5347081153095186,
 446: 1.5347081153095186,
 447: 1.5347081153095186,
 448: 1.5347081153095186,
 449: 1.5347081153095186,
 450: 1.5347081153095186,
 451: 1.5347081153095186,
 452: 1.5347081153095186,
 453: 1.5347081153095186,
 454: 1.5347081153095186,
 455: 1.5347081153095186,
 456: 1.5347081153095186,
 457: 1.5347081153095186,
 458: 1.5347081153095186,
 459: 1.5347081153095186,
 460: 1.5347081153095186,
 461: 1.5347081153095186,
 462: 1.5347081153095186,
 463: 1.5347081153095186,
 464: 1.5347081153095186,
 465: 1.5347081153095186,
 466: 1.5347081153095186,
 467: 1.5347081153095186,
 468: 1.5347081153095186,
 469: 1.5347081153095186,
 470: 1.5347081153095186,
 471: 1.5347081153095186,
 472: 1.5347081153095186,
 473: 1.5347081153095186,
 474: 1.5347081153095186,
 475: 1.5347081153095186,
 476: 1.5347081153095186,
 477: 1.5347081153095186,
 478: 1.5347081153095186,
 479: 1.5347081153095186,
 480: 1.5347081153095186,
 481: 1.5347081153095186,
 482: 1.5347081153095186,
 483: 1.5347081153095186,
 484: 1.5347081153095186,
 485: 1.5347081153095186,
 486: 1.5347081153095186,
 487: 1.5347081153095186,
 488: 1.5347081153095186,
 489: 1.5347081153095186,
 490: 1.5347081153095186,
 491: 1.5347081153095186,
 492: 1.5347081153095186,
 493: 1.5347081153095186,
 494: 1.5347081153095186,
 495: 1.5347081153095186,
 496: 1.5347081153095186,
 497: 1.5347081153095186,
 498: 1.5347081153095186,
 499: 1.5347081153095186,
 500: 1.5347081153095186}
In [4]:
sns.set()
fig = plt.figure(figsize = (12, 8))
ax = fig.add_subplot(xlim = (12, 50), ylim = (0, 1.65))


#3 Scatter Plots.
ax.scatter(x = list(ELs.keys()),
           y = list(ELs.values()),
           c = "#238A8D",
           lw = 3,
           label = "Expected Length")

ax.hlines(y = ELs[500],
           xmin = 12,
           xmax = 50,
           color = "#238A8D",
           ls = ':',
           lw = 2,
           label = "EL ≈ 1.534708115")

ax.scatter(x = list(space_p.keys()),
           y = list(space_p.values()),
           c = "#440154",
           lw = 3,
           label = "P(Char) = Space")

ax.hlines(y = 2/9,
           xmin = 12,
           xmax = 50,
           color = "#440154",
           ls = ':',
           lw = 2,
           label = "P = 2/9")

#Titles, Axes, & Legend
ax.set_title("How Long is the River?", fontsize = 24)
ax.set_xlabel("Character Location in Line", fontsize = 20)
ax.set_xticks([4*x for x in range(3, 13)])
ax.set_ylabel("Probability / Expected Length", fontsize = 18);
ax.tick_params('both', labelsize =  '20')
ax.legend(fontsize = '16', loc = 'center right')

fig.savefig('2025.05.23 FiddlerEC.png');

Rohan Lewis¶

2025.05.12¶

In [ ]: