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
"""Prime number generation and number factorization.""" | |
import bisect, itertools, random, sys | |
_primes = [2] | |
_miller_rabin_limit = 48611 # 5000th prime | |
_miller_rabin_security = 7 | |
def modpow (a, b, c): |
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
"""Compute solutions to the diophantine Pell equation x^2-D*y^2=1.""" | |
import itertools | |
def pell (D): | |
"""Return the smallest integer set solving Pell equation | |
x^2-D*y^2=1 where x, D and y are positive integers. If there are no | |
solution (D is a square), return None. | |
>>> pell(3) |
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: hash-sets kernel locals math sequences sets ; | |
IN: acm | |
:: add ( set n -- newset ) | |
HS{ } clone :> newset | |
set members [ n [ + ] [ - ] 2bi [ newset adjoin ] bi@ ] each newset ; | |
:: least ( n -- x ) | |
HS{ 0 } 1 [ [ add n over in? ] keep swap ] [ 1 + ] until nip ; |
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
int netaccept(int fd, char *server, int *port) | |
{ | |
int cfd = 0; | |
int one = 0; | |
union { | |
struct sockaddr_in ipv4; | |
struct sockaddr_in6 ipv6; | |
} sa; | |
socklen_t len = sizeof sa; | |
int rc = 0, af; |
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
// StopWatch class | |
abstract class StopWatch { | |
def giveTime: Time | |
} | |
// Class is declared abstract as it is lacking a StopWatch which will be later injected. | |
// Note that we could have defined a default value here and thus made the class concrete. | |
abstract class FooBar { |
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 with a default value as in: | |
// runningScalaVersion getOrElse "2.8.0" | |
lazy val runningScalaVersion = { | |
val matcher = """version (\d+\.\d+\.\d+).*""".r | |
util.Properties.versionString match { | |
case matcher(vsn) => Some(vsn) | |
case _ => None | |
} | |
} |
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
// Compile with -std=gnu99 to get the proper definitions of struct addrinfo | |
#include <stdbool.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <netdb.h> | |
#include <arpa/inet.h> | |
#include <errno.h> | |
#include <netinet/in.h> |
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
class Example { | |
println("Constructing an Example object: " + this) | |
} | |
object Test extends App { | |
// Return a new object of type T when called as f[T] | |
def f[T : Manifest] = manifest[T].erasure.getConstructor().newInstance() |
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
import scala.collection.mutable.{HashMap, Map} | |
import scala.concurrent.Channel | |
import scala.concurrent.ops.spawn | |
import android.content.Context | |
import android.os.{Handler, Message} | |
object AndroidBG { | |
private val androidBGs: Map[Context, AndroidBG] = new HashMap() |
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
package cgeo.geocaching.maps; | |
import cgeo.geocaching.Settings; | |
import cgeo.geocaching.cgBase; | |
import cgeo.geocaching.cgSearch; | |
import cgeo.geocaching.geopoint.Geopoint; | |
import org.apache.commons.lang3.StringUtils; | |
import android.os.Handler; |
OlderNewer