This commit is contained in:
2022-12-01 14:49:18 -05:00
parent 16c04c4da1
commit 478cb41309
2 changed files with 92 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"def recsum(n):\n",
" if n:\n",
" n+=n\n",
" recsum(n-1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"recsum(10)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.5 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "369f2c481f4da34e4445cda3fffd2e751bd1c4d706f27375911949ba6bb62e1c"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
+40
View File
@@ -0,0 +1,40 @@
def recsum(n):
if not n:
return 0
else:
return recsum(n-1)+n
print(recsum(10))
def boardlength(n):
if n<=3:
return 0
else:
return boardlength(n-4)+1
print(boardlength(16))
def reversing(list_n):
if len(list_n) == 1:
return list_n
else:
first_half = list_n[:len(list_n)//2]
second_half = list_n[len(list_n)//2:]
return reversing(second_half) + reversing(first_half)
print(reversing([1,2,3,4]))
def binarySearch(list1,element):
print(list1,element,len(list1))
if list1[len(list1)//2]==element:
return len(list1)//2
elif list1[len(list1)//2] < element:
return binarySearch(list1[len(list1)//2:],element)
elif list1[len(list1)//2] > element:
return binarySearch(list1[:len(list1)//2],element)
elif len(list1) == 1 and list1[len(list1)//2] != element:
return None
print(binarySearch([1,2,3,4,5],5))