+ {
+ "cell_type": "code",
+ "execution_count": 97,
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'dearu nclew ilhel masyo uprom isedw ethor oughl yenjo yedou rvisi ttoyo urcou sinin linco lnand found itmos tinfo rmati vesto ptheb eauti fulca thedr alalm ostju stifi edour visit onits ownan dourh ostss hared withu ssome inter estin gdraw ingso fthet owers youme ntion edsto pthey graci ously allow edmet ocopy thesk etche sande xplai nedmu chabo uthow theto wersa rebui ltand whyst opasu suali wills endyo umyno tesan dsket chesv iaour dearf riend jessi cawho haspr omise dtoen suret heirs afede liver ystop reall yimus tcong ratul ateou rhost sinth eloca lscou tgrou psfor thema rvell ouswa yinwh ichth eyhav eorga nised ourtr avelt hough someo fthes couts haveb eenra therm oreso licit ousth anweh adexp ected askin grath eralo tofqu estio nsabo utour plans stopg enera llyih opeth eywer esati sfied witht heans werst hatwe gaveb utwef eelth atwea reatr iskof overs tayin gourw elcom esowe willr eturn tolon donon tuesd aysto peven thoug hweha veenj oyedo urtim etoge thert hereh asbee nsome debat eamon gtheg roupa boutw herew eshou ldvis itnex tstop there areso manyi ntere sting sites tovis italo ngthe majes ticth amese stuar ysowe haved ecide dtosp litin totwo group sstop ralfw illle adone party onato uroft heken tcoas twhil eiamv erymu chloo kingf orwar dtoex plori ngthe essex marsh essto pdole tmekn owify ouhav eabet terid eabut ihave beent oldth atcan ewdon sfift eenth centu rychu rchaf fords anele vatio nwith awide viewo fthes urrou nding lands inthi sothe rwise rathe rflat lands capea ndist hesit eofan other fasci natin gtowe rwhic hiwil lbece rtain toske tchfo ryous topfi nally ifyou havea nyfur therr eques tsfor speci ficin forma tiont henpe rhaps youco uldle aveam essag eform eatth epost offic ether estop karlm essag eends'"
+ ]
+ },
+ "execution_count": 97,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "wcat(chunks(spb, 5))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 98,
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'uwlomwrlouiounoddsoiobiarmuirtsnhsduernwotsenoyiywtykeeiuowoaidtuisoontvrfdiorentserplsgluthauuralahhvadrthossbamothhpdnhouoorsgahhridtstebfharfsnwmernnndongajometheetngawwusxpeoiegssoesheredepnoppweeyotnslvuofrxiexhoenyvtdtethnnthuufseoheosugsieeetsattnrinecleneosiyuarrsrinatesoemgmhtcrpmgs'"
+ ]
+ },
+ "execution_count": 98,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "cat(w[-1] for w in chunks(spb, 5))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 99,
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(87, 47, 35)"
+ ]
+ },
+ "execution_count": 99,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "locR = [i for i, c in enumerate(spb) if c == 'r']\n",
+ "locD = [i for i, c in enumerate(spb) if c == 'd']\n",
+ "locF = [i for i, c in enumerate(spb) if c == 'f']\n",
+ "len(locR), len(locD), len(locF)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 100,
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[(3, 586, 1169, 583),\n",
+ " (34, 350, 666, 316),\n",
+ " (50, 519, 988, 469),\n",
+ " (124, 395, 666, 271),\n",
+ " (163, 769, 1375, 606),\n",
+ " (197, 337, 477, 140),\n",
+ " (305, 337, 369, 32),\n",
+ " (368, 769, 1170, 401),\n",
+ " (370, 866, 1362, 496),\n",
+ " (419, 830, 1241, 411),\n",
+ " (440, 769, 1098, 329),\n",
+ " (450, 798, 1146, 348),\n",
+ " (485, 958, 1431, 473),\n",
+ " (512, 830, 1148, 318),\n",
+ " (522, 594, 666, 72),\n",
+ " (558, 960, 1362, 402),\n",
+ " (563, 866, 1169, 303),\n",
+ " (976, 1173, 1370, 197),\n",
+ " (1002, 1086, 1170, 84),\n",
+ " (1011, 1193, 1375, 182),\n",
+ " (1160, 1248, 1336, 88),\n",
+ " (1165, 1256, 1347, 91)]"
+ ]
+ },
+ "execution_count": 100,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "triples = []\n",
+ "for r in locR:\n",
+ " for d in locD:\n",
+ " for f in locF:\n",
+ " if d > r:\n",
+ " if d - r == f - d:\n",
+ " triples += [(r, d, f, d - r)]\n",
+ "triples"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 101,
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "dearunclewilhelma s youpromisedwet\n",
+ "horoughlyenjoyedo u rvisittoyourco\n",
+ "usininlincolnandf o unditmostinfor\n",
+ "mativestopthebeau t ifulcathedrala\n",
+ "lmostjustifiedour v isitonitsownan\n",
+ "dourhostssharedwi t hussomeinteres\n",
+ "tingdrawingsofthe t owersyoumentio\n",
+ "nedstoptheygracio u slyallowedmeto\n",
+ "copythesketchesan d explainedmucha\n",
+ "bouthowthetowersa r ebuiltandwhyst\n",
+ "opasusualiwillsen d youmynotesands\n",
+ "ketchesviaourdear f riendjessicawh\n",
+ "ohaspromisedtoens u retheirsafedel\n",
+ "iverystopreallyim u stcongratulate\n",
+ "ourhostsintheloca l scoutgroupsfor\n",
+ "themarvellouswayi n whichtheyhaveo\n",
+ "rganisedourtravel t houghsomeofthe\n",
+ "scoutshavebeenrat h ermoresolicito\n",
+ "usthanwehadexpect e daskingrathera\n",
+ "lotofquestionsabo u tourplansstopg\n",
+ "enerallyihopethey w eresatisfiedwi\n",
+ "ththeanswersthatw e gavebutwefeelt\n",
+ "hatweareatriskofo v erstayingourwe\n",
+ "lcomesowewillretu r ntolondonontue\n",
+ "sdaystopeventhoug h wehaveenjoyedo\n",
+ "urtimetogetherthe r ehasbeensomede\n",
+ "bateamongthegroup a boutwherewesho\n",
+ "uldvisitnextstopt h erearesomanyin\n",
+ "terestingsitestov i sitalongthemaj\n",
+ "esticthamesestuar y sowehavedecide\n",
+ "dtosplitintotwogr o upsstopralfwil\n",
+ "lleadonepartyonat o urofthekentcoa\n",
+ "stwhileiamverymuc h lookingforward\n",
+ "toexploringtheess e xmarshesstopdo\n",
+ "letmeknowifyouhav e abetterideabut\n",
+ "ihavebeentoldthat c anewdonsfiftee\n",
+ "nthcenturychurcha f fordsanelevati\n",
+ "onwithawideviewof t hesurroundingl\n",
+ "andsinthisotherwi s eratherflatlan\n",
+ "dscapeandisthesit e ofanotherfasci\n",
+ "natingtowerwhichi w illbecertainto\n",
+ "sketchforyoustopf i nallyifyouhave\n",
+ "anyfurtherrequest s forspecificinf\n",
+ "ormationthenperha p syoucouldleave\n",
+ "amessageformeatth e postofficether\n",
+ "estopkarlmessagee n ds\n"
+ ]
+ }
+ ],
+ "source": [
+ "t = cat(c if c.isupper() else '.' for c in pbscap)\n",
+ "col = 305 % 32\n",
+ "tcs = chunks(spb, 32)\n",
+ "stcs = [wcat([c[:col], c[col], c[col+1:]]) for c in tcs]\n",
+ "print(lcat(stcs))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 102,
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "780"
+ ]
+ },
+ "execution_count": 102,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "results = []\n",
+ "for l in range(1, 40):\n",
+ " for i in range(l):\n",
+ " cs = chunks(spb, l, fillvalue=' ')\n",
+ " t = cat(c[i] for c in cs)\n",
+ " f = Ptrigrams(t)\n",
+ " results += [{'l': l, 'i': i, 't': t, 'f': f * l}]\n",
+ "len(results)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 103,
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[{'l': 39,\n",
+ " 'i': 37,\n",
+ " 't': 'gnfsihalnpaseseasemerenhworttaragsods ',\n",
+ " 'f': -5279.032049169729},\n",
+ " {'l': 38,\n",
+ " 'i': 35,\n",
+ " 't': 'ocatteseoslsuteerefloatsoralycanaepsls ',\n",
+ " 'f': -5213.417095225861},\n",
+ " {'l': 39,\n",
+ " 'i': 24,\n",
+ " 't': 'mosdsepenjessoloitatmeegdemraceshotes ',\n",
+ " 'f': -5197.69063368185},\n",
+ " {'l': 1,\n",
+ " 'i': 0,\n",
+ " 't': 'dearunclewilhelmasyoupromisedwethoroughlyenjoyedourvisittoyourcousininlincolnandfounditmostinformativestopthebeautifulcathedralalmostjustifiedourvisitonitsownandourhostssharedwithussomeinterestingdrawingsofthetowersyoumentionedstoptheygraciouslyallowedmetocopythesketchesandexplainedmuchabouthowthetowersarebuiltandwhystopasusualiwillsendyoumynotesandsketchesviaourdearfriendjessicawhohaspromisedtoensuretheirsafedeliverystopreallyimustcongratulateourhostsinthelocalscoutgroupsforthemarvellouswayinwhichtheyhaveorganisedourtravelthoughsomeofthescoutshavebeenrathermoresolicitousthanwehadexpectedaskingratheralotofquestionsaboutourplansstopgenerallyihopetheyweresatisfiedwiththeanswersthatwegavebutwefeelthatweareatriskofoverstayingourwelcomesowewillreturntolondonontuesdaystopeventhoughwehaveenjoyedourtimetogethertherehasbeensomedebateamongthegroupaboutwhereweshouldvisitnextstoptherearesomanyinterestingsitestovisitalongthemajesticthamesestuarysowehavedecidedtosplitintotwogroupsstopralfwillleadonepartyonatourofthekentcoastwhileiamverymuchlookingforwardtoexploringtheessexmarshesstopdoletmeknowifyouhaveabetterideabutihavebeentoldthatcanewdonsfifteenthcenturychurchaffordsanelevationwithawideviewofthesurroundinglandsinthisotherwiseratherflatlandscapeandisthesiteofanotherfascinatingtowerwhichiwillbecertaintosketchforyoustopfinallyifyouhaveanyfurtherrequestsforspecificinformationthenperhapsyoucouldleaveamessageformeatthepostofficetherestopkarlmessageends',\n",
+ " 'f': -4923.336122800165}]"
+ ]
+ },
+ "execution_count": 103,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "list(sorted(results, key=lambda r: r['f']))[-4:]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 104,
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "1"
+ ]
+ },
+ "execution_count": 104,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "rdfresults = [r for r in results if 'rdf' in r['t']]\n",
+ "len(rdfresults)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 105,
+ "metadata": {
+ "Collapsed": "false"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[{'l': 32,\n",
+ " 'i': 17,\n",
+ " 't': 'suotvttudrdfuulntheuwevrhrahiyooheecftsewispen',\n",
+ " 'f': -6630.535098505313}]"
+ ]
+ },
+ "execution_count": 105,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "rdfresults"
+ ]
+ },