Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0a742b0

Browse files
Add files via upload
1 parent 1d4ce8b commit 0a742b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5385
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"def fact(n):\n",
10+
" return n*fact(n-1)"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 2,
16+
"metadata": {},
17+
"outputs": [
18+
{
19+
"name": "stdout",
20+
"output_type": "stream",
21+
"text": [
22+
"2\n"
23+
]
24+
},
25+
{
26+
"ename": "RecursionError",
27+
"evalue": "maximum recursion depth exceeded",
28+
"output_type": "error",
29+
"traceback": [
30+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
31+
"\u001b[1;31mRecursionError\u001b[0m Traceback (most recent call last)",
32+
"\u001b[1;32m<ipython-input-2-feb88f6cc06b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mn\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[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mfact\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
33+
"\u001b[1;32m<ipython-input-1-cd32c1657d49>\u001b[0m in \u001b[0;36mfact\u001b[1;34m(n)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mfact\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mn\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[1;32m----> 2\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mn\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mfact\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
34+
"... last 1 frames repeated, from the frame below ...\n",
35+
"\u001b[1;32m<ipython-input-1-cd32c1657d49>\u001b[0m in \u001b[0;36mfact\u001b[1;34m(n)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mfact\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mn\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[1;32m----> 2\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mn\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mfact\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
36+
"\u001b[1;31mRecursionError\u001b[0m: maximum recursion depth exceeded"
37+
]
38+
}
39+
],
40+
"source": [
41+
"n = int(input())\n",
42+
"fact(n)"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": 2,
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"def fact(n):\n",
52+
" if n == 0:\n",
53+
" return 1\n",
54+
" return n*fact(n-1)"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": 9,
60+
"metadata": {
61+
"scrolled": true
62+
},
63+
"outputs": [
64+
{
65+
"name": "stdout",
66+
"output_type": "stream",
67+
"text": [
68+
"3\n"
69+
]
70+
},
71+
{
72+
"data": {
73+
"text/plain": [
74+
"6"
75+
]
76+
},
77+
"execution_count": 9,
78+
"metadata": {},
79+
"output_type": "execute_result"
80+
}
81+
],
82+
"source": [
83+
"n = int(input())\n",
84+
"fact(n)"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": 8,
90+
"metadata": {},
91+
"outputs": [],
92+
"source": [
93+
"def Sum_n(n):\n",
94+
" if n ==0:\n",
95+
" return 0\n",
96+
" smalloutput = Sum_n(n-1)\n",
97+
" output = smalloutput + n\n",
98+
" return output "
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": 11,
104+
"metadata": {
105+
"scrolled": true
106+
},
107+
"outputs": [
108+
{
109+
"name": "stdout",
110+
"output_type": "stream",
111+
"text": [
112+
"5\n"
113+
]
114+
},
115+
{
116+
"data": {
117+
"text/plain": [
118+
"15"
119+
]
120+
},
121+
"execution_count": 11,
122+
"metadata": {},
123+
"output_type": "execute_result"
124+
}
125+
],
126+
"source": [
127+
"n = int(input())\n",
128+
"Sum_n(n)"
129+
]
130+
}
131+
],
132+
"metadata": {
133+
"kernelspec": {
134+
"display_name": "Python 3",
135+
"language": "python",
136+
"name": "python3"
137+
},
138+
"language_info": {
139+
"codemirror_mode": {
140+
"name": "ipython",
141+
"version": 3
142+
},
143+
"file_extension": ".py",
144+
"mimetype": "text/x-python",
145+
"name": "python",
146+
"nbconvert_exporter": "python",
147+
"pygments_lexer": "ipython3",
148+
"version": "3.8.5"
149+
}
150+
},
151+
"nbformat": 4,
152+
"nbformat_minor": 4
153+
}

‎01. Recursion - 1/2. Print first N natural numbers & Fibonacci $ DEPTH OF RECURSION.ipynb

Lines changed: 249 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 3,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"def isSorted(a):\n",
10+
" l = len(a)\n",
11+
" if l == 0 or l == 1:\n",
12+
" return True\n",
13+
" if a[0]>a[1]:\n",
14+
" return False\n",
15+
" smallerlist = a[1:]\n",
16+
" SmallerlistSorted = isSorted(smallerlist) \n",
17+
" if SmallerlistSorted:\n",
18+
" return True\n",
19+
" else:\n",
20+
" return False"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 4,
26+
"metadata": {
27+
"scrolled": true
28+
},
29+
"outputs": [
30+
{
31+
"data": {
32+
"text/plain": [
33+
"False"
34+
]
35+
},
36+
"execution_count": 4,
37+
"metadata": {},
38+
"output_type": "execute_result"
39+
}
40+
],
41+
"source": [
42+
"a = [1,2,3,4,5,6,7,8,9,1]\n",
43+
"isSorted(a)"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": 12,
49+
"metadata": {},
50+
"outputs": [],
51+
"source": [
52+
"def isSortedBetter(a,si):\n",
53+
" l = len(a)\n",
54+
" if si == l-1 or si == l:\n",
55+
" return True\n",
56+
" if a[si]>a[si+1]:\n",
57+
" return False\n",
58+
" isSmallerpartsorted = isSortedBetter(a,si+1)\n",
59+
" return isSmallerpartsorted"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": 14,
65+
"metadata": {
66+
"scrolled": true
67+
},
68+
"outputs": [
69+
{
70+
"data": {
71+
"text/plain": [
72+
"False"
73+
]
74+
},
75+
"execution_count": 14,
76+
"metadata": {},
77+
"output_type": "execute_result"
78+
}
79+
],
80+
"source": [
81+
"a = [1,2,3,4,5,6,70,8,9]\n",
82+
"isSortedBetter(a,0)"
83+
]
84+
},
85+
{
86+
"cell_type": "code",
87+
"execution_count": 15,
88+
"metadata": {},
89+
"outputs": [
90+
{
91+
"data": {
92+
"text/plain": [
93+
"True"
94+
]
95+
},
96+
"execution_count": 15,
97+
"metadata": {},
98+
"output_type": "execute_result"
99+
}
100+
],
101+
"source": [
102+
"a = [1,2,3,4,5,6,7,8,9]\n",
103+
"isSortedBetter(a,0)"
104+
]
105+
}
106+
],
107+
"metadata": {
108+
"kernelspec": {
109+
"display_name": "Python 3",
110+
"language": "python",
111+
"name": "python3"
112+
},
113+
"language_info": {
114+
"codemirror_mode": {
115+
"name": "ipython",
116+
"version": 3
117+
},
118+
"file_extension": ".py",
119+
"mimetype": "text/x-python",
120+
"name": "python",
121+
"nbconvert_exporter": "python",
122+
"pygments_lexer": "ipython3",
123+
"version": "3.8.5"
124+
}
125+
},
126+
"nbformat": 4,
127+
"nbformat_minor": 4
128+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /