Skip to content

Commit 08882f3

Browse files
authored
Second attempt in comparing Mojo and Python
1 parent 4f8ee06 commit 08882f3

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

problem-2/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Problem 2
2+
3+
Link: https://leetcode.com/problems/student-attendance-record-i/description/
4+
5+
## Benchmarks
6+
7+
| CPU | Time | Mem |
8+
|-------|-------|------|
9+
10+
Which performed better?

problem-2/problem-2.mojo

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from python import Python
2+
3+
def checkRecord():
4+
py = Python.import_module("builtins")
5+
attendance_record = py.input("Enter the attendance record: ")
6+
attendance_record_str = str(attendance_record)
7+
8+
absent_count = 0
9+
late_count = 0
10+
11+
for i in range(len(attendance_record_str)):
12+
13+
if attendance_record_str[i] == 'A':
14+
absent_count += 1
15+
late_count = 0
16+
elif attendance_record_str[i] == 'L':
17+
late_count += 1
18+
else:
19+
late_count = 0
20+
21+
if late_count >=3 or absent_count >= 2:
22+
py.print("The attendance record is not acceptable.")
23+
return False
24+
25+
py.print("The attendance record is acceptable.")
26+
return True
27+
28+
# Main function
29+
def main():
30+
checkRecord()

problem-2/problem-2.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def isPalindrome(x):
2+
enternumber = x
3+
4+
enternumber_str = str(enternumber)
5+
if not enternumber_str.isdigit():
6+
print("Invalid input. Please enter a valid integer.")
7+
return
8+
9+
store1 = [0] * len(enternumber_str)
10+
store2 = [0] * len(enternumber_str)
11+
12+
for i in range(len(enternumber_str)):
13+
store1[i] = int(enternumber_str[i])
14+
print(store1[i])
15+
16+
for j in range(len(enternumber_str)-1, -1, -1):
17+
store2[len(enternumber_str)-1-j] = int(enternumber_str[j])
18+
19+
for i in range(len(enternumber_str)):
20+
print(store2[i])
21+
if store1[i] != store2[i]:
22+
return False
23+
return True
24+
25+
def main():
26+
input_number = int(input("Enter an integer: "))
27+
result = isPalindrome(input_number)
28+
print("Is Palindrome:", result)

0 commit comments

Comments
 (0)