Skip to content

Instantly share code, notes, and snippets.

@georgespingos
georgespingos / gist:4317570
Last active December 9, 2015 19:28
Calculate Fibonacci without recursion or loops !! (Math hack)
public static double SuperCoolFibonacci(int n)
{
return Math.Round((Math.Pow(0.5 + 0.5 * Math.Sqrt(5.0), n) - Math.Pow(0.5 - 0.5 * Math.Sqrt(5.0), n)) / Math.Sqrt(5.0), MidpointRounding.AwayFromZero);
}
@georgespingos
georgespingos / gist:4317529
Created December 17, 2012 11:14
One line FizzBuzz in C# (135 character)
Enumerable.Range(1, 20).ToList().ForEach(c => Console.WriteLine((c%15==0)?"FizzBuzz":((c%3==0)?"Fizz":(c%5==0)?"Buzz":c.ToString())));
@georgespingos
georgespingos / gist:4276659
Last active October 13, 2015 23:58
Validate Greek IBAN
import string
def VAlidateIBAN_GR(IBAN):
if len(IBAN) != 27 or IBAN[0].isalpha() == False or IBAN[1].isalpha() == False or IBAN[2:].isdigit() == False:
return False;
alph={};
i=10;
for x in string.ascii_uppercase:
@georgespingos
georgespingos / gist:4275860
Created December 13, 2012 11:30
C# Validate AMKA
public static bool ValidateAMKA(string AMKA)
{
double _numAMKA = 0;
int sum = int.Parse(AMKA.Last().ToString());
if (AMKA.Length != 11 || !double.TryParse(AMKA, out _numAMKA))
return false;
else
{
int iter = AMKA.Length - 1;
@georgespingos
georgespingos / gist:4275696
Created December 13, 2012 10:53
Python AMKA Validator (no string slice)
def ValidateAMKA (amka):
if len(amka) != 11 or amka.isdigit() == False:
return False
else:
sum = int(amka[10])
i = 0
for s in amka[0:10]:
if i%2 != 0:
if int(s)* 2 > 9:
sum += int(s)*2 % 10+1
@georgespingos
georgespingos / gist:4275486
Created December 13, 2012 10:16
Python Validate AMKA
def ValidateAMKA (amka):
if len(amka) != 11 or amka.isdigit() == False:
return False
else:
sum = int(amka[10])
i = 0
for s in amka[0:10]:
if i%2 != 0:
if int(s)* 2 > 9:
sum += int(str(int(s)* 2)[0]) + int(str(int(s)* 2)[1])