Skip to content

Instantly share code, notes, and snippets.

View juanplopes's full-sized avatar
🌲
Is that a Segment Tree problem?

Juan Lopes juanplopes

🌲
Is that a Segment Tree problem?
View GitHub Profile
/// <summary>
/// Devolve sempre 1.
/// </summary>
/// <returns></returns>
private Double FechaPorta()
{
Double fechaPorta = 0d;
switch (_port)
{
/// <summary>
/// Returns -1 in BalancaResponse.Peso if there was an error and the error message.
/// </summary>
/// <returns></returns>
public BalancaResponse GetWeight()
{
BalancaResponse response = new BalancaResponse();
response.Peso = -1d;
Double peso = this.AbrePorta();
if (peso == 0d)
[Test]
public void ShouldServeAsNonGenericIEqualityComparer()
{
Sample1 obj1 = new Sample1();
EqualityHelper<Sample1> helper = new EqualityHelper<Sample1>();
helper.Add(x => x.IntProp);
helper.Add(x => x.StringProp);
var hash = new Hashtable(helper);
@juanplopes
juanplopes / gist:757685
Created December 28, 2010 20:41 — forked from tucaz/gist:757678
//C#
public T FindInList<T>(IEnumerable<T> source, IEnumerable<T> target)
{
return source.First(target.Contains)
//return source.Intersect(target).First();
}
//F#
//C#
public T FindInList<T>(IEnumerable<T> source, IEnumerable<T> target)
{
return source.First(target.Contains)
}
//F#
let FindInList (source : seq<_>) (target : seq<_>) = source.First(Func<_,bool>(target.Contains))
public class Usuario
{
public class Map : ClassMap<Usuario>
{
public Map()
{
Table("tsdrusu0");
Id(x => x.Id).Column("id_usu");
Map(x => x.NmLogin).Column("nm_login");
}
public static class BitOperations
{
public static int PopCountIn(ulong value)
{
unchecked
{
const ulong mask0 = 0x0101010101010101;
const ulong mask1 = ~0ul / 3 << 1;
const ulong mask2 = ~0ul / 5;
const ulong mask3 = ~0ul / 17;
public static int HighestBitPosition(ulong value)
{
if (value == 0) return -1;
var r = 0;
foreach (var e in new [] { 32, 16, 8, 4, 2, 1 })
if (value >= 1ul << e) { value >>= e; r += e; }
return r;
static int[] index64 = new[]
{
63, 0, 58, 1, 59, 47, 53, 2,
60, 39, 48, 27, 54, 33, 42, 3,
61, 51, 37, 40, 49, 18, 28, 20,
55, 30, 34, 11, 43, 14, 22, 4,
62, 57, 46, 52, 38, 26, 32, 41,
50, 36, 17, 19, 29, 10, 13, 21,
56, 45, 25, 31, 35, 16, 9, 12,
44, 24, 15, 8, 23, 7, 6, 5
def e(h,w,r,c)
return r+c-1 if (r==1 || c==w)
return e(h,w,h-r+1,w-c+1)+h+w-2 if (r==h || c==1);
return e(h-2,w-2,r-1,c-1)+2*(h+w-2);
end
a,b=gets.split.map(&:to_i)
d=Math.log10(a*b).to_i + 1
for i in 1..a
for j in 1..b