Skip to content

Instantly share code, notes, and snippets.

View coderick14's full-sized avatar
💭
Learning to prevent outages

Deep Bhattacharyya coderick14

💭
Learning to prevent outages
View GitHub Profile
@coderick14
coderick14 / differ.sh
Created October 18, 2020 00:42
Bash script to diff outputs of two codes
# Function to compile file if it's been modified.
compile() {
basename=$1
code_timestamp=$(stat -f '%c' "$basename.cpp")
executable_timestamp=$(stat -f '%c' "$basename")
if [[ code_timestamp -ge executable_timestamp ]]; then
echo "Compiling $basename.cpp"
g++ -std=c++14 "$basename.cpp" -o $basename
fi
}
@coderick14
coderick14 / string_guesser.py
Created June 3, 2019 14:34
Simple genetic algorithm to guess a string
import random
import time
import sys
from string import ascii_lowercase
class Individual:
def __init__(self, name, fitness = 0.0):
self.name = name
self.fitness = fitness
@coderick14
coderick14 / template.cpp
Last active November 13, 2020 03:55
CP template
/*
* Deleted code is debugged code :)
*/
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
@coderick14
coderick14 / Minesweeper.java
Created May 10, 2018 13:20
Minesweeper in Java
import java.util.Random;
import java.util.Scanner;
class Square {
private boolean hasMine;
private boolean isOpened;
private boolean isMarked;
private int mineCount;
private static final int neighbourCount = 8;
@coderick14
coderick14 / MoveSemantics.cpp
Created April 29, 2018 10:02
Move semantics in C++
#include <iostream>
using namespace std;
class Demo {
private:
int dataSize;
int* data;
public:
explicit Demo(int size) : dataSize(size), data(new int[size]) {
@coderick14
coderick14 / printer.cpp
Created April 10, 2018 14:01
Variadic Template for debugging in C++14
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void printer(T first) {
cout << first << "\n";
}
template<typename T, typename... Args>
void printer(T first, Args... args) {
@coderick14
coderick14 / trie.cpp
Created April 4, 2018 18:22
Object Oriented Trie
class TrieNode {
private:
const int CHILDREN_SIZE = 26;
bool wordEnds;
vector<TrieNode*> children;
public:
TrieNode() {
wordEnds = false;
children.resize(CHILDREN_SIZE);
class Solution {
public:
long mirror(long num) {
string mirrored = to_string(num);
int i = 0, j = mirrored.length() - 1;
while (i < j) {
mirrored[j--] = mirrored[i++];
}
return stol(mirrored);
}
@coderick14
coderick14 / reverse.asm
Created February 8, 2018 09:51
8086 program to reverse a string
.MODEL SMALL
.DATA
STR1 DB 5 DUP(' '),'$'
STR2 DB 5 DUP(' '),'$'
NL DB 0DH,0AH,'$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
@coderick14
coderick14 / palindrome.asm
Created February 8, 2018 09:50
8086 program to print check for palindrome
.MODEL SMALL
.DATA
STR1 DB 5 DUP(' '),'$'
NL DB 0DH,0AH,'$'
PRINTPAL DB 0DH,0AH,"PALINDROME$"
PRINTNOTPAL DB 0DH,0AH,"NOT PALINDROME$"
OKAY DB 0DH,0AH,"MATCH FOUND$"
.CODE
MAIN PROC
MOV AX,@DATA