From 92714b545ab82a488e3e60591284aeb87c51cbff Mon Sep 17 00:00:00 2001 From: Achyut Tripathi <62375358+Achyut08@users.noreply.github.com> Date: Fri, 1 Oct 2021 01:38:16 +0530 Subject: [PATCH] Add files via upload --- gfg/Array rotation.py | 17 +++++++++++++++++ gfg/Monotonicity of array.py | 7 +++++++ gfg/hole problem.py | 8 ++++++++ gfg/run length encoding.py | 25 +++++++++++++++++++++++++ gfg/sum of array.py | 5 +++++ 5 files changed, 62 insertions(+) create mode 100644 gfg/Array rotation.py create mode 100644 gfg/Monotonicity of array.py create mode 100644 gfg/hole problem.py create mode 100644 gfg/run length encoding.py create mode 100644 gfg/sum of array.py diff --git a/gfg/Array rotation.py b/gfg/Array rotation.py new file mode 100644 index 0000000..dd1ee50 --- /dev/null +++ b/gfg/Array rotation.py @@ -0,0 +1,17 @@ +def rotatearray(arr,n,d): + temp=[] + i=0 + while(i< d): + temp.append(arr[i]) + i=i+1 + i=0 + while(d=a[i+1] for i in range(len(a)-1))) + + +A = [6, 5, 4, 4] +print(IsMonotonic(A)) diff --git a/gfg/hole problem.py b/gfg/hole problem.py new file mode 100644 index 0000000..9f9519e --- /dev/null +++ b/gfg/hole problem.py @@ -0,0 +1,8 @@ +s = input() +hole=0 +for i in s: + if (i in ["A","D","O","P","R"]): + hole+= 1 + elif(i in ["B"]): + hole= hole+2 +print(hole) \ No newline at end of file diff --git a/gfg/run length encoding.py b/gfg/run length encoding.py new file mode 100644 index 0000000..a4344c7 --- /dev/null +++ b/gfg/run length encoding.py @@ -0,0 +1,25 @@ +def encode(message): + count = 0 + chatacter = '' + previous_char = message[0] + result = '' + length = len(message) + + i = 0 + while (i != length ): + chatacter = message[i] + + if previous_char == chatacter : + count = count + 1 + else : + result = result + str(count) + previous_char + count = 1 + #print(str(i) + str(chatacter) + str(previous_char) + " " + str(result)) + previous_char = chatacter + i = i + 1 + + return result + str(count) + str(previous_char) + +m=int(input("Enter the string")) +encoded_message=encode(m) +print(encoded_message) diff --git a/gfg/sum of array.py b/gfg/sum of array.py new file mode 100644 index 0000000..634026e --- /dev/null +++ b/gfg/sum of array.py @@ -0,0 +1,5 @@ +sum=0 +arr={1,2,3,4} +for i in arr: + sum=sum+i +print(sum)