Skip to content

Instantly share code, notes, and snippets.

View MihailJP's full-sized avatar

MihailJP MihailJP

View GitHub Profile
@MihailJP
MihailJP / fizzbuzz.hs
Created September 14, 2012 16:44
Fizz Buzz in Haskell
fizzbuzz = [f n | n <- [1..]]
where
f x
| x `mod` 15 == 0 = "Fizz Buzz"
| x `mod` 5 == 0 = "Buzz"
| x `mod` 3 == 0 = "Fizz"
| otherwise = show (fromIntegral x)
main = do print (take 60 fizzbuzz)
@MihailJP
MihailJP / gist:3652275
Created September 6, 2012 06:53
Logical (not bitwise) XOR in C++
#include <iostream>
int main() {
int a = 1; int b = 2;
if ((bool)a != (bool)b)
std::cout << "a xor b -> true" << std::endl;
else
std::cout << "a xor b -> false" << std::endl;
return 0;
}
@MihailJP
MihailJP / gist:3599125
Created September 2, 2012 13:55
Lua scope test
v = "global"
do
print(v) -- "global"
local v = "local"
print(v) -- "local", of course
v = nil
print(v) -- nil, not "global"
collectgarbage("collect")
print(v) -- still nil
print (_G.v) -- of course "global"
@MihailJP
MihailJP / complex.lua
Created August 28, 2012 16:41
Complex numbers for Lua
--[[
--
-- *** Complex numbers for Lua ***
--
--]]
-- Module "cmath" ... mathematic functions for complex numbers
module("cmath", package.seeall)