diff --git a/access_rights.md b/access_rights.md new file mode 100644 index 0000000..cf9f0a7 --- /dev/null +++ b/access_rights.md @@ -0,0 +1,209 @@ +--- +title: Access rights +--- + +# Problem Statement + +You are trying to create a permission based filesystem access for the new unix-inspired Operating System you are developing. The requirements for this system is as given below. + +For each file there is a known set of operations which may be applied to it: +write W, +read R, +execute X. + +The first line contains the number N — the number of files contained in the filesystem. The following N lines contain the file names and allowed operations with them, separated by spaces. The next line contains an integer M — the number of operations to the files. In the last M lines specify the operations that are requested for files. One file can be requested many times. + +For each request your program should return OK if the requested operation is valid or Access denied if the operation is invalid. + +**Input Format:** An integer N, followed by N lines containing the file names and permissions. Then an integer M on the next line, followed by M lines specifying operation requests on the files. + +**Output Format:** The response to each of the M requests, one per line, print `OK` if the requested operation is allowed or `Access denied` if it is disallowed. + +## Sample Input +``` +4 +helloworld.exe R X +pinglog W R +nya R +goodluck X W R +5 +read nya +write helloworld.exe +execute nya +read pinglog +write pinglog +``` +## Sample Output +``` +OK +Access denied +Access denied +OK +OK +``` + +# Solution +```python test.py -r 'python test.py' + +``` + +# Public Test Cases + +## Input 1 + +``` +4 +helloworld.exe R X +pinglog W R +nya R +goodluck X W R +5 +read nya +write helloworld.exe +execute nya +read pinglog +write pinglog +``` + +## Output 1 + +``` +OK +Access denied +Access denied +OK +OK +``` + + +## Input 2 + +``` +1 +abacaba X +3 +read abacaba +write abacaba +execute abacaba +``` + +## Output 2 + +``` +Access denied +Access denied +OK +``` + + +## Input 3 + +``` +1 +tmp_909925047 W X R +7 +execute tmp_909925047 +read tmp_909925047 +write tmp_909925047 +read tmp_909925047 +execute tmp_909925047 +execute tmp_909925047 +read tmp_909925047 +``` + +## Output 3 + +``` +OK +OK +OK +OK +OK +OK +OK +``` + + +# Private Test Cases + +## Input 1 + +``` +5 +tmp_1017722015 W +tmp_897110090 X W R +tmp_651548400 W X +tmp_422551574 X R W +tmp_477658548 W +1 +write tmp_897110090 +``` + +## Output 1 + +``` +OK +``` + +## Input 2 + +``` +2 +tmp_584361681 R X +tmp_70361076 X +3 +read tmp_70361076 +write tmp_70361076 +write tmp_70361076 +``` + +## Output 2 + +``` +Access denied +Access denied +Access denied +``` + +## Input 3 + +``` +4 +tmp_796487715 X R W +tmp_31144126 X R +tmp_967334538 R +tmp_264755563 R W +3 +read tmp_264755563 +execute tmp_796487715 +execute tmp_796487715 +``` + +## Output 3 + +``` +OK +OK +OK +``` diff --git a/frequency_analysis.md b/frequency_analysis.md new file mode 100644 index 0000000..049f6f6 --- /dev/null +++ b/frequency_analysis.md @@ -0,0 +1,277 @@ +--- +title: Frequency Analysis +--- + +# Problem Statement + +Given a number n, followed by n lines of text, create a function that prints all words encountered in the text, one per line. The words should be sorted in descending order according to their number of occurrences in the text, and all words with the same frequency should be printed in lexicographical order. + +**Input Format:** An integer `n` in the first line followed by n lines of text. + +**Output Format:** The sequence of words encountered in the text, one per line, sorted first by their frequencies and then lexicographically. + +**Sample Input** +``` +9 +hi +hi +what is your name +my name is bond +james bond +my name is damme +van damme +claude van damme +jean claude van damme +``` +**Sample Output** +``` +damme +is +name +van +bond +claude +hi +my +james +jean +what +your +``` + +**Hint:** After you create a dictionary of the words and their frequencies, you would like to sort it according to the frequencies. This can be achieved if you create a list whose elements are tuples of two elements: the frequency of occurrence of a word and the word itself. For example, [(2, 'hi'), (1, 'what'), (3, 'is')]. Then the standard list sort will sort a list of tuples, with the tuples compared by the first element, and if these are equal, by the second element. This is nearly what is required in the problem. + +# Solution +```python test.py -r 'python test.py' + +def frequency_analysis() -> None: + ''' + Print the sequence of words encountered in the text, + one per line, sorted first by their frequencies + and then lexicographically. + ''' + + + +frequency_analysis() + +``` + +# Public Test Cases + +## Input 1 + +``` +9 +hi +hi +what is your name +my name is bond +james bond +my name is damme +van damme +claude van damme +jean claude van damme +``` + +## Output 1 + +``` +damme +is +name +van +bond +claude +hi +my +james +jean +what +your +``` + + +## Input 2 + +``` +1 +ai ai ai ai ai ai ai ai ai ai +``` + +## Output 2 + +``` +ai +``` + + +## Input 3 + +``` +2 +iovjxotfvt h h iovjxotfvt h iovjxotfvt iovjxotfvt h +h iovjxotfvt +``` + +## Output 3 + +``` +h +iovjxotfvt +``` + + +# Private Test Cases + +## Input 1 + +``` +4 +eqlbahbovv pzpumhz mlcgtbbnfr +axsjbontg emojwajtfi +basdu nzyh wpyirkmz xxkmrr blnlqwcpur eqlbahbovv nzyh mlcgtbbnfr +mlcgtbbnfr axsjbontg mlcgtbbnfr mlcgtbbnfr mlcgtbbnfr blnlqwcpur mlcgtbbnfr +``` + +## Output 1 + +``` +mlcgtbbnfr +axsjbontg +blnlqwcpur +eqlbahbovv +nzyh +basdu +emojwajtfi +pzpumhz +wpyirkmz +xxkmrr +``` + +## Input 2 + +``` +14 +That thou hast her it is not all my grief, +And yet it may be said I loved her dearly, +That she hath thee is of my wailing chief, +A loss in love that touches me more nearly. +Loving offenders thus I will excuse ye, +Thou dost love her, because thou know'st I love her, +And for my sake even so doth she abuse me, +Suff'ring my friend for my sake to approve her. +If I lose thee, my loss is my love's gain, +And losing her, my friend hath found that loss, +Both find each other, and I lose both twain, +And both for my sake lay on me this cross, +But here's the joy, my friend and I are one, +Sweet flattery, then she loves but me alone. +``` + +## Output 2 + +``` +my +I +And +for +friend +her, +is +love +me +sake +she +That +and +both +hath +her +it +lose +loss +that +thou +A +Both +But +If +Loving +Suff'ring +Sweet +Thou +abuse +all +alone. +approve +are +be +because +but +chief, +cross, +dearly, +dost +doth +each +even +excuse +find +flattery, +found +gain, +grief, +hast +her. +here's +in +joy, +know'st +lay +losing +loss, +love's +loved +loves +may +me, +more +nearly. +not +of +offenders +on +one, +other, +said +so +the +thee +thee, +then +this +thus +to +touches +twain, +wailing +will +ye, +yet +``` diff --git a/knight_move.md b/knight_move.md new file mode 100644 index 0000000..da5d713 --- /dev/null +++ b/knight_move.md @@ -0,0 +1,213 @@ +--- +title: Knight Move +--- + +# Problem Statement + +In a game of chess, the knight moves like the letter L. It can move two cells horizontally and one cell vertically, or two cells vertically and one cells horizontally. Given two different cells of the chessboard, create a function that determines whether a knight can go from the first cell to the second in one move. +The function receives as input, four numbers from 1 to 8, each specifying the column and row number, first two - for the first cell, and then the last two - for the second cell. The function should return `True` if a knight can go from the first cell to the second in one move, or `False` otherwise. + +**Input Format:** A sequence of 4 integers, one per line, indicating the initial and final coordinates of the knight. + +**Output Format:** `True` if the maneuver is possible or `False` otherwise. + +## Sample Input +``` +2 +4 +3 +2 +``` +## Sample Output +``` +True +``` + +# Solution +```python test.py -r 'python test.py' + +def knight_move(x1: int, y1: int, x2: int, y2: int) -> bool: + ''' + Return True if the knight can move from + the first to the second coordinate + + Otherwise return False + ''' + + + +x1 = int(input()) +y1 = int(input()) +x2 = int(input()) +y2 = int(input()) +print(knight_move(x1, y1, x2, y2)) + +``` + +# Public Test Cases + +## Input 1 + +``` +1 +1 +1 +4 +``` + +## Output 1 + +``` +False +``` + + +## Input 2 + +``` +1 +1 +8 +8 +``` + +## Output 2 + +``` +False +``` + + +## Input 3 + +``` +2 +4 +3 +2 +``` + +## Output 3 + +``` +True +``` + + +## Input 4 + +``` +5 +2 +4 +4 +``` + +## Output 4 + +``` +True +``` + + +## Input 5 + +``` +2 +8 +3 +7 +``` + +## Output 5 + +``` +False +``` + + +# Private Test Cases + +## Input 1 + +``` +2 +8 +3 +5 +``` + +## Output 1 + +``` +False +``` + +## Input 2 + +``` +5 +5 +3 +7 +``` + +## Output 2 + +``` +False +``` + +## Input 3 + +``` +2 +4 +2 +5 +``` + +## Output 3 + +``` +False +``` + +## Input 4 + +``` +4 +7 +6 +6 +``` + +## Output 4 + +``` +True +``` + +## Input 5 + +``` +4 +5 +2 +4 +``` + +## Output 5 + +``` +True +``` diff --git a/reverse_the_sequence.md b/reverse_the_sequence.md new file mode 100644 index 0000000..7ee1051 --- /dev/null +++ b/reverse_the_sequence.md @@ -0,0 +1,157 @@ +--- +title: Reverse the sequence +--- + +# Problem Statement + +Given a sequence of integers as input that terminates with a 0, create a recursive function to print the sequence in reverse order. + +**Note:** Don't use lists or other data structures. + +**Input Format:** A sequence of integers, one per line and ends with 0. + +**Output Format:** The sequence of integers in reverse order, one per line. + +**Sample Input** +``` +1 +2 +3 +0 +``` +**Sample Output** +``` +0 +3 +2 +1 +``` + +# Solution +```python test.py -r 'python test.py' + +def reverse() -> None: + ''' + Print the sequence of integers + in reverse order. + ''' + + + +reverse() + +``` + +# Public Test Cases + +## Input 1 + +``` +1 +2 +3 +0 +``` + +## Output 1 + +``` +0 +3 +2 +1 +``` + + +## Input 2 + +``` +8 +7 +2 +3 +1 +4 +5 +0 +``` + +## Output 2 + +``` +0 +5 +4 +1 +3 +2 +7 +8 +``` + + +## Input 3 + +``` +1 +0 +``` + +## Output 3 + +``` +0 +1 +``` + + +# Private Test Cases + +## Input 1 + +``` +0 +``` + +## Output 1 + +``` +0 +``` + +## Input 2 + +``` +1 +2 +3 +4 +5 +6 +7 +8 +9 +0 +``` + +## Output 2 + +``` +0 +9 +8 +7 +6 +5 +4 +3 +2 +1 +```