This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cassert> | |
#include <cmath> | |
#include <iostream> | |
using namespace std; | |
void printbytes(double d) { | |
unsigned long long int* pi = (unsigned long long int*) &d; | |
unsigned long long int i = *pi; | |
short int e = (i >> 52 & 0x7ff) - 1023; // Exponent | |
unsigned long long int m = (i << 12 >> 12) + pow(2, 52); // Mantissa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fib :: Int -> Int | |
fib x | |
| x < 0 = error ("Can't calculate fib of negative number " ++ show x) | |
| x == 0 = 0 | |
| x > 0 = accum (x-1) 0 1 | |
where | |
accum :: Int -> Int -> Int -> Int | |
accum x y z | |
| x > 0 = accum (x-1) z (y+z) | |
| otherwise = z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
split :: Ord a => a -> [a] -> ([a],[a]) | |
split x ys = accum x ys ([],[]) | |
where | |
accum :: Ord a => a -> [a] -> ([a],[a]) -> ([a],[a]) | |
accum _ [] result = result | |
accum x (y:ys) (ls,rs) | |
| y > x = accum x ys (ls,y:rs) | |
| otherwise = accum x ys (y:ls,rs) | |
sort :: Ord a => [a] -> [a] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Test::More; | |
use List::Util qw(reduce); | |
my @masks = map { | |
my $group_bin = 0 x $_ . 1 x $_; | |
my $bin_length = $_ * 2; | |
my $mask_bin = $group_bin x ( 32 / $bin_length ); |
NewerOlder