Task 0 in Python
[summerofcode2018soln.git] / src / task0 / task0.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 3,
6 "metadata": {},
7 "outputs": [],
8 "source": [
9 "import collections"
10 ]
11 },
12 {
13 "cell_type": "markdown",
14 "metadata": {},
15 "source": [
16 "Import the names, splitting the lines into individual names."
17 ]
18 },
19 {
20 "cell_type": "code",
21 "execution_count": 1,
22 "metadata": {},
23 "outputs": [
24 {
25 "data": {
26 "text/plain": [
27 "200"
28 ]
29 },
30 "execution_count": 1,
31 "metadata": {},
32 "output_type": "execute_result"
33 }
34 ],
35 "source": [
36 "invites = [line.strip().split(', ') for line in open('../../data/00-invites.txt')]\n",
37 "len(invites)"
38 ]
39 },
40 {
41 "cell_type": "markdown",
42 "metadata": {},
43 "source": [
44 "Find the line with most names"
45 ]
46 },
47 {
48 "cell_type": "code",
49 "execution_count": 2,
50 "metadata": {},
51 "outputs": [
52 {
53 "data": {
54 "text/plain": [
55 "33"
56 ]
57 },
58 "execution_count": 2,
59 "metadata": {},
60 "output_type": "execute_result"
61 }
62 ],
63 "source": [
64 "max(len(invite) for invite in invites)"
65 ]
66 },
67 {
68 "cell_type": "markdown",
69 "metadata": {},
70 "source": [
71 "Create a `Counter` from the flattended list of list of names. Then count how many items are in the `Counter` with a count of more than 1."
72 ]
73 },
74 {
75 "cell_type": "code",
76 "execution_count": 4,
77 "metadata": {},
78 "outputs": [
79 {
80 "data": {
81 "text/plain": [
82 "457"
83 ]
84 },
85 "execution_count": 4,
86 "metadata": {},
87 "output_type": "execute_result"
88 }
89 ],
90 "source": [
91 "invite_counts = collections.Counter(name for invite in invites for name in invite)\n",
92 "sum(1 for name in invite_counts if invite_counts[name] > 1)"
93 ]
94 },
95 {
96 "cell_type": "code",
97 "execution_count": null,
98 "metadata": {},
99 "outputs": [],
100 "source": []
101 }
102 ],
103 "metadata": {
104 "kernelspec": {
105 "display_name": "Python 3",
106 "language": "python",
107 "name": "python3"
108 },
109 "language_info": {
110 "codemirror_mode": {
111 "name": "ipython",
112 "version": 3
113 },
114 "file_extension": ".py",
115 "mimetype": "text/x-python",
116 "name": "python",
117 "nbconvert_exporter": "python",
118 "pygments_lexer": "ipython3",
119 "version": "3.6.5"
120 }
121 },
122 "nbformat": 4,
123 "nbformat_minor": 2
124 }