Skip to content

Instantly share code, notes, and snippets.

View rakeshsukla53's full-sized avatar

Rakesh Sukla rakeshsukla53

View GitHub Profile
import numpy as np
import random
def one_to_five():
two_D_array = np.array([[1, 2, 3, 4, 5], [6, 7, 1, 2, 3], [4, 5, 6, 7, 1], [2, 3, 4, 5, 6], [7, 0, 0, 0, 0]], int)
x = random.randrange(1, 6, 1)
y = random.randrange(1, 6, 1)
@rakeshsukla53
rakeshsukla53 / Highest Palindrome finder in a string
Created March 9, 2015 08:54
Dynamic programming for palindrome finder
__author__ = 'rakesh'
# print out the highest palindrome and length of each palindrome exist in the string
def Palindrome(text):
list = []
palindrome = []
new_list = []
f = []
@rakeshsukla53
rakeshsukla53 / Twitter Sentiment Analysis
Created March 9, 2015 09:06
Twiter Sentiment Analysis
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import urllib, json
import urllib2
ckey = ''
csecret = ''
atoken = ''
asecret = ''
@rakeshsukla53
rakeshsukla53 / Linux Commands
Created March 12, 2015 01:14
Interesting list of linux commands
1- curl www.website.com/ | grep '^<a href=.*title=$' > new1.txt
this will fetch all the links stored in a given website and display it into the file new1.txt
2-
@rakeshsukla53
rakeshsukla53 / Regex
Last active June 20, 2020 21:54
Regular Expression list
Regular Expression #use this link http://regexone.com/lesson/3
1-
match text abc123xyz ?
match text define “123” ?
match text var g = 123;
.* -> . means select any character, *one or more character
[a-z0-9]+ -> it will only cover abc123xyz because it will take any character between a-z and 0-9
@rakeshsukla53
rakeshsukla53 / forever_alone
Last active August 29, 2015 14:17
Find single elements among duplicates
a = [7, 2, 2, 3, 3, 4, 4, 55, 55, 100, 100]
b = 0
#for i in range(len(a)):
#you will find the forever alone element in the array
def XOR():
@rakeshsukla53
rakeshsukla53 / Subsets
Created March 29, 2015 05:37
Find subsets
__author__ = 'rakesh'
import math
'''
Q3. Write a code to find all subsets of a given set:-
Exp: {1,2,3} will give {1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}
'''
'''
@rakeshsukla53
rakeshsukla53 / Binary_Search_Tree
Created March 30, 2015 01:05
Binary_Search_tree
__author__ = 'rakesh'
class BinarySearchTree: #now you can perform any type of opertion on this tree
def __init__(self, value):
self.value = value
self.right = None
self.left = None
@rakeshsukla53
rakeshsukla53 / Red Black Tree
Created March 30, 2015 03:45
Red Black Tree Description
Red Black Tree is a Binary Search Tree which the following red-black properties
1- Every node is either black or red
2- Every leaf(NULL) is black
3- if a node is red then both its children will be black
4- Every simple path from a node to a descendent leaf contains the same number of black nodes.
<implies that on any path from the root to a leaf, red nodes must not be adjacent. However, any number of black nodes may appear in a sequence >
Image - <https://www.cs.auckland.ac.nz/software/AlgAnim/fig/rb_tree1.gif> this is a basic red black tree
@rakeshsukla53
rakeshsukla53 / Merge Sort, Heap Sort , RSA and Convex
Last active August 29, 2015 14:18
Questions based on merge sort , insertion sort and heap sort
Video referred for merge sort <https://www.youtube.com/watch?v=jeaxzxErLKk>
def mergeSort(alist):
2 print("Splitting ",alist)
3 if len(alist)>1:
4 mid = len(alist)//2
5 lefthalf = alist[:mid]
6 righthalf = alist[mid:]
7
8 mergeSort(lefthalf)