Skip to content

Commit

Permalink
Add Solution for Problem 03 of the Assignment 05
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahrjose committed Aug 21, 2022
1 parent 0617d2a commit a875b0f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Assignment 05/Problem -03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Problem -03


def readLines(file_path: str) -> list:

with open(file_path, "r") as file:
lines: list = file.readlines()
return lines


def writeLines(file_path: str, lines: list) -> None:

with open(file_path, "w") as file:
file.writelines("\n".join(lines))


def main():

from collections import deque

inPath = ["task3_input1.txt", "task3_input2.txt"]
outPath = ["task3_output1.txt", "task3_output2.txt"]

for name in range(0, 2):

stack = deque()
fileInput = [line.replace("\n", "") for line in readLines(inPath[name])]

# total_tasks = fileInput[0]
task_list = list(map(int, fileInput[1].split(" ")))
string = fileInput[2]

task_list.sort()

seq = ""
jack = 0
jill = 0
index = 0
for char in string:
if char == "J":
stack.append(task_list[index])
seq += str(task_list[index])
jack += task_list[index]
index += 1

elif char == "j":
var = stack.pop()
seq += str(var)
jill += var

fileOutput = []
fileOutput.append(seq)
fileOutput.append(f"Jack will work for {jack} hours")
fileOutput.append(f"Jill will work for {jill} hours")

writeLines(outPath[name], fileOutput)


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions Assignment 05/task3_input1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
4
1 4 2 3
JJjJjjJ
3 changes: 3 additions & 0 deletions Assignment 05/task3_input2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
3
2 5 3
JjJJjj
3 changes: 3 additions & 0 deletions Assignment 05/task3_output1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1223314
Jack will work for 10 hours
Jill will work for 6 hours
3 changes: 3 additions & 0 deletions Assignment 05/task3_output2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
223553
Jack will work for 10 hours
Jill will work for 10 hours

0 comments on commit a875b0f

Please sign in to comment.