{ "cells": [ { "cell_type": "code", "execution_count": 30, "id": "9dd3736a-5d60-44c5-a93d-2c95bc54fb3c", "metadata": {}, "outputs": [], "source": [ "def ITER_ODD(A: list[int]) -> int:\n", " counter = 0\n", " for x in A:\n", " if x % 2 == 1 and x > 0:\n", " counter += 1\n", " return counter\n", "\n", "def DC_ODD(A: list[int], i = 0, f = None) -> int:\n", " if f is None:\n", " f = len(A)\n", " if f - i == 1:\n", " return A[i] % 2 and A[i] > 0\n", " midp = (f - i) // 2 + i\n", " return DC_ODD(A, i, midp) + DC_ODD(A, midp, f)" ] }, { "cell_type": "code", "execution_count": 31, "id": "a4932c94-7747-4084-875c-7894d924196a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ITER_ODD([2, -7, 3, 0, 13, -1, 4, 0])" ] }, { "cell_type": "code", "execution_count": 32, "id": "c3a1fdd3-833b-42f5-9269-88f0afe9e9c4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DC_ODD([2, -7, 3, 0, 13, -1, 4, 0])" ] }, { "cell_type": "code", "execution_count": 33, "id": "106d480b-12e0-40c4-98ec-eb6fb2e7ed6c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DC_ODD([1,2,3,4])" ] }, { "cell_type": "code", "execution_count": null, "id": "9deff933-969f-4428-9b01-46114b728d64", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }