This file contains 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
%% Power function (X ^ Y) and root function (X ^ (1/Y)) for | |
%% integers in Erlang | |
%% by Kenji Rikitake <[email protected]> 26-JAN-2010 | |
%% modified by Hynek Vychodil <[email protected]> 2-FEB-2010 | |
%% Distributed under MIT license at the end of the source code. | |
-module(bignum_root). | |
-export([power/2, root/2, sqrt/1]). |
This file contains 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
proplists_get_value(Key, List)-> | |
case lists:keyfind(Key,1,List) of | |
{K,V} when K =:= Key -> | |
V; | |
_-> | |
proplists_get_value_(Key, List) | |
end. | |
proplists_get_value_(_,[])-> | |
undefined; |
This file contains 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
use strict; | |
use warnings; | |
package LCP; | |
sub LCP { | |
return '' unless @_; | |
return $_[0] if @_ == 1; | |
my $i = 0; | |
my $first = shift; |
This file contains 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
drop table if exists products; | |
drop table if exists prod; | |
drop table if exists `out`; | |
SET max_heap_table_size = 1024*1024*1024; | |
create table products ( id int not null, partner int not null, start date not null) engine=memory ; | |
load data infile '/tmp/test.data' into table products columns terminated by ','; | |
create table prod ( r int not null AUTO_INCREMENT primary key, rp int default 1, id int not null, partner int not null, start date ) engine=memory as select id, partner, start from products order by partner, start; | |
drop table products; | |
update prod set rp = r-1; | |
create table `out` engine=memory select p1.id, p1.partner, p1.start, p2.start prev from prod p1 left join prod p2 on p2.r = p1.rp and p2.partner = p1.partner; |
This file contains 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
-module(polish_numbers). | |
-export([generate/1]). | |
generate(N) when is_integer(N), N >= 0 -> | |
Self = self(), % spawn subprocess to avoid process dictionary pollution by put/get | |
Pid = spawn_link(fun() -> Self ! {result, self(), gen(N, 999999)} end), | |
[X || {_,X} <- receive {result, Pid, R} -> R end]. | |
gen(N, _) when N < 10 -> [{1, [N+$0]}]; |
This file contains 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 <stdlib.h> | |
#include <stdio.h> | |
#include <math.h> | |
#include <string.h> | |
typedef struct { | |
unsigned char length; | |
char op; | |
} best_rec_head; |
This file contains 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 <stdlib.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
enum { | |
max_k = 6, // it can't be bigger than 6 because it has to fit in 64 bit set | |
}; | |
typedef uint64_t set; | |
typedef unsigned char number; // 1 << max_k has to fit |
This file contains 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
-module(vertical_tree). | |
-export([draw/1, get_verical_lines/1]). | |
-record(node, { | |
value, | |
left = nil, | |
right = nil | |
}). |
This file contains 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
%% Fibonacci number generator in Erlang | |
%% by Hynek Vychodil <[email protected]> 3-JAN-2014 | |
%% Distributed under MIT license at the end of the source code. | |
-module(fib). | |
-export([fib/1]). | |
% NOTE: Native compilation (HiPE) doesn't improve efficiency due heavy integer | |
% bignum computations as observed in R16 |
This file contains 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 <stdlib.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
// fast int | |
#if __WORDSIZE == 64 | |
typedef unsigned long int uint_fast_t; | |
#define UINT_FAST(c) c ## UL | |
#else | |
typedef unsigned int uint_fast_t; |
OlderNewer