41 "<style>/* Styles used for the Hoogle display in the pager */\n",
44 "padding-bottom: 1.3em;\n",
45 "padding-left: 0.4em;\n",
49 "font-family: monospace;\n",
50 "white-space: pre;\n",
57 "font-weight: bold;\n",
60 "font-weight: bold;\n",
64 "margin-left: 0.4em;\n",
66 ".hoogle-package {\n",
67 "font-weight: bold;\n",
68 "font-style: italic;\n",
71 "font-weight: bold;\n",
74 "font-weight: bold;\n",
78 "font-weight: bold;\n",
79 "font-family: monospace;\n",
81 "white-space: pre-wrap;\n",
85 "font-weight: bold;\n",
86 "font-family: monospace;\n",
87 "margin-left: 1em;\n",
90 "font-family: monospace;\n",
95 "font-style: italic;\n",
96 "font-family: monospace;\n",
97 "white-space: pre;\n",
102 "font-weight: bold;\n",
104 ".err-msg.in.collapse {\n",
105 "padding-top: 0.7em;\n",
107 ".highlight-code {\n",
108 "white-space: pre;\n",
109 "font-family: monospace;\n",
111 ".suggestion-warning { \n",
112 "font-weight: bold;\n",
113 "color: rgb(200, 130, 0);\n",
115 ".suggestion-error { \n",
116 "font-weight: bold;\n",
119 ".suggestion-name {\n",
120 "font-weight: bold;\n",
122 "</style><div class=\"suggestion-name\" style=\"clear:both;\">Redundant bracket</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">(fromIntegral a) * b</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Why Not:</div><div class=\"highlight-code\" id=\"haskell\">fromIntegral a * b</div></div>"
125 "Line 1: Redundant bracket\n",
127 "(fromIntegral a) * b\n",
133 "output_type": "display_data"
142 "output_type": "display_data"
146 "(fromIntegral a) * b"
151 "execution_count": 5,
161 "output_type": "display_data"
165 "(156 * 202) `mod` 256"
169 "cell_type": "markdown",
172 "Generator A starts with 873\n",
174 "Generator B starts with 583"
179 "execution_count": 6,
183 "generator :: Word64 -> Word64 -> Word64 -> Word64\n",
184 "generator divisor factor n = fromIntegral $ fromIntegral n * factor `rem` divisor"
189 "execution_count": 7,
193 "generatorA = generator 2147483647 16807\n",
194 "generatorB = generator 2147483647 48271"
199 "execution_count": 8,
203 "toWord16 :: Word64 -> Word16\n",
204 "toWord16 = fromIntegral"
209 "execution_count": 9,
215 "[43879,63289,58186,5831,38948]"
219 "output_type": "display_data"
223 "map toWord16 $ take 5 $ drop 1 $ iterate generatorA 65"
228 "execution_count": 10,
234 "[54071,34184,58186,52231,10244]"
238 "output_type": "display_data"
242 "map toWord16 $ take 5 $ drop 1 $ iterate generatorB 8921"
247 "execution_count": 11,
251 "stream :: (Word64 -> Word64) -> Word64 -> [Word16]\n",
252 "stream gen n0 = map toWord16 $ drop 1 $ iterate gen n0"
257 "execution_count": 12,
267 "output_type": "display_data"
271 "length $ filter (uncurry (==)) $ take 40000000 $ zip (stream generatorA 65) (stream generatorB 8921)"
276 "execution_count": 13,
286 "output_type": "display_data"
290 "length $ filter (uncurry (==)) $ take 40000000 $ zip (stream generatorA 873) (stream generatorB 583)"
295 "execution_count": 14,
299 "filteredStream :: Word16 -> [Word16] -> [Word16]\n",
300 "filteredStream f stream = filter (\\n -> n .&. f == 0) stream"
305 "execution_count": 15,
311 "[38948,48816,54372,43440,40536]"
315 "output_type": "display_data"
319 "take 5 $ filteredStream 3 $ stream generatorA 65"
324 "execution_count": 16,
334 "output_type": "display_data"
338 "toWord16 1352636452"
343 "execution_count": 17,
349 "[1352636452,1992081072,530830436,1980017072,740335192]"
353 "output_type": "display_data"
357 "take 5 $ filter (\\n -> n .&. 3 == 0) $ iterate generatorA 65"
362 "execution_count": 29,
368 "[1233683848,862516352,1159784568,1616057672,412269392]"
372 "output_type": "display_data"
376 "take 5 $ filter (\\n -> n .&. 7 == 0) $ iterate generatorB 8921"
381 "execution_count": 34,
385 "solE = length $ filter (uncurry (==)) $ take 5000000 $ zip fsA fsB\n",
386 " where fsA = filteredStream 3 $ stream generatorA 65\n",
387 " fsB = filteredStream 7 $ stream generatorB 8921"
392 "execution_count": 35,
402 "output_type": "display_data"
411 "execution_count": 32,
415 "sol = length $ filter (uncurry (==)) $ take 5000000 $ zip fsA fsB\n",
416 " where fsA = filteredStream 3 $ stream generatorA 873\n",
417 " fsB = filteredStream 7 $ stream generatorB 583"
422 "execution_count": 33,
432 "output_type": "display_data"
441 "execution_count": null,
449 "display_name": "Haskell",
450 "language": "haskell",
454 "codemirror_mode": "ihaskell",
455 "file_extension": ".hs",