Skip to content

Instantly share code, notes, and snippets.

sum = 0;
for(n in 1..1000-1) {
if(n%3==0 || n%5==0)
sum += n;
}
println sum;
def primes(long upto) {
def primes=[];
// We only search primes below sqrt, as a result of algrebraic well knwon results
long max = Math.max(Math.sqrt(upto), 1L);
for(tested in 2..max) {
long maxTested = Math.sqrt(tested);
boolean isPrime = true;
for(i in primes) {
if(isPrime) {
if(i<=maxTested) {
start = System.currentTimeMillis();
numbers = 100..999;
products=[];
// Create all products
for(i in numbers) {
for(j in 100..i) {
products<<i*j;
}
}
range = 1..100;
squareSum = range.inject (0, {sum, number ->
sum+=(number*number)
});
println squareSum;
sum = range.inject (0, {sum, number ->
sum+=(number)
});
sum *=sum;
println sum-squareSum;
def array = [
"73167176531330624919225119674426574742355349194934",
"96983520312774506326239578318016984801869478851843",
"85861560789112949495459501737958331952853208805511",
"12540698747158523863050715693290963295227443043557",
"66896648950445244523161731856403098711121722383113",
"62229893423380308135336276614282806444486645238749",
"30358907296290491560440772390713810515859307960866",
"70172427121883998797908792274921901699720888093776",
"65727333001053367881220235421809751254540594752243",
def MAX = 1000;
def get(max) {
def results = [:]
for(i in 1..max) {
for(j in i..max) {
def sum = i*i+j*j;
double sqrt = Math.sqrt(sum);
if(sqrt==sqrt.round()) {
results[[i,j]]=sqrt.round();
}
def primes(long max) {
def primes=[:]; primes[2]=4;
def i=3;
while(i<max) {
def isPrime = true;
primes.each { k,v ->
if(isPrime && v<=i) {
isPrime = (i%k!=0);
}
}
Rechercher : ^h([0-9])\. (.*)$
Rempalcer : <h\1>\2</h\1>
toto
#
# Delete any existing table `wp_quotes`
#
DROP TABLE IF EXISTS `wp_quotes`;
#
# Table structure of table `wp_quotes`
require 'yaml'
#DUMP_FILE = 'extract_dump_mysql.sql'
DUMP_FILE = 'wordpress_wp_20061231_000.sql'
DUMP_EXPORT_DIR = "dump"
CATEGORIES_STORE = 'categories_files.yaml'
# La lecture du fichier a été copiée de http://pleac.sourceforge.net/pleac_ruby/fileaccess.html
# Hash associant à leurs ids les catégories, sous forme elles aussi de hash
categories = Hash.new