Skip to content

Instantly share code, notes, and snippets.

View Lakhan-Nad's full-sized avatar
🎯
Focusing

Lakhan Nad Lakhan-Nad

🎯
Focusing
View GitHub Profile
@Lakhan-Nad
Lakhan-Nad / bencodeDecode.kt
Last active November 24, 2022 20:00
Bencode decoder in Kotlin
import java.lang.Exception
import java.nio.charset.Charset
// Bencode parser in Kotlin
object BencodeParser {
class InvalidBencodeFormat(
startIndex: Int,
msg: String
@Lakhan-Nad
Lakhan-Nad / Client.java
Created November 3, 2020 15:55
Generic Client-Server program boilerplate code. Easily customizable as per your requirements
package client;
import java.io.Console;
import java.util.Scanner;
public final class Client {
private static Session session;
private static Scanner sc;
private Client() {
@Lakhan-Nad
Lakhan-Nad / RandomPointsInPlane.java
Last active August 3, 2020 07:13
Generates random point inside a given polygon (it can also be a straight line)
import java.util.Random;
import java.util.Date;
public class RandomPointsInPlane{
private static final int BATCH_SIZE = 25;
private static final int MIN_BATCH_SIZE = 5;
public static long getSeed(){
return (new Date().getTime() % Integer.MAX_VALUE);
@Lakhan-Nad
Lakhan-Nad / KMeansWithKpp.java
Created August 2, 2020 06:52
K means clustering using K++ initialisation
import java.util.Random;
public class KMeansWithKpp{
// Data Needed
public Point[] points;
public Point[] centroids;
Random rand;
public int n;
public int k;
@Lakhan-Nad
Lakhan-Nad / piCollisions.cpp
Created July 10, 2020 10:00
Based and inspired by 3Blue1Brown's Pi Collisions Video.
// Includes
#include <iostream>
class Box {
private:
long double x, v, m, w;
public:
Box(long double wx, long double mx) {
w = wx;
@Lakhan-Nad
Lakhan-Nad / mastermind_solve.cpp
Last active June 25, 2020 11:40
Donald E. Knuth's method to solve MasterMind Game
#include <iostream>
class solution {
private:
// game configs
int positions;
int options;
char *secret;
int chances;
@Lakhan-Nad
Lakhan-Nad / random_lcg.cpp
Last active August 2, 2020 11:33
linear congruential generator implemented in CPP
class random {
private:
static long long seed;
static const long long rand_max = 4294967296; // 2^32
static const long long multiplier = 22695477;
static const long long increament = 1;
public:
static void srand(long long s) { seed = s; }
static long long rand() {
# Import Pandas Library
import pandas as pd
# Custom Exception Added
class AlreadyUpperCase(Exception):
def __init__(self):
super().__init__("DataFrame Provided Is Already In Upper Case")
pass
@Lakhan-Nad
Lakhan-Nad / introsort.cpp
Last active August 15, 2020 01:56
Tried to implement C++'s STL Sort routine -- Introsort
/* Trying to implement Introsort for integer array
Used in STL
*/
/* Headers for testing */
#include <cstdlib>
#include <iostream>
namespace IntroSort {
@Lakhan-Nad
Lakhan-Nad / CompetetiveTemplate.cpp
Last active April 20, 2020 19:12
A template for Competetive programming can be used in C/C++ both.
#include <stdio.h>
#include <iostream>
/* FAST I/O for cin cout methods */
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
/* Impement as testcase{ body for each testcase} */
#define testcase \
long long t; \
scanf("%lld", &t); \