Skip to content

Instantly share code, notes, and snippets.

View hnh12358's full-sized avatar

Horacio Nunez hnh12358

View GitHub Profile
let empty m n =
requires (m = 0 || n = 0) MATRIX_EMPTYCREATION_BADDIMENSIONS
new FMatrix(m,n, fun (i,j) -> failwith MATRIX_EMPTY )
let identity m =
requires (m >= 0) MATRIX_IDENTITYCREATION_BADDIMENSIONS
if m = 0 then
empty 0 0
else
new FMatrix(m,m, fun (i,j) -> if i = j then 1.0 else 0.0)
function [Result ResultSudoku] = ResolveSudoku(InputSudoku)
A = [1 2 3 4 5 6 7 8 9];
B = [1 2 3 4 4 5 5 6 6 7 7 7 8 8 8 9 9 9];
C = [1 2 2 3 3 3 4 5 5 6 6 6 7 8 8 9 9 9];
f = @(x) sum(sum(power(2,x))) / 1022;
g = @(m,r,c) [m(3*r-2,3*c-2:3*c) m(3*r-1,3*c-2:3*c) m(3*r,3*c-2:3*c)];
j = @(m,r,c) g(m,sum(B == r),sum(B == c));
h = @(m,r,c) intersect(intersect(setdiff(A,m(r,:)),setdiff(A,m(:,c))),setdiff(A,j(m,r,c)));
function [R RS] = Resolve(IS,ESC)
if ESC == 0
@hnh12358
hnh12358 / verifying-ramanujan-1-over-pi.py
Created March 14, 2011 06:22
Verify the Ramanujan's 1/pi formula for 1000 digits of pi.
##author: Horacio Nunez
import decimal, math, functools
D = decimal.Decimal
C = decimal.getcontext()
C.prec = 1024
def multiply(x,y): return C.multiply(x,y)
@hnh12358
hnh12358 / functional-matrixs.fs
Created April 8, 2011 01:36
Building Simple Functional Mtrixs
let empty m n =
requires (m = 0 || n = 0) MATRIX_EMPTYCREATION_BADDIMENSIONS
new FMatrix(m,n, fun (i,j) -> failwith MATRIX_EMPTY )
let identity m =
requires (m >= 0) MATRIX_IDENTITYCREATION_BADDIMENSIONS
if m = 0 then
empty 0 0
else
new FMatrix(m,m, fun (i,j) -> if i = j then 1.0 else 0.0)
@hnh12358
hnh12358 / ObjectHelper.cs
Created November 22, 2012 02:34
NullDefender
//After working with a Functional Language I can't help to think that the world will be more
//safe without all the need to be checking for null values.
//This is an small helper I wrote to stop writing 'null' every once in a while.
namespace Horacio.Helpers
{
using System.Net.NetworkInformation;
public static class ObjectHelper
{
public void Foo(MailBodyFormat bodyFormat) {
string emailBody;
switch (bodyFormat)
{
case MailBodyFormat.PlainText:
isHtml = false;
emailBody = body;
break;
// In the end
if (newIndex == this.stepsInfo.Count)
{
return false; // It doesn't even matter
}
using System;
namespace CSharpAdventures
{
class MainClass
{
public static void Main (string[] args)
{
int max = Int32.MaxValue;
Console.WriteLine (CheckedSum(UncheckedSum(max,1),1)); //Doesn't Break.
//Console.WriteLine (UncheckedSum(CheckedSum(max,1),1)); //Will Break!
using System;
namespace CSharpAdventures
{
class MainClass
{
public static void Main (string[] args)
{
int max = Int32.MaxValue;