saw a project of a friend of mine ( http://hugopeixoto.net/mergesort.xhtml ) and tried to spice up the ruby implementation
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
vector<string> split(const string& s) | |
{ | |
vector<string> ret; | |
typedef string: ize_type string_size; | |
string_size i = 0; | |
// invariant: we have processed characters [original value of i, i) | |
while (i != s.size()) { | |
// ignore leading blanks | |
// invariant: characters in range [original i, current i) are all spaces |
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
namespace clit { | |
int stringToInt(string argumento) { | |
istringstream str(argumento); | |
int x; | |
return (str>>x) ? x : -1; | |
} | |
template <class T> |
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
require 'rubygems' | |
require 'mongo_mapper' | |
class Subject | |
include MongoMapper::EmbeddedDocument | |
key :nome, String | |
key :ano, Integer | |
end |
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
using System; | |
using System.Security.Cryptography; | |
using System.Text; | |
using System.Net.Mail; | |
class Toolbox { | |
public static String GenerateToken() { | |
return Guid.NewGuid().ToString(); | |
} |
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
99.downto 1 do|x|puts (y=x.to_s+a=" bottle#{"s" if x!=1} of beer")+(b=" on the wall")+", "+y+".",x==1?"Go to the store and buy some more, 99 bottles of beer#{b}.":"Take one down and pass it around, #{x-1}#{x==2?a.gsub("s",""):a}#{b}. | |
"end |
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
frase --> sn, sv. | |
sn --> artigo, nome. | |
sn --> nome. | |
sv --> verbo, sn. | |
sv --> verbo. | |
artigo --> [o]. | |
artigo --> [a]. |
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
p(L,L1,L2) :- length(L,C), C1 is C//2, p(L,C1,L1,L2). | |
p(L,0,[],L) :- !. | |
p([H|T],N,[H|LR],L2) :- N > 0, N1 is N-1, p(T,N1,LR, L2). | |
% a) Faça a tracagem do predicado quando é chamado da seguinte maneira: ?- p([1,2,3,4,5],L1,L2). | |
% b) Diga o que este predicado faz. Sem fazer traçagem diga o resultado da seguinte chamada: ?- p([1,30,24,56,100,33,23,12],L1,L2). | |
% c) O que aconteceria se o predicado fosse chamado da seguinte maneira: ?- p([1,2,3,4,5],[1,2,3],L2). |
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
elimina1(N,[H|T],T) :- N == H . | |
elimina1(N,[H|T],[H|LB]) :- elimina1(N,T,LB) . |
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
fib(0,0). | |
fib(1,1). | |
fib(N,R) :- | |
N1 is N-1, | |
N2 is N-2, | |
fib(N1,R1), | |
fib(N2,R2), | |
R is R1+R2. |