Skip to content

Instantly share code, notes, and snippets.

View MihailJP's full-sized avatar

MihailJP MihailJP

View GitHub Profile
@MihailJP
MihailJP / gcd.lua
Created January 26, 2014 11:25
Implementation of Euclidian algorithm
function gcd(a, b)
local x = a; local y = b
repeat
if x > y then
x = math.fmod(x, y)
else
y = math.fmod(y, x)
end
until x == 0 or y == 0
return x + y
@MihailJP
MihailJP / groovy.spec
Last active August 29, 2015 14:00 — forked from kazuhisya/Makefile
%define groovy_root_dir /usr/share
Name: groovy
Version: 2.2.2
Release: 1%{?dist}
License: See: http://groovy.codehaus.org/license.html
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Group: Development/Languages/Groovy
Summary: Contains the base system for executing groovy scripts.
Source: http://dist.codehaus.org/groovy/distributions/groovy-binary-%{version}.zip
@MihailJP
MihailJP / modulo.hpp
Created May 17, 2014 10:31
C++ modulo whose resulting sign is same as DIVISOR, not dividend
#include <stdexcept>
template<typename T> T modulo(T dividend, T divisor) {
if (divisor == static_cast<T>(0)) // division by zero is not allowed
throw std::domain_error("division by zero");
if (dividend < static_cast<T>(0)) // dividend is negative
return -((-dividend) % (-divisor));
else // dividend is non-negative
return dividend % divisor;
}
@MihailJP
MihailJP / gcd.fth
Created May 17, 2014 11:25
GCD and LCM of two numbers, implemented with Forth
\ This implements Euclidean algorithm in Forth
: gcd ( X Y )
2dup <= if swap ( Y X ) then
( X Y )
begin
tuck ( Y X Y )
mod ( Y Z )
dup ( Y Z Z )
0= until ( Y Z )
( Y 0 )