From b50c7e99603e9f85d82d700d62c16c4fcef88715 Mon Sep 17 00:00:00 2001 From: Geno <48206120+gabrielegenovese@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:57:56 +0200 Subject: Code generation (#20) Co-authored-by: geno Co-authored-by: Santo Cariotti --- test/3-1.py | 14 ++++++++++++++ test/3-2.py | 16 ++++++++++++++++ test/3-3.py | 8 ++++++++ test/3-4.py | 8 ++++++++ 4 files changed, 46 insertions(+) create mode 100644 test/3-1.py create mode 100644 test/3-2.py create mode 100644 test/3-3.py create mode 100644 test/3-4.py (limited to 'test') diff --git a/test/3-1.py b/test/3-1.py new file mode 100644 index 0000000..95d2fbe --- /dev/null +++ b/test/3-1.py @@ -0,0 +1,14 @@ + +def prime_num(num, div): + if (num >=1): + if (div*div <= num/2): + if (num % div) == 0: + return False + else: + return prime_num(num,div+1) + else: + return True + else: + return False + +print(prime_num(29,2)) diff --git a/test/3-2.py b/test/3-2.py new file mode 100644 index 0000000..417fbde --- /dev/null +++ b/test/3-2.py @@ -0,0 +1,16 @@ + +num = 29 + +def prime_numBIS(div): + if (num >=1): + if (div*div <= num/2): + if (num % div) == 0: + return False + else: + return prime_numBIS(div+1) + else: + return True + else: + return False + +print(prime_numBIS(2)) diff --git a/test/3-3.py b/test/3-3.py new file mode 100644 index 0000000..af57e46 --- /dev/null +++ b/test/3-3.py @@ -0,0 +1,8 @@ + +def fibonacci(n): + if ((n == 0) or (n == 1)): + return 1 + else: + return (fibonacci(n-1) + fibonacci(n-2)) + +print(fibonacci(6)) diff --git a/test/3-4.py b/test/3-4.py new file mode 100644 index 0000000..79bf77a --- /dev/null +++ b/test/3-4.py @@ -0,0 +1,8 @@ + +def fibonacciIT(n,a,b): + if ((n == 0) or (n == 1)): + return a + else: + return (fibonacciIT(n-1, a+b, a)) + +print(fibonacciIT(6,1,1)) -- cgit v1.2.3-18-g5258