Skip to content

Instantly share code, notes, and snippets.

@obikag
obikag / TicTacToe.lua
Last active July 15, 2023 09:09
Simple game of Tic-Tac-Toe created in Lua. View comments for more details
--Start a new game
function new()
a = {" "," "," "}
b = {" "," "," "}
c = {" "," "," "}
player = 1
print("New game started")
end
--Print board to screen
@obikag
obikag / fibonacci.lua
Created August 13, 2013 23:10
Fibonacci Number methods done in Lua. First two methods calculates the Fibonacci number (n), while the last method prints the Fibonacci number sequence 'n' times.
-- Recursive Method calculating Fibonacci Number for n
function fibRecursion(n)
if n == 0 then
return 0
elseif n == 1 then
return 1
else
return fibRecursion(n-1) + fibRecursion(n-2)
end
end
@obikag
obikag / Simple-CSV.lua
Created July 31, 2013 00:52
Simple Lua Object that can read and modify a CSV file. Strings containing a comma (,) are not supported.
--Initialise
SimpleCSV = {}
SimpleCSV.__index = SimpleCSV
--Create new object
function SimpleCSV.new()
self = setmetatable({},SimpleCSV)
self.csv_table = {}
return self
end
@obikag
obikag / Key.java
Created August 30, 2013 01:31
Public Key Generator using the RSA algorithm written in JAVA. See comments for more details.
package main;
import java.math.BigInteger;
/**
* Key class used to store the key's Component and Modulus
* @author obikag
* @since 2013-06-22
*/
public class Key {
@obikag
obikag / XorCipher.lua
Created November 21, 2013 21:59
XOR Cipher in Lua. See comments for more information.
cipher = "10101111" -- must be eight digit binary number
--Returns the XOR of two binary numbers
function xor(a,b)
local r = 0
local f = math.floor
for i = 0, 31 do
local x = a / 2 + b / 2
if x ~= f(x) then
r = r + 2^i
@obikag
obikag / PascalTriangle.py
Last active January 9, 2019 17:14
Pascal's Triangle calculated using a recursive function in Python
'''
Created on Feb 24, 2015
'''
import sys
# Recursive method to create the mathematical series
def pascal(col,row):
if(col == 0) or (col == row):
return 1
else:
@obikag
obikag / tennis.html
Created August 24, 2016 12:38
My version of the tennis game from the Udemy course, "Code Your First Game: Arcade Classic in JavaScript on Canvas".
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<canvas id="gameCanvas" width="800" height="600"></canvas>
<script>
var canvas;
@obikag
obikag / ROT13.lua
Created October 18, 2013 02:39
ROT13 substitution cipher implemented in Lua. ROT13 function encrypts and decrypts a given string. Special characters and numbers are not encrypted with this cipher.
--Create a table to store the cipher
cipher = {
A="N",B="O",C="P",D="Q",E="R",F="S",G="T",H="U",I="V",J="W",K="X",L="Y",M="Z",
N="A",O="B",P="C",Q="D",R="E",S="F",T="G",U="H",V="I",W="J",X="K",Y="L",Z="M",
a="n",b="o",c="p",d="q",e="r",f="s",g="t",h="u",i="v",j="w",k="x",l="y",m="z",
n="a",o="b",p="c",q="d",r="e",s="f",t="g",u="h",v="i",w="j",x="k",y="l",z="m"
}
--Function encrypts and decrypts using ROT13
function ROT13(str)
@obikag
obikag / PascalTriangle.lua
Last active December 23, 2015 23:09
Pascal's Triangle calculated using a recursive function in Lua.
--Recursive function to create the mathemeatical series
function pascal(col,row)
if(col == 0) or (col == row) then return 1
else return pascal(col-1,row-1) + pascal(col,row-1)
end
end
--Prints Pascal's Triangle to the 'n'th row
function PascalTriangle(num)
if (num <= 0) then print("Number must be greater than zero") return end
@obikag
obikag / Prime.lua
Created September 19, 2013 00:03
Prime number functions done in Lua. First function determines if a number is prime, while the second function print to screen the first 'n' prime numbers. View comments for more information.
---Function to determine if a number is a prime number
function isPrime(num)
if num <= 0 then
print("Number must be a positive integer greater than zero")
return false
elseif num == 1 then return true end
--[[Prime number is divisable by itself and one,
so we check for other factors between the prime number and one. (1 < x < num)
]]
for x = num-1,2,-1 do