Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.75 KB | None | 0 0
  1. use itertools::iproduct;
  2. use std::collections::HashMap; // 0.8.0
  3.  
  4. fn main() {
  5. let input = "auxwcbzrmdvpsjfgkrthnkioqm
  6. auxwcbzrmdvpsjfgbltonyijqe
  7. auxwcbzrmdfpsefgklthnoioqe
  8. auxwcbzrmdvpsjfgkluhnjisqe
  9. auxwcbzrmdvesjfgdzthnyioqe
  10. auxwcbzrmdvhsjfgklthnmijqe
  11. auxwcbzridvpsjfgkltxeyioqe
  12. ayxwcbzrgdvpsjfgklthiyioqe
  13. ajxwcbzrmdvpsjfgklkhnyiode
  14. auxwcbcrmdvpsjfqelthnyioqe
  15. auxwcbzrmsvpsjsgklthnyiope
  16. auxwcbzrmqvpsjzgklghnyioqe
  17. auxwcbzrmdvpsjtqklthxyioqe
  18. auxwcbzrmdopsjfdklthncioqe
  19. auxwcbzrmdvpsjfgkltmhyfoqe
  20. aixwcbzrmdvpsjfgllthdyeoqe
  21. vuxicbzrmdepsjfgklthnyioqe
  22. auxwcbbxmdkpsjfgklthnyioqe
  23. auxwcbzrgdvpsofaklthnyioqe
  24. auxycbzrmdvpsjfgklthnyuose
  25. aujwcbzrmdvprjfgkltcnyioqe
  26. auxwgbzrmdvpsjfgyzthnyioqe
  27. auxwcbzrmavpsjfgkltsnyiome
  28. auxwcbgrmdvpsjfgkdthnrioqe
  29. kuxwcbzrmdvpsyfgklthnyioue
  30. auxwcbzomdvpjdfgklthnyioqe
  31. auxwcbzrmdppsjfgklthvyifqe
  32. aunwubzrmdvpsjrgklthnyioqe
  33. auxwcbzrmoipsjfgklbhnyioqe
  34. auxwdbzrmdvpsjfgmlthnyioce
  35. auxwcbzjmsvpsjfiklthnyioqe
  36. auxwcbzrmwcpsjfcklthnyioqe
  37. auxwcbzfmdvprjfhklthnyioqe
  38. auxdcbzrgdvpsjfgklthnyxoqe
  39. wuxwbbzrmdvpsjfgklthnyiote
  40. auowcbjrmdvpsjfgklthnyfoqe
  41. auxwsbzrmdvpsjfglltcnyioqe
  42. quxwcbzrmdvpkjfgklthnyioqt
  43. vuxwcbzrudvpsjfgklthnyioqi
  44. puxwcbzrmdvgsjfgklthncioqe
  45. luxdcbzrmdvpsjfgkothnyioqe
  46. auxwcbzrmdvpsjfyklthfhioqe
  47. auxwcbqrmdvpsjfgkldhnyiote
  48. quxwcbzrmlvpsjfgklthnyioqi
  49. auxwcbzgmdvpsjfoklthnyiuqe
  50. auxwcbzrmdvpsbfgkltdjyioqe
  51. auxwcbzsmdrpsjfgklthpyioqe
  52. auxwcbzrmfvpsjfwklthnyiote
  53. auxbkpzrmdvpsjfgklthnyioqe
  54. auxwcbzrddvpsjfsklthnyroqe
  55. abxwcbzrmdvpsjfgkltdnyivqe
  56. awxwcbzrmvvpsjfgklthngioqe
  57. auxwcbzrmkvgsjfgkltcnyioqe
  58. auxwcbammdvpsjfgklthpyioqe
  59. auxwcbhrmdvpsjfgtlthnuioqe
  60. auxwcpzrmdvpbjogklthnyioqe
  61. auxwcbzrmdvpslfgklbhkyioqe
  62. auxwcbsrmdvpjjfgkldhnyioqe
  63. auxwcbzrmdqpsjfgauthnyioqe
  64. ydxwcbxrmdvpsjfgklthnyioqe
  65. auxwcbzrmdvpejfgklthnyyofe
  66. auxwchzrmxvpsjfgklthnyioqh
  67. auxwcbzrtdvpsjfgklxhnzioqe
  68. auxwcbyrmdvpsnfgklnhnyioqe
  69. auxwcbzrcdvpsjugklihnyioqe
  70. auxwcbzrddvpsjfgklhhnyiaqe
  71. aumwtbzrmdvpsjfgklthnyitqe
  72. auxucbzrmdvpsjfgklthwfioqe
  73. auxwcbzrmdvpzmfgkllhnyioqe
  74. auxwcbzrmdvpsjhgklthntiome
  75. buxwzbzrmdvpszfgklthnyioqe
  76. ouxwcbzsgdvpsjfgklthnyioqe
  77. auxwcbzrmdvpsjfskltgnyioqz
  78. auxwcbbrmdvpsjftklthnyioqu
  79. quxocbzrmdvpsjfgklthfyioqe
  80. acxwcbzrmdvpsjfgklfhnrioqe
  81. auxwcbzrmdnpsjfrkjthnyioqe
  82. wuxwybzrmdwpsjfgklthnyioqe
  83. auxwgbxrmdvpsjfghlthnyioqe
  84. atxwcbzrmdvnsjfgklthnyjoqe
  85. acxwcbzmmdvpsjfbklthnyioqe
  86. auxhcbzrmdvbsjbgklthnyioqe
  87. auxwlbzrfdvpsjfgxlthnyioqe
  88. auxwmbzrmdfpsjqgklthnyioqe
  89. auxwcbzrmdvpsgfgklahnyigqe
  90. auxwgbzrmdvpsjfgzldhnyioqe
  91. auxwcbzrmdvpydfgklthnyiohe
  92. auxwxbzrmdvpsjfsklchnyioqe
  93. auxqcbzrmdvpsjfgqlthnyiwqe
  94. auxwcozrmdvssbfgklthnyioqe
  95. auxvcczrmdvpsufgklthnyioqe
  96. auxwcbzrudvpsjfgklyhnyioxe
  97. aulwcbzrmdvpsjqgknthnyioqe
  98. auukcbzrmdvpsjfgklthtyioqe
  99. auxwcszimdvpsjfgklthnyigqe
  100. juxwcbzrbdvpsjfgklthnyboqe
  101. auxwcbzrmdvpjofgklthnyioqj
  102. auxwcbzrmdvpsjfgplfhnyione
  103. auxwcbzrmdhpsjfgkltknyeoqe
  104. luxwcqzrmdvpsjfgklthnbioqe
  105. uuxwcbzrmdvpsjfgkithnyiiqe
  106. auxwcbzrmdvpdjfgkrthnyeoqe
  107. auuwcbnrmdvpsjfgklthnjioqe
  108. auxwcnzrmdvpsjvgklthnyooqe
  109. auxwcbzcmdvpsjfcklthnyiose
  110. auxwcbzrldfpsjfgklthjyioqe
  111. auxwcizrmdvpsjfjklthnymoqe
  112. auxwcbtrmdvpsjfgtlphnyioqe
  113. amxwcbzrmdvksjfgklthnyiove
  114. auxwcbzrmdvpszfgkpthnyiuqe
  115. auxwcbzrmdvxdjfgkltqnyioqe
  116. auxwcbzrudvpsjfgklthnymiqe
  117. auxwcbirmdvfsjfgklmhnyioqe
  118. auwwcbzrndvprjfgklthnyioqe
  119. auxwcbormdgpsjfgklbhnyioqe
  120. auxwabzrmdupsjfgklthnyioqt
  121. auxvcbzrmdvpsjfgkltrmyioqe
  122. auxwcbzrmddpsjfsklthnyizqe
  123. auxwcczrmuvpyjfgklthnyioqe
  124. auxwcczrmdvpsnfgkpthnyioqe
  125. auxkcbzrmdvpsjfhklihnyioqe
  126. auxwcbzrmdvpsjfgklthnkijje
  127. auxwcbzcmdvpsjpgkldhnyioqe
  128. auxwcnzrudvpstfgklthnyioqe
  129. xuxwcbzrgdvusjfgklthnyioqe
  130. aaxwcbzrmdvpsjvgklthnyidqe
  131. auxwcbztmdvpsjfgklthnyhqqe
  132. auxwcbzrmfvpsjfgklthnyilfe
  133. auxwcbzrmdvksjfgklthjyioqq
  134. auxwcbzrmdzksjfgktthnyioqe
  135. auxwcbzrmfvpszfgklohnyioqe
  136. auxwckzamdvpsjfgklthnyioqs
  137. auxwcmzrhdvpsjfaklthnyioqe
  138. fuxwcbzrmdapsjfgklrhnyioqe
  139. avxwxbzrmdvpsjfgklthniioqe
  140. auxwubzrmevpsjfgkltpnyioqe
  141. fuxwcbzrgdvpsjfgklhhnyioqe
  142. duxwwbdrmdvpsjfgklthnyioqe
  143. audwcbzrmdvpnjcgklthnyioqe
  144. auxtcbzrmdvpsjmgklthnyyoqe
  145. aucwcbwrmdepsjfgklthnyioqe
  146. auxwcbzrudvpsjfpklthnyiose
  147. auxwcbzridvpsjfsklthxyioqe
  148. auxtcbzrmdvpscfgklyhnyioqe
  149. auxwcbzrmdvppjfgklthnyivee
  150. auxwdbzrmuvpskfgklthnyioqe
  151. auxwubzrmdvosjfgklthnyiope
  152. auxwcbzrmhnpsjfgklthnyimqe
  153. auxwcbzrmdqpwjfgkltpnyioqe
  154. auxwcbormdvpsjljklthnyioqe
  155. auxwcbzrmdjpsjfgkltjpyioqe
  156. auxwcbzrmdvpszfgklthkyizqe
  157. auxwcbzighvpsjfgklthnyioqe
  158. auxwcbzrmdlpsjfgcythnyioqe
  159. auxwcbzumdvpsjflklthnyimqe
  160. pdxwcbzrmdvpsjfgklthnyihqe
  161. auxwcbzrsdvpsjfgklhhvyioqe
  162. auxwcfzamdvpsjfgkmthnyioqe
  163. aexwcdzrmdvpsjogklthnyioqe
  164. auxxcbkrmavpsjfgklthnyioqe
  165. auxwcbzredvssjfgklthryioqe
  166. aupwqbzrmdvpsjfgklthnyioqc
  167. auxwcbzrmdvpkcagklthnyioqe
  168. auxwcbzrmdvwsbfgklthnlioqe
  169. aunwcbzxmdvhsjfgklthnyioqe
  170. auxwcbzrhddpsjfgklthnnioqe
  171. ouxwcbzrmdvtsifgklthnyioqe
  172. auxwcbzrmdqpsjfgklthnyfoqp
  173. auxwrbzrhdvpsjfgolthnyioqe
  174. auxwcbcqmdvpsjugklthnyioqe
  175. auxwcbzrqdvpsjhgklthnjioqe
  176. auxmcbzrmdvpsjfgmlthnyjoqe
  177. auxwcbzrmdvpsjfgzlthnycoqv
  178. auswcbzrmdvpsffgslthnyioqe
  179. auxwcbzrfdvpsjfrmlthnyioqe
  180. auxwcbzrmdvpsjngzlthnxioqe
  181. auxwcbzrmdvpsjfuqlthnyiyqe
  182. auxwzbzrrdvosjfgklthnyioqe
  183. auxwcbzdmdvpsjfikxthnyioqe
  184. guxwcbzrmdvpsjfgmlthnytoqe
  185. auxwcbzrmdvpspfgkytenyioqe
  186. auxvcbzrldvpsjfgklthnyhoqe
  187. auxwcbzrmavpckfgklthnyioqe
  188. autwcbzrmdvpsafgklthnyirqe
  189. auxwcbzrxuvpsjfgklthmyioqe
  190. auxwcbarmdppsjfgklthnywoqe
  191. anxvcbzrmdvpsjfgklthnyijqe
  192. auxwcbwrmdapsjngklthnyioqe
  193. abxwcbzrmdvpsjugkltgnyioqe
  194. auxwcbtrmdvpsjfgkltunyioue
  195. aujwcbzrmovpsjfgklthryioqe
  196. auxwcbzrydvpsjfgklthndikqe
  197. auxwcbzrmdvpsjfgklmrnyioqo
  198. auxwcbzrddvpsjfggithnyioqe
  199. auxwcbzrmdvpfjfaklthlyioqe
  200. fuxtcbzrmdvpsjfgklwhnyioqe
  201. tuxwcbzrjdvpsjfgjlthnyioqe
  202. auxwcbzrmdppsofgklthnyfoqe
  203. auxvclzamdvpsjfgklthnyioqe
  204. auxwcbzrmdvpsjfdklhhnzioqe
  205. auxwcbzrmsvpsvdgklthnyioqe
  206. arxfcbzrmdvpsvfgklthnyioqe
  207. auxzcbzrmdvpsjfgklthnhioqj
  208. auxwcbzrrdvpsjfgpltunyioqe
  209. auxuibzrmdvpwjfgklthnyioqe
  210. auxwcbzrwdqpsjfgklthnyooqe
  211. aujwcbzrmdvpsjvgklthxyioqe
  212. abxwcbzrmfvpsjfgklthnyxoqe
  213. aurwcbzrmdvpshfgklthnyhoqe
  214. auxwcbzjmdvpsjfgknthnycoqe
  215. auxwcbzrmdvpsjfgklmhxwioqe
  216. auxwcbzrmfvpsjfgklthnyiorq
  217. auxwcbormdvpsjfgklwhnlioqe
  218. auxwctzrmdvpsjfgklcknyioqe
  219. awxwcbzrmdvpsjfgvlthnyiome
  220. auxwcbzrmdvpsjfjklthnyixje
  221. auxwcsxrmdvpsjfgkltsnyioqe
  222. auxbmbzrmdvpsjfgklthnyioce
  223. auxwcbzrmdvpsjfukzthnytoqe
  224. aixwcbzrmdvpsjfgllthdyioqe
  225. auxwcbzrmdypsjfgklthnlioqy
  226. auxccbzrmdvpsjfgkltrnnioqe
  227. auxwcznrmdvpsjfgklthnykoqe
  228. auxwmqzrmdvpsjfgilthnyioqe
  229. auxwcbzrmdvpdyfgolthnyioqe
  230. auxwcbzrmdvpsjfgkmohnqioqe
  231. auxwcfzrmzvpsjfoklthnyioqe
  232. auxwjyzrmdvpsjfgulthnyioqe
  233. auxwcgzredvpsjfgkxthnyioqe
  234. wuxwcbtrmdvpsjfgklthnyiofe
  235. auxwcbzrmdopsgfgklthncioqe
  236. auxmcbzjmdvpsjfgklbhnyioqe
  237. auxwlbzrmdvpsjffklthgyioqe
  238. auxwcbzrmrvpsjfgqlthtyioqe
  239. kuxwhbzrmdvpsjfgklthgyioqe
  240. auxwcozrmdgpsjfgklthnydoqe
  241. auxwdbzrmdvpdjfgklthgyioqe
  242. auxwqbzrmdapsvfgklthnyioqe
  243. auqwcbzridvjsjfgklthnyioqe
  244. auxwckzrmdvpsjfoklthnyuoqe
  245. auxwcbzvmdvpsjfgklghnyiome
  246. auxtcbzrmdvpsjqgktthnyioqe
  247. auxwcbzrmdvesjfgkljhnnioqe
  248. auxwcbzrmpvpsqfgklthnqioqe
  249. auxwcbzrmdcpsqfgklthnzioqe
  250. yuxwcbzrmdvpsjggklthnlioqe
  251. auxwcbzradvpsjftklthoyioqe
  252. auxwcbzrmdvjujfgklmhnyioqe
  253. auxwcbzrmdvpsrfgklpinyioqe
  254. auxwobzrvqvpsjfgklthnyioqe";
  255.  
  256. let s: Vec<String> = input.split_whitespace().map(String::from).collect();
  257. let count_occurrences = |s: String, i: i32| {
  258. s.chars()
  259. .fold(HashMap::new(), |mut m, x| {
  260. m.entry(x).and_modify(|v| *v += 1).or_insert(1);
  261. m
  262. })
  263. .iter()
  264. .any(|(_, b)| b == &i)
  265. };
  266.  
  267. println!(
  268. "Part1: {}",
  269. s.iter()
  270. .filter(|x| count_occurrences(x.to_string(), 2))
  271. .count()
  272. * s.iter()
  273. .filter(|x| count_occurrences(x.to_string(), 3))
  274. .count()
  275. );
  276.  
  277. let diff = |a: String, b: String| a.chars().zip(b.chars()).filter(|&(a, b)| a != b).count();
  278. let common = |(a, b): (String, String)| -> String {
  279. a.chars()
  280. .zip(b.chars())
  281. .filter(|&(a, b)| a == b)
  282. .fold(String::new(), |mut acc, b| { acc.push(b.0); acc})
  283. };
  284.  
  285. let mut b = iproduct!(&s, &s);
  286. println!(
  287. "{:?}",
  288. common(b.find(|(i, j)| diff(i.to_string(), j.to_string()) == 1)
  289. .unwrap())
  290. );
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement