From 8aff6e794be9bbebb08f8f17ccbdc39193b7261d Mon Sep 17 00:00:00 2001 From: s473573 Date: Mon, 25 Nov 2024 16:01:16 +0100 Subject: [PATCH] Complete task 1 --- TaskB01/shakespeare.out | 106 ++++++++++++++++++++++++++++++++++++++++ TaskB01/solution.py | 18 +++++++ 2 files changed, 124 insertions(+) create mode 100644 TaskB01/shakespeare.out create mode 100644 TaskB01/solution.py diff --git a/TaskB01/shakespeare.out b/TaskB01/shakespeare.out new file mode 100644 index 0000000..69f6f7d --- /dev/null +++ b/TaskB01/shakespeare.out @@ -0,0 +1,106 @@ +CLAUDIUS, King of Denmark, Hamlet’s uncle. +The GHOST of the late king, Hamlet’s father. +GERTRUDE, the Queen, Hamlet’s mother, now wife of Claudius. +HORATIO, Friend to Hamlet. +Dar’d to the combat; in which our valiant Hamlet, +His fell to Hamlet. Now, sir, young Fortinbras, +Unto young Hamlet; for upon my life, + Enter Claudius King of Denmark, Gertrude the Queen, Hamlet, Polonius, +Though yet of Hamlet our dear brother’s death +But now, my cousin Hamlet, and my son— +Good Hamlet, cast thy nighted colour off, +’Tis sweet and commendable in your nature, Hamlet, +Let not thy mother lose her prayers, Hamlet. +This gentle and unforc’d accord of Hamlet + [_Exeunt all but Hamlet._] +For Hamlet, and the trifling of his favour, +So please you, something touching the Lord Hamlet. +Than a command to parley. For Lord Hamlet, +As to give words or talk with the Lord Hamlet. + Enter Hamlet, Horatio and Marcellus. +That I will speak to thee. I’ll call thee Hamlet, + [_Ghost beckons Hamlet._] + [_Exeunt Ghost and Hamlet._] + Enter Ghost and Hamlet. +Wouldst thou not stir in this. Now, Hamlet, hear. +O Hamlet, what a falling off was there, +Adieu, adieu, adieu. Hamlet, remember me. +[_Within._] Lord Hamlet. +And what so poor a man as Hamlet is +Lord Hamlet, with his doublet all unbrac’d, +Of Hamlet’s transformation; so I call it, +And bring these gentlemen where Hamlet is. +The very cause of Hamlet’s lunacy. +Came this from Hamlet to her? +‘Lord Hamlet is a prince, out of thy star. + Enter Hamlet, reading. +How does my good Lord Hamlet? +You go to seek the Lord Hamlet; there he is. +For we have closely sent for Hamlet hither, +Of Hamlet’s wildness: so shall I hope your virtues + Enter Hamlet. +You need not tell us what Lord Hamlet said, + Enter Hamlet and certain Players. +How fares our cousin Hamlet? +I have nothing with this answer, Hamlet; these words are not mine. +Come hither, my dear Hamlet, sit by me. + [_Exeunt all but Hamlet and Horatio._] + [_Exeunt all but Hamlet._] + Enter Hamlet. + Enter Hamlet. +Hamlet, thou hast thy father much offended. +Why, how now, Hamlet? +O Hamlet, speak no more. +No more, sweet Hamlet. +Speak to her, Hamlet. +O Hamlet, thou hast cleft my heart in twain. + [_Exit Hamlet dragging out Polonius._] +What, Gertrude? How does Hamlet? +Hamlet in madness hath Polonius slain, + Enter Hamlet. +[_Within._] Hamlet! Lord Hamlet! +What noise? Who calls on Hamlet? O, here they come. + Enter Hamlet and Guildenstern. +Now, Hamlet, where’s Polonius? +Hamlet, this deed, for thine especial safety,— +Ay, Hamlet. +Thy loving father, Hamlet. +The present death of Hamlet. Do it, England; + Enter Hamlet, Rosencrantz, Guildenstern &c. + [_Exeunt all but Hamlet._] +I should be greeted, if not from Lord Hamlet. +Letters, my lord, from Hamlet. +From Hamlet! Who brought them? +’Tis Hamlet’s character. ’Naked!’ +And that in Hamlet’s hearing, for a quality +Did Hamlet so envenom with his envy +Hamlet comes back: what would you undertake +Hamlet return’d shall know you are come home: + Enter Hamlet and Horatio, at a distance. +Hamlet o’ercame Fortinbras. +that young Hamlet was born,—he that is mad, and sent into England. +I hop’d thou shouldst have been my Hamlet’s wife; +Hamlet the Dane. +Hamlet! Hamlet! + Enter Hamlet and Horatio. + [_Hamlet moves him to put on his hat._] +Come, Hamlet, come, and take this hand from me. + [_The King puts Laertes’s hand into Hamlet’s._] +Was’t Hamlet wrong’d Laertes? Never Hamlet. +If Hamlet from himself be ta’en away, +Then Hamlet does it not, Hamlet denies it. +Hamlet is of the faction that is wrong’d; +His madness is poor Hamlet’s enemy. +Give them the foils, young Osric. Cousin Hamlet, +If Hamlet give the first or second hit, +The King shall drink to Hamlet’s better breath, +‘Now the King drinks to Hamlet.’ Come, begin. +Stay, give me drink. Hamlet, this pearl is thine; +Here, Hamlet, take my napkin, rub thy brows. +The Queen carouses to thy fortune, Hamlet. + [_Laertes wounds Hamlet; then, in scuffling, they change rapiers, and + Hamlet wounds Laertes._] +No, no, the drink, the drink! O my dear Hamlet! +It is here, Hamlet. Hamlet, thou art slain. +Exchange forgiveness with me, noble Hamlet. +Bear Hamlet like a soldier to the stage, diff --git a/TaskB01/solution.py b/TaskB01/solution.py new file mode 100644 index 0000000..f150cce --- /dev/null +++ b/TaskB01/solution.py @@ -0,0 +1,18 @@ +import sys +import re + +def solve(lines): + return [l for l in lines if re.search("Hamlet", l)] + +if __name__ == "__main__": + lines = [] + + fp = sys.argv[1] + assert(fp == "shakespeare.in") # just a sanity check + + print(fp) + with open(fp, encoding="utf-8") as f: + lines = f.readlines() + sol = solve(lines) + with open("./shakespeare.out", 'w', encoding="utf-8") as f: + f.writelines(sol) \ No newline at end of file