This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]$") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Student.java | |
package com.shail; | |
import lombok.*; | |
@Getter | |
@NoArgsConstructor | |
@ToString | |
class Student { | |
private int id; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hello World Program in Assembly | |
.data | |
HelloWorldString: | |
.ascii "Hello World\n" | |
.text | |
.globl _start | |
_start: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HelloRunnable implements Runnable { | |
@Override | |
public void run() { | |
for(int i = 0; i <= 10; i++) { | |
System.out.println(i + "\t" + Thread.currentThread().getName()); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
NewerOlder