Loading...
More Python Posts
# Python program for implementation of Bogo Sortimport random# Sorts array a[0..n-1] using Bogo sortdef bogoSort(a):n = len(a)while (is_sorted(a)== False):shuffle(a)# To check if array is sorted or notdef is_sorted(a):n = len(a)for i in range(0, n-1):if (a[i] > a[i+1] ):return Falsereturn True# To generate permuatation of the arraydef 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]# Driver code to test abovea = [3, 2, 4, 1, 0, 5]bogoSort(a)print("Sorted array :")for i in range(len(a)):print ("%d" %a[i]),
#You are given a two-digit integer n. Return the sum of its digits.#Example#For n = 29 the output should be solution (n) = 11def solution(n):return (n//10 + n%10)
print("hellur")
import subprocess #for the praat callsimport os #for ffmpeg and the pause call at the end#Even if we wanted all videos being rendered asynchronously, we couldn't see progress or errorsimport glob #for the ambiguous filesimport tempfileaudioFileDirectory = 'Audio Files'timeList = {}fileList = glob.glob(audioFileDirectory + '\\*.wav')pipeList = {}for fileName in fileList:arglist = ['Praat.exe', '--run', 'crosscorrelateMatch.praat', 'zeussound.wav', fileName, "0" , "300"]print(' '.join(arglist))pipe = subprocess.Popen(arglist, stdout=subprocess.PIPE)pipeList[fileName[len(audioFileDirectory)+1:-4]] = pipe #+1 because of back slash, -4 because .wav#for fileName, pipe in pipeList.items():# text = pipe.communicate()[0].decode('utf-8')# timeList[fileName] = float(text[::2])for fileName, pipe in pipeList.items():if float(pipe.communicate()[0].decode('utf-8')[::2]) > .0003: #.000166 is not a match, and .00073 is a perfect match. .00053 is a tested matcharglist = ['Praat.exe', '--run', 'crosscorrelate.praat', 'zeussound.wav', audioFileDirectory + '\\' + fileName + '.wav', "0" , "300"]print(' '.join(arglist))text = subprocess.Popen(arglist, stdout=subprocess.PIPE).communicate()[0].decode('utf-8')timeList[fileName] = float(text[::2])clipLength = 10for fileName, time in timeList.items():arglist = ['ffmpeg', '-i', '"'+fileName+'.mp4"', '-ss', str(time-clipLength), '-t', str(clipLength*2), '-acodec', 'copy' , '-vcodec', 'copy', '"ZEUS'+ fileName + '.mp4"']print(' '.join(arglist))os.system(' '.join(arglist))tempFile = tempfile.NamedTemporaryFile(delete=False)for fileName in glob.glob('ZEUS*.mp4'):tempFile.write(("file '" + os.path.realpath(fileName) + "'\n").encode());tempFile.seek(0)print(tempFile.read())tempFile.close()arglist = ['ffmpeg', '-safe', '0', '-f', 'concat', '-i', '"'+tempFile.name+'"', '-c', 'copy', 'ZeusMontage.mp4']print(' '.join(arglist))os.system(' '.join(arglist))os.unlink(tempFile.name) #Delete the temp file#print(timeList)os.system('PAUSE')
""" Binary Search Algorithm----------------------------------------"""#iterative implementation of binary search in Pythondef binary_search(a_list, item):"""Performs iterative binary search to find the position of an integer in a given, sorted, list.a_list -- sorted list of integersitem -- integer you are searching for the position of"""first = 0last = len(a_list) - 1while first <= last:i = (first + last) / 2if a_list[i] == item:return ' found at position '.format(item=item, i=i)elif a_list[i] > item:last = i - 1elif a_list[i] < item:first = i + 1else:return ' not found in the list'.format(item=item)#recursive implementation of binary search in Pythondef binary_search_recursive(a_list, item):"""Performs recursive binary search of an integer in a given, sorted, list.a_list -- sorted list of integersitem -- integer you are searching for the position of"""first = 0last = len(a_list) - 1if len(a_list) == 0:return ' was not found in the list'.format(item=item)else:i = (first + last) // 2if item == a_list[i]:return ' found'.format(item=item)else:if a_list[i] < item:return binary_search_recursive(a_list[i+1:], item)else:return binary_search_recursive(a_list[:i], item)
def Fibonacci(n):if n<0:print("Incorrect input")# First Fibonacci number is 0elif n==1:return 0# Second Fibonacci number is 1elif n==2:return 1else:return Fibonacci(n-1)+Fibonacci(n-2)# Driver Programprint(Fibonacci(9))