Skip to content

Instantly share code, notes, and snippets.

View locks's full-sized avatar
🌟
Ember Polaris

Ricardo Mendes locks

🌟
Ember Polaris
View GitHub Profile
@locks
locks / lv1
Created December 17, 2009 02:15
string::split c++
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
@locks
locks / Toolkit.h
Created December 19, 2009 02:56
CLIT (C++ Library Is a Toolkit)
namespace clit {
int stringToInt(string argumento) {
istringstream str(argumento);
int x;
return (str>>x) ? x : -1;
}
template <class T>
@locks
locks / README.md
Created December 27, 2009 23:15
Mergesort implementation
@locks
locks / mongo.rb
Created January 2, 2010 13:35
MongoDB experiments
require 'rubygems'
require 'mongo_mapper'
class Subject
include MongoMapper::EmbeddedDocument
key :nome, String
key :ano, Integer
end
@locks
locks / cenas.cs
Created January 12, 2010 13:46
dotNET toolbox
using System;
using System.Security.Cryptography;
using System.Text;
using System.Net.Mail;
class Toolbox {
public static String GenerateToken() {
return Guid.NewGuid().ToString();
}
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
@locks
locks / iarti_f01a01v01.pl
Created April 9, 2010 09:53
resoluções para a cadeira de iarti
frase --> sn, sv.
sn --> artigo, nome.
sn --> nome.
sv --> verbo, sn.
sv --> verbo.
artigo --> [o].
artigo --> [a].
@locks
locks / miniteste.pl
Created December 6, 2010 09:26
Prolog, miniteste 8h@06122010
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).
elimina1(N,[H|T],T) :- N == H .
elimina1(N,[H|T],[H|LB]) :- elimina1(N,T,LB) .
@locks
locks / fib.pl
Created February 3, 2011 21:49
fib.pl
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.