Skip to content

Instantly share code, notes, and snippets.

View shailrshah's full-sized avatar
🖥️
Available

Shail Shah shailrshah

🖥️
Available
View GitHub Profile
@shailrshah
shailrshah / hangman.py
Created January 22, 2020 18:22
Play hangman on the command line
from collections import defaultdict
from os import system
def clear():
_ = system('clear')
class Hangman:
def __init__(self):
self.word = input("Enter the word to guess: ").lower()
@shailrshah
shailrshah / balanced_paranthesis.py
Created January 22, 2020 18:21
Return a unique list of strings each of length 2*n which have balanced paranthesis
from typing import List
def generate_all_paranthesis(n: int) -> List[str]:
'Return a unique list of strings each of length 2*n which have balanced paranthesis'
all_paranthesis = []
backtrack_helper(all_paranthesis, "", 0, 0, n)
return all_paranthesis
def backtrack_helper(all_paranthesis: List[str], curr_str: str, open: int, close: int, n: int) -> None:
@shailrshah
shailrshah / scopeAndHoisting.js
Created May 20, 2019 17:40
Javascript Scope and Hoisting
// Scope - let and const have block scope. var has function scope.
if(true) {var x = 1; let y = 2; const z = 3;}
console.log(x); // 1
console.log(y); // ReferenceError: y is not defined
console.log(z); // ReferenceError: z is not defined
let y = 2;
const z = 3;
y = 20;
z = 30; // TypeError: Assignment to constant variable.
console.log(y); // 20
@shailrshah
shailrshah / hangman.py
Created January 7, 2019 07:12
Hangman
from re import compile
class Hangman:
"""Play Hangman"""
def __init__(self, word="demo", chances=3):
"""Initialize the game with the correct word and number of chances"""
self.wordPattern = compile("^[a-z]+$")
self.guessPattern = compile("^[a-z]$")
@shailrshah
shailrshah / diceRoller.py
Created January 7, 2019 05:32
A program to simulate dice rolls
from random import randint
class DiceRoller:
"""A DiceRoller instance is able to simulate dice rolls"""
def __init__(self, min=1, max=6):
self.min = min
self.max = max
print("Initialized. min is", min, "and max is", max)
package com.shail;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class BackTrack {
// [1, 2, 3] => {1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}
// Ordering matters
@shailrshah
shailrshah / Student.java
Last active July 8, 2018 21:08
JSON serialization/deserialization
// Student.java
package com.shail;
import lombok.*;
@Getter
@NoArgsConstructor
@ToString
class Student {
private int id;
@shailrshah
shailrshah / HelloWorld.s
Created March 27, 2018 15:52
Hello World in Assembly
# Hello World Program in Assembly
.data
HelloWorldString:
.ascii "Hello World\n"
.text
.globl _start
_start:
@shailrshah
shailrshah / ThreadDemo.java
Last active March 27, 2018 12:39
Threading example
class HelloRunnable implements Runnable {
@Override
public void run() {
for(int i = 0; i <= 10; i++) {
System.out.println(i + "\t" + Thread.currentThread().getName());
}
}
}
@shailrshah
shailrshah / Person.java
Created March 19, 2018 22:32
Sort a list of people using CompareTo
import java.util.Collections;
import java.util.List;
public class Person implements Comparable<Person>{
private int age;
private String name;
Person(String name, int age) {
this.name = name;
this.age = age;