My omnium-gatherom of scripts and source code.
1{
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 30,
6 "id": "9dd3736a-5d60-44c5-a93d-2c95bc54fb3c",
7 "metadata": {},
8 "outputs": [],
9 "source": [
10 "def ITER_ODD(A: list[int]) -> int:\n",
11 " counter = 0\n",
12 " for x in A:\n",
13 " if x % 2 == 1 and x > 0:\n",
14 " counter += 1\n",
15 " return counter\n",
16 "\n",
17 "def DC_ODD(A: list[int], i = 0, f = None) -> int:\n",
18 " if f is None:\n",
19 " f = len(A)\n",
20 " if f - i == 1:\n",
21 " return A[i] % 2 and A[i] > 0\n",
22 " midp = (f - i) // 2 + i\n",
23 " return DC_ODD(A, i, midp) + DC_ODD(A, midp, f)"
24 ]
25 },
26 {
27 "cell_type": "code",
28 "execution_count": 31,
29 "id": "a4932c94-7747-4084-875c-7894d924196a",
30 "metadata": {},
31 "outputs": [
32 {
33 "data": {
34 "text/plain": [
35 "2"
36 ]
37 },
38 "execution_count": 31,
39 "metadata": {},
40 "output_type": "execute_result"
41 }
42 ],
43 "source": [
44 "ITER_ODD([2, -7, 3, 0, 13, -1, 4, 0])"
45 ]
46 },
47 {
48 "cell_type": "code",
49 "execution_count": 32,
50 "id": "c3a1fdd3-833b-42f5-9269-88f0afe9e9c4",
51 "metadata": {},
52 "outputs": [
53 {
54 "data": {
55 "text/plain": [
56 "2"
57 ]
58 },
59 "execution_count": 32,
60 "metadata": {},
61 "output_type": "execute_result"
62 }
63 ],
64 "source": [
65 "DC_ODD([2, -7, 3, 0, 13, -1, 4, 0])"
66 ]
67 },
68 {
69 "cell_type": "code",
70 "execution_count": 33,
71 "id": "106d480b-12e0-40c4-98ec-eb6fb2e7ed6c",
72 "metadata": {},
73 "outputs": [
74 {
75 "data": {
76 "text/plain": [
77 "2"
78 ]
79 },
80 "execution_count": 33,
81 "metadata": {},
82 "output_type": "execute_result"
83 }
84 ],
85 "source": [
86 "DC_ODD([1,2,3,4])"
87 ]
88 },
89 {
90 "cell_type": "code",
91 "execution_count": null,
92 "id": "9deff933-969f-4428-9b01-46114b728d64",
93 "metadata": {},
94 "outputs": [],
95 "source": []
96 }
97 ],
98 "metadata": {
99 "kernelspec": {
100 "display_name": "Python 3 (ipykernel)",
101 "language": "python",
102 "name": "python3"
103 },
104 "language_info": {
105 "codemirror_mode": {
106 "name": "ipython",
107 "version": 3
108 },
109 "file_extension": ".py",
110 "mimetype": "text/x-python",
111 "name": "python",
112 "nbconvert_exporter": "python",
113 "pygments_lexer": "ipython3",
114 "version": "3.12.3"
115 }
116 },
117 "nbformat": 4,
118 "nbformat_minor": 5
119}