start new:
tmux
start new with session name:
tmux new -s myname
/// @file segmented_sieve.cpp | |
/// @author Kim Walisch, <[email protected]> | |
/// @brief This is a simple implementation of the segmented sieve of | |
/// Eratosthenes with a few optimizations. It generates the | |
/// primes below 10^9 in 0.9 seconds (single-threaded) on an | |
/// Intel Core i7-4770 CPU (3.4 GHz) from 2013. | |
/// @license Public domain. | |
#include <iostream> | |
#include <algorithm> |
(ns primes.core | |
(:use clojure.test) | |
(:require [clojure.math.numeric-tower :as math])) | |
;; Problem statement: | |
;; You are given a function ‘secret()’ that accepts a single integer parameter | |
;; and returns an integer. In your favorite programming language, write a | |
;; program that determines if this function is an additive function | |
;; [ secret(x+y) = secret(x) + secret(y) ] for all prime numbers under 100. |
# Sieve of Eratosthenes, docstrings coming in Julia 0.4 | |
function es(n::Int64) # accepts one 64 bit integer argument | |
isprime = ones(Bool, n) # n-element vector of true-s | |
isprime[1] = false # 1 is not a prime | |
for i in 2:int64(sqrt(n)) # loop integers from 2 to sqrt(n), explicit conversion to integer | |
if isprime[i] # conditional evaluation | |
for j in (i*i):i:n # sequence from i^2 to n with step i | |
isprime[j] = false # j is divisible by i | |
end | |
end |
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
## Algoritmos de caminos más cortos | |
from estructuras import Cola, ColaMin | |
from conectividad import ordenamiento_topologico | |
inf = float('inf') #Tratar infinito como un numero | |
def recorrido_a_lo_ancho(G, s): | |
dist, padre = {v:inf for v in G}, {v:v for v in G} | |
dist[s] = 0 |
function squareroot(x) | |
it = x | |
while abs(it*it - x) > 1e-13 | |
it = it - (it*it-x)/(2it) | |
end | |
return it | |
end | |
function time_sqrt(x) | |
const num_iter = 100000 |
import socket | |
import fcntl | |
import struct | |
def getHwAddr(ifname): | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15])) | |
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1] |
# ---- @sexpr: S-expression to AST conversion ---- | |
is_expr(ex, head::Symbol) = (isa(ex, Expr) && (ex.head == head)) | |
is_expr(ex, head::Symbol, n::Int) = is_expr(ex, head) && length(ex.args) == n | |
macro sexpr(ex) | |
esc(sexpr_to_expr(ex)) | |
end | |
sexpr_to_expr(ex) = expr(:quote, ex) |
#usr/bin/python | |
#coding: utf-8 | |
#Cdt.py | |
from math import * | |
#resolveremos una ecuacion cuadratica de la forma ax^2+bx+c=0 | |
class Cdt(object): | |
def __init__(self, cc, cx, ti): #cc=a, cx=b y ti=c | |
self.a1=cc |