Program to Split the array and add the first part to the end

def splitArr(arr, n, k):

for i in range(0, k):

x = arr[0]

for j in range(0, n-1):

arr[j] = arr[j + 1]

arr[n-1] = x

arr = [12, 8, 10, 11, 52, 36]

n = len(arr)

position = 2

splitArr(arr, n, position)

for i in range(0, n):

print(arr[i], end = ' ')


Program for BogoSort or Permutation Sort

import random

def bogoSort(a):

n = len(a)

while (is_sorted(a)== False):

shuffle(a)

def is_sorted(a):

n = len(a)

for i in range(0, n-1):

if (a[i] > a[i+1] ):

return False

return True

def shuffle(a):

n = len(a)

for i in range (0,n):

r = random.randint(0,n-1)

a[i], a[r] = a[r], a[i]

a = [3, 2, 4, 1, 0, 5]

bogoSort(a)

print("Sorted array :")

for i in range(len(a)):

print ("%d" %a[i]),


Program to find mirror characters in a string

def mirrorChars(input,k):

original = 'abcdefghijklmnopqrstuvwxyz'

reverse = 'zyxwvutsrqponmlkjihgfedcba'

dictChars = dict(zip(original,reverse))

prefix = input[0:k-1]

suffix = input[k-1:]

mirror = ''

for i in range(0,len(suffix)):

mirror = mirror + dictChars[suffix[i]]

print (prefix+mirror)

if __name__ == "__main__":

input = 'paradox'

k = 3

mirrorChars(input,k)


Turtle race using python

import turtle

from random import *

from turtle import *

penup()

goto(-140,140)

for sp in range(15): 

  write(sp)

  right(90)

  forward(10)

  pendown()

  forward(150)

  penup()

  backward(160)

  left(90)

  forward(20)

x = Turtle() 

x.color('green') 

x.shape('turtle') 

x.penup() 

x.goto(-160,100) 

x.pendown() 

y = Turtle() 

y.color('red') 

y.shape('turtle') 

y.penup() 

y.goto(-160,80) 

y.pendown() 

turtlee = Turtle() 

turtlee.color('blue') 

turtlee.shape('turtle') 

turtlee.penup() 

turtlee.goto(-160,60) 

turtlee.pendown() 

for turn in range(100): 

  x.forward(randint(1,5)) 

  y.forward(randint(1,5)) 

  turtlee.forward(randint(1,5)) 

turtle.done()

Program for Recursive Topological Sorting

from collections import defaultdict

class Graph:

def __init__(self,vertices):

self.graph = defaultdict(list) 

self.V = vertices 

def addEdge(self,u,v):

self.graph[u].append(v)

def topologicalSortUtil(self,v,visited,stack):

visited[v] = True

for i in self.graph[v]:

if visited[i] == False:

self.topologicalSortUtil(i,visited,stack)

stack.insert(0,v)

def topologicalSort(self):

visited = [False]*self.V

stack =[]

for i in range(self.V):

if visited[i] == False:

self.topologicalSortUtil(i,visited,stack)

print (stack)

g= Graph(6)

g.addEdge(5, 2);

g.addEdge(5, 0);

g.addEdge(4, 0);

g.addEdge(4, 1);

g.addEdge(2, 3);

g.addEdge(3, 1);

print ("Following is a Topological Sort of the given graph")

g.topologicalSort()