Done challenge 9
[cipher-challenge.git] / 2020 / challenge3-clue.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 1,
6 "metadata": {
7 "Collapsed": "false"
8 },
9 "outputs": [],
10 "source": [
11 "from szyfrow.support.language_models import *\n",
12 "from szyfrow.support.utilities import *\n",
13 "import collections"
14 ]
15 },
16 {
17 "cell_type": "code",
18 "execution_count": 2,
19 "metadata": {
20 "Collapsed": "false"
21 },
22 "outputs": [
23 {
24 "data": {
25 "text/plain": [
26 "14843"
27 ]
28 },
29 "execution_count": 2,
30 "metadata": {},
31 "output_type": "execute_result"
32 }
33 ],
34 "source": [
35 "words8 = [w for w in keywords if len(w) == 8]\n",
36 "len(words8)"
37 ]
38 },
39 {
40 "cell_type": "code",
41 "execution_count": 3,
42 "metadata": {
43 "Collapsed": "false"
44 },
45 "outputs": [],
46 "source": [
47 "anags8 = collections.defaultdict(list)\n",
48 "for w in words8:\n",
49 " anags8[cat(sorted(w))] += [w]"
50 ]
51 },
52 {
53 "cell_type": "code",
54 "execution_count": 4,
55 "metadata": {
56 "Collapsed": "false"
57 },
58 "outputs": [
59 {
60 "data": {
61 "text/plain": [
62 "['aegilnrt', 'aeginrst', 'deeinrst', 'ceeprsst', 'aeinrrst']"
63 ]
64 },
65 "execution_count": 4,
66 "metadata": {},
67 "output_type": "execute_result"
68 }
69 ],
70 "source": [
71 "cands = [w for w in anags8 if len(anags8[w]) >= 5]\n",
72 "cands"
73 ]
74 },
75 {
76 "cell_type": "code",
77 "execution_count": 5,
78 "metadata": {
79 "Collapsed": "false"
80 },
81 "outputs": [
82 {
83 "name": "stdout",
84 "output_type": "stream",
85 "text": [
86 "aegilnrt ['alerting', 'altering', 'integral', 'relating', 'triangle']\n",
87 "aeginrst ['angriest', 'gantries', 'granites', 'ingrates', 'rangiest', 'tangiers']\n",
88 "deeinrst ['dniester', 'inserted', 'nerdiest', 'resident', 'trendies']\n",
89 "ceeprsst ['respects', 'scepters', 'sceptres', 'specters', 'spectres']\n",
90 "aeinrrst ['restrain', 'retrains', 'strainer', 'terrains', 'trainers']\n"
91 ]
92 }
93 ],
94 "source": [
95 "for c in cands:\n",
96 " print(c, anags8[c])"
97 ]
98 },
99 {
100 "cell_type": "code",
101 "execution_count": 13,
102 "metadata": {
103 "Collapsed": "false"
104 },
105 "outputs": [
106 {
107 "data": {
108 "text/plain": [
109 "\"alerting', 'altering', 'integral', 'relating', 'triangle', 'angriest', 'gantries', 'granites', 'ingrates', 'rangiest', 'tangiers', 'dniester', 'inserted', 'nerdiest', 'resident', 'trendies', 'respects', 'scepters', 'sceptres', 'specters', 'spectres', 'restrain', 'retrains', 'strainer', 'terrains', 'trainers\""
110 ]
111 },
112 "execution_count": 13,
113 "metadata": {},
114 "output_type": "execute_result"
115 }
116 ],
117 "source": [
118 "\"', '\".join(w for c in cands for w in anags8[c])"
119 ]
120 },
121 {
122 "cell_type": "code",
123 "execution_count": null,
124 "metadata": {
125 "Collapsed": "false"
126 },
127 "outputs": [],
128 "source": []
129 }
130 ],
131 "metadata": {
132 "kernelspec": {
133 "display_name": "Python 3",
134 "language": "python",
135 "name": "python3"
136 },
137 "language_info": {
138 "codemirror_mode": {
139 "name": "ipython",
140 "version": 3
141 },
142 "file_extension": ".py",
143 "mimetype": "text/x-python",
144 "name": "python",
145 "nbconvert_exporter": "python",
146 "pygments_lexer": "ipython3",
147 "version": "3.7.4"
148 }
149 },
150 "nbformat": 4,
151 "nbformat_minor": 4
152 }