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
sum = 0; | |
for(n in 1..1000-1) { | |
if(n%3==0 || n%5==0) | |
sum += n; | |
} | |
println sum; |
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
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) { |
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
start = System.currentTimeMillis(); | |
numbers = 100..999; | |
products=[]; | |
// Create all products | |
for(i in numbers) { | |
for(j in 100..i) { | |
products<<i*j; | |
} | |
} |
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
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; |
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
def array = [ | |
"73167176531330624919225119674426574742355349194934", | |
"96983520312774506326239578318016984801869478851843", | |
"85861560789112949495459501737958331952853208805511", | |
"12540698747158523863050715693290963295227443043557", | |
"66896648950445244523161731856403098711121722383113", | |
"62229893423380308135336276614282806444486645238749", | |
"30358907296290491560440772390713810515859307960866", | |
"70172427121883998797908792274921901699720888093776", | |
"65727333001053367881220235421809751254540594752243", |
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
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(); | |
} |
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
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); | |
} | |
} |
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
Rechercher : ^h([0-9])\. (.*)$ | |
Rempalcer : <h\1>\2</h\1> |
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
toto | |
# | |
# Delete any existing table `wp_quotes` | |
# | |
DROP TABLE IF EXISTS `wp_quotes`; | |
# | |
# Table structure of table `wp_quotes` |
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
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 |
OlderNewer