Skip to content

Instantly share code, notes, and snippets.

View ashofphoenix's full-sized avatar
🐢
तर्कतथ्युक्तिचप्रमाणे वैदुष्यमशस्त्राणी ।

Ashish Bhatt ashofphoenix

🐢
तर्कतथ्युक्तिचप्रमाणे वैदुष्यमशस्त्राणी ।
View GitHub Profile
@ashofphoenix
ashofphoenix / totp.py
Last active March 12, 2021 14:37
Python script to generate TOTP as per RFC6238
# * Generate 10-digit time-based one time password conforming to RFC6238 TOTP.
#
# ** USERID is the email of participant and SECRET is some shared secret. USERID+SECRET is used to generate the
# ** SHARED_SECRET which is used at approver end also
#
import hmac
import hashlib
import time
import sys
@ashofphoenix
ashofphoenix / merge-sort.cpp
Created March 16, 2021 06:18
mergesort implementation in c++
#include <iostream>
using namespace std;
void print_a(int arr[], int start, int end){
/* Utility function to print array */
for(int i = start;i <= end; i++)
cout << arr[i] << " ";
cout << endl;
}
@ashofphoenix
ashofphoenix / frog_river_one.cpp
Last active March 20, 2021 06:56
Codility FrogRiverOne
/*
A small frog wants to get to the other side of a river. The frog is initially located on one bank of the river (position 0)
and wants to get to the opposite bank (position X+1). Leaves fall from a tree onto the surface of the river.
You are given an array A consisting of N integers representing the falling leaves. A[K] represents the position where one
leaf falls at time K, measured in seconds.
The goal is to find the earliest time when the frog can jump to the other side of the river. The frog can cross only when
leaves appear at every position across the river from 1 to X (that is, we want to find the earliest moment when all the
positions from 1 to X are covered by leaves). You may assume that the speed of the current in the river is negligibly small,
@ashofphoenix
ashofphoenix / max_counter.cpp
Created March 20, 2021 07:01
Codility max counter
/*
You are given N counters, initially set to 0, and you have two possible operations on them:
increase(X) − counter X is increased by 1,
max counter − all counters are set to the maximum value of any counter.
A non-empty array A of M integers is given. This array represents consecutive operations:
if A[K] = X, such that 1 ≤ X ≤ N, then operation K is increase(X),
if A[K] = N + 1 then operation K is max counter.
For example, given integer N = 5 and array A such that:
@ashofphoenix
ashofphoenix / perm_check.cpp
Created March 20, 2021 07:55
Check if the array element form a sequence from 1 ... N
/*
A non-empty array A consisting of N integers is given.
A permutation is a sequence containing each element from 1 to N once, and only once.
For example, array A such that:
A[0] = 4
A[1] = 1
A[2] = 3
@ashofphoenix
ashofphoenix / count_divisers.cpp
Last active April 18, 2021 16:23
Find the total number of divisers by K between range A and B
/*
Write a function:
int solution(int A, int B, int K);
that, given three integers A, B and K, returns the number of integers within the range [A..B] that are divisible by K, i.e.:
{ i : A ≤ i ≤ B, i mod K = 0 }
For example, for A = 6, B = 11 and K = 2, your function should return 3, because there are three numbers divisible by 2
@ashofphoenix
ashofphoenix / factory_pattern.php
Last active April 18, 2021 16:29
Implementation of Factory Pattern using PHP 7.0
<?php
/**
Define the classes and their methods (including parameters and return types) for a system that consist of a bookshelf,
books, magazines, and notebooks. The bookshelf should allow store and retrieval of the items as well as reporting on the
state of the bookshelf (how many items it has, how many more items it can hold) and initializing the capacity (in number
of items it can hold in total). The other items should allow reading of a single page given the page number that returns
the text of the page. A book has an accessible title and author. A magazine has an accessible name. A notebook has an
accessible owner.
*/
abstract class BookShelfFactory{
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
/**
* Check if string is balanced using stack DataStructure
*/
bool isBalanced(string s){
char c;
int n = s.length();
/**
* Program to find all the factors of given Number N
*/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]){
// int N = 2147483643;
@ashofphoenix
ashofphoenix / tree.cpp
Created April 18, 2021 16:19
Binary Search Tree with pre-order, post-order & in-order traversal
/**
* Program to make a tree structure with Pre-order, Post-order & In-order traversal
*/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
class Node {
public: