Skip to content

Commit b651da5

Browse files
committed
Workshop Config
1 parent ada7b6a commit b651da5

File tree

2 files changed

+251
-0
lines changed

2 files changed

+251
-0
lines changed

CPWorkshop.ipynb

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 16,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdin",
10+
"output_type": "stream",
11+
"text": [
12+
" 1 6 4 11 1 13 21 3 7 11 3 7 1\n"
13+
]
14+
},
15+
{
16+
"ename": "ValueError",
17+
"evalue": "invalid literal for int() with base 10: '1 6 4 11 1 13 21 3 7 11 3 7 1'",
18+
"output_type": "error",
19+
"traceback": [
20+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
21+
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
22+
"\u001b[1;32m<ipython-input-16-df47fdcad453>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfor\u001b[0m \u001b[0m_\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mn\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m;\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mar1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mset\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mar2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mset\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mar3\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mar1\u001b[0m \u001b[1;33m&\u001b[0m \u001b[0mar2\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
23+
"\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: '1 6 4 11 1 13 21 3 7 11 3 7 1'"
24+
]
25+
}
26+
],
27+
"source": [
28+
"#https://practice.geeksforgeeks.org/problems/array-subset-of-another-array/0\n",
29+
"\n",
30+
"for _ in range(int(input())):\n",
31+
" n,m=map(int,input().split());\n",
32+
"ar1 = set(map(int,input().split()))\n",
33+
"ar2 = set(map(int,input().split()))\n",
34+
"ar3 = ar1 & ar2\n",
35+
"ar4 = ar2-ar3\n",
36+
"print(\"Yes\" if len(ar4)==0 else \"No\")"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 18,
42+
"metadata": {},
43+
"outputs": [
44+
{
45+
"ename": "NameError",
46+
"evalue": "name '_name_' is not defined",
47+
"output_type": "error",
48+
"traceback": [
49+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
50+
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
51+
"\u001b[1;32m<ipython-input-18-873830cb1a9e>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Yes\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 21\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0m_name_\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'_main_'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 22\u001b[0m \u001b[0mmn\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 23\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
52+
"\u001b[1;31mNameError\u001b[0m: name '_name_' is not defined"
53+
]
54+
}
55+
],
56+
"source": [
57+
"# https://www.hackerrank.com/challenges/ctci-ransom-note/problem\n",
58+
"\n",
59+
"import math\n",
60+
"import os\n",
61+
"import random\n",
62+
"import re\n",
63+
"import sys\n",
64+
"from collections import defaultdict\n",
65+
"\n",
66+
"def checkMagazine(magazine, note):\n",
67+
" mag = defaultdict(int)\n",
68+
" _note = defaultdict(int)\n",
69+
" for i in magazine:\n",
70+
" mag[i]+=1\n",
71+
" for i in note:\n",
72+
" _note[i]+=1\n",
73+
" for i in _note:\n",
74+
" if _note[i]>mag[i]:\n",
75+
" print(\"No\")\n",
76+
" return\n",
77+
" print(\"Yes\")\n",
78+
"\n",
79+
"if _name_ == '_main_':\n",
80+
" mn = input().split()\n",
81+
"\n",
82+
" m = int(mn[0])\n",
83+
"\n",
84+
" n = int(mn[1])\n",
85+
"\n",
86+
" magazine = input().rstrip().split()\n",
87+
"\n",
88+
" note = input().rstrip().split()\n",
89+
"\n",
90+
" checkMagazine(magazine, note)"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": 20,
96+
"metadata": {},
97+
"outputs": [
98+
{
99+
"name": "stdin",
100+
"output_type": "stream",
101+
"text": [
102+
" 2 5 5 9 1 2 4 5 7 5 6 3 4 8 2 2 3 0 2 1 3\n"
103+
]
104+
},
105+
{
106+
"ename": "ValueError",
107+
"evalue": "invalid literal for int() with base 10: '2 5 5 9 1 2 4 5 7 5 6 3 4 8 2 2 3 0 2 1 3'",
108+
"output_type": "error",
109+
"traceback": [
110+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
111+
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
112+
"\u001b[1;32m<ipython-input-20-e5fbcdc54429>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m#https://practice.geeksforgeeks.org/problems/find-all-pairs-whose-sum-is-x/0/\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;32mfor\u001b[0m \u001b[0m_\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[0mn\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mdic1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m1\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mmap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mint\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
113+
"\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: '2 5 5 9 1 2 4 5 7 5 6 3 4 8 2 2 3 0 2 1 3'"
114+
]
115+
}
116+
],
117+
"source": [
118+
"#https://practice.geeksforgeeks.org/problems/find-all-pairs-whose-sum-is-x/0/\n",
119+
"\n",
120+
"for _ in range(int(input())):\n",
121+
" n,m,x = map(int,input().split())\n",
122+
" dic1 = {k:1 for k in map(int,input().split())}\n",
123+
" dic2 = {k:1 for k in map(int,input().split())}\n",
124+
" cnt=0\n",
125+
" ar=[]\n",
126+
" for i in dic1.keys():\n",
127+
" if (x-i) in dic2:\n",
128+
" cnt+=1\n",
129+
" ar.append((i,x-i))\n",
130+
" ar.sort()\n",
131+
" if cnt==0: print(-1)\n",
132+
" else:\n",
133+
" for i in ar[:-1]:\n",
134+
" print(i[0],i[1],end=\", \")\n",
135+
" print(ar[-1][0],ar[-1][1])"
136+
]
137+
}
138+
],
139+
"metadata": {
140+
"kernelspec": {
141+
"display_name": "Python 3",
142+
"language": "python",
143+
"name": "python3"
144+
},
145+
"language_info": {
146+
"codemirror_mode": {
147+
"name": "ipython",
148+
"version": 3
149+
},
150+
"file_extension": ".py",
151+
"mimetype": "text/x-python",
152+
"name": "python",
153+
"nbconvert_exporter": "python",
154+
"pygments_lexer": "ipython3",
155+
"version": "3.7.4"
156+
}
157+
},
158+
"nbformat": 4,
159+
"nbformat_minor": 4
160+
}

Pract.ipynb

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdin",
10+
"output_type": "stream",
11+
"text": [
12+
" Hello\n"
13+
]
14+
},
15+
{
16+
"name": "stdout",
17+
"output_type": "stream",
18+
"text": [
19+
"Hello\n"
20+
]
21+
}
22+
],
23+
"source": [
24+
"my_string=input()\n",
25+
"print(my_string)"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 9,
31+
"metadata": {},
32+
"outputs": [
33+
{
34+
"name": "stdin",
35+
"output_type": "stream",
36+
"text": [
37+
"Enter ip HH\n"
38+
]
39+
},
40+
{
41+
"name": "stdout",
42+
"output_type": "stream",
43+
"text": [
44+
"{'H': 2}\n"
45+
]
46+
}
47+
],
48+
"source": [
49+
"strl=input(\"Enter ip\")\n",
50+
"\n",
51+
"dictX = {} \n",
52+
"\n",
53+
"for i in strl: \n",
54+
" if i not in dictX.keys(): \n",
55+
" dictX[i] = 1\n",
56+
" else: \n",
57+
" dictX[i] += 1\n",
58+
" \n",
59+
"print (dictX)"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": null,
65+
"metadata": {},
66+
"outputs": [],
67+
"source": []
68+
}
69+
],
70+
"metadata": {
71+
"kernelspec": {
72+
"display_name": "Python 3",
73+
"language": "python",
74+
"name": "python3"
75+
},
76+
"language_info": {
77+
"codemirror_mode": {
78+
"name": "ipython",
79+
"version": 3
80+
},
81+
"file_extension": ".py",
82+
"mimetype": "text/x-python",
83+
"name": "python",
84+
"nbconvert_exporter": "python",
85+
"pygments_lexer": "ipython3",
86+
"version": "3.7.4"
87+
}
88+
},
89+
"nbformat": 4,
90+
"nbformat_minor": 4
91+
}

0 commit comments

Comments
 (0)