Skip to content

Instantly share code, notes, and snippets.

@mefahimrahman
mefahimrahman / Duplicate Character Check in string
Created February 6, 2021 18:49
Check if a string contains duplicate characters or not.
def check_unique_characters(astring):
for char in range(len(astring)):
for chars in range(char+1, len(astring)):
if astring[chars] == astring[char]:
return False
return True
if __name__ == "__main__":
astr = input()
@mefahimrahman
mefahimrahman / Merge Sort
Created February 5, 2021 18:50
Implementation of Merge Sort Algorithm
def mergeSort(alist):
if len(alist) > 1:
# Divide the given list until single element in each side
mid = len(alist) // 2
lefthalf = alist[:mid]
righthalf = alist[mid:]
mergeSort(lefthalf)
mergeSort(righthalf)
@mefahimrahman
mefahimrahman / Find the First and Last occurrence of a number
Last active February 3, 2021 19:12
Using Binary search find out the first/last occurrence of number.
def BinaryIterativeSearch(alist, num):
start = 0
end = len(alist)
# For finding the fisrt or last occurrence of any number
# res = -1
while end >= start:
mid = (start + end) // 2
@mefahimrahman
mefahimrahman / Binary Search
Last active February 3, 2021 19:27
Implementation of Binary Search Algorithm both in iterative and recursive approchs.
@mefahimrahman
mefahimrahman / Linear Search
Created January 24, 2021 16:57
Linear Search Implementation
@mefahimrahman
mefahimrahman / Towers_of_Hanoi
Last active January 24, 2021 16:54
This is my implementation of the Towers of Hanoi algorithm.
def towersOfHanoi(n, source, destination):
'''
Calculate the moving steps for moving
n number of disks from Source Tower to
Destination Tower using one Intermidiate Tower.
'''
if n == 1:
printMessase(source, destination)
return
@mefahimrahman
mefahimrahman / Prime Sieve
Last active January 24, 2021 16:58
This is my implementation of Sieve of Eratosthenes for finding out all prime numbers up to n (getting from input) number.
def sieve_prime(alist):
# Mark all odd number as prime
i = 3
while i <= len(alist):
alist[i] = True
# Mark Only odd numbers
i += 2
# Multiples Mark
i = 3
@mefahimrahman
mefahimrahman / check_import.py
Created August 11, 2019 06:26 — forked from peterjc123/check_import.py
Help to detect import errors for PyTorch on Windows
# This script tries to figure out the reason of
# `ImportError` on Windows.
# Run it with `python check_import.py`.
import ctypes
import glob
import os
import sys
import subprocess
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x=7,&y=x;
cout<<"Whithout Increment: ";
cout<<&x<<" "<<&y<<endl;
cout<<x<<" "<<y<<endl;
--x;