Skip to content

Instantly share code, notes, and snippets.

#Solving this:
#https://www.youtube.com/watch?v=uCsD3ZGzMgE
#by iteration and not math
def JosephusProblem(n):
people = list(range(1,n+1))
i = 0
@lukakostic
lukakostic / MoreRandom.cs
Last active August 22, 2018 22:39
Better UnityEngine.Random, replace "Random" with this "MoreRandom" in your code and thats it
//More random version of UnityEngine.Random
//Just replace Random with MoreRandom in your code and thats it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
// Images, example and guide at : https://github.com/lukakostic/Random-Infinite-2DTerrain
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(PolygonCollider2D))]
[RequireComponent(typeof(LineRenderer))]
public class RandomTerrain2D : MonoBehaviour {
@lukakostic
lukakostic / Source.c
Created August 22, 2018 22:38
Print digits of pi using the Leibniz formula: pi = 4 * (1 -1/3 +1/5 -1/7 ....)
//Print digits of pi using the Leibniz formula: pi = 4 * (1 -1/3 +1/5 -1/7 ....)
#include <stdio.h>
#define NumType long double
int main(){
NumType d = 1.0;
NumType f = 0.0;
@lukakostic
lukakostic / Perlin_Tiled.cs
Created August 23, 2018 07:31 — forked from Flafla2/Perlin_Tiled.cs
A slightly modified implementation of Ken Perlin's improved noise that allows for tiling the noise arbitrarily.
public class Perlin {
public int repeat;
public Perlin(int repeat = -1) {
this.repeat = repeat;
}
public double OctavePerlin(double x, double y, double z, int octaves, double persistence) {
double total = 0;
//1-neuron N-inputs 1-output perceptron in c++ (Binary classifier)
//Training data is for AND but you edit it to what you want the Perceptron to learn
//Short and sweet with lots of comments
#include <stdio.h>
#define dataLenght 4
#define numOfInputs 2
#define trainTimes 100
/*
Try doing your own to replicate the below output, it took me more than id like to admit ;) (~1-2hrs)
lenght = 25
*************************
************ ************
*********** ***********
********** **********
********* *********
******** ********
******* *******
#define n double
n l=25; //Change this
#define p(X) putchar("* \n"[X])
#define f(X,Y) for(n X=0;X<l;p(Y)){X++;
n g(n z){return z==1?0:(z==2?1:g(z-1)+2);}void main(){n o=0.5;n h=l*o;f(i,2)n d=i>h?g(l-i+1):g(i);
n s=(l-d)*o;f(j,(j==h+o)?(j<=(s+o)?0:1):(j<=h?(j<(s+o)?0:1):((l+1-j)<(s+o)?0:1)))}}}
@lukakostic
lukakostic / Noise.py
Created August 31, 2018 05:17
Produces a random colored noise image of size
from PIL import Image
import numpy as np
import random
import time
random.seed(time.time())
size = 256 #edit size here
im = Image.new('RGB', (size, size))
@lukakostic
lukakostic / encrypt_decrypt.c
Created October 1, 2018 15:16
Start args: key mode(encrypt/decrypt) input.txt output.txt OR input.txt output.txt (will encrypt and print the random key used)
#include<stdio.h>
#include<stdlib.h> //rand & srand
#include<time.h> //to seed srand
int main(int argc, char * argv[])
{
FILE * file;
long length; //file length
char * text = 0;