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
from scoop import futures | |
import subprocess | |
import sys | |
def runApplication(number): | |
command = "opendcp_j2k -i in/{num:06d}.tiff -o out/{num:06d}.j2c" | |
return subprocess.call(command.format(num=number), shell=True) | |
if __name__ == "__main__": | |
returnValue = list(futures.map(runApplication, range(1, 172801))) |
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(x for x in range(1000) if x % 5 == 0 or x % 3 == 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
import timeit | |
timeit.timeit( | |
"sum(x for x in range(1000) if x % 5 == 0 or x % 3 == 0)", | |
number=10000 | |
) / 10000. |
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
# Algorithm | |
from itertools import chain | |
sum(set(x for x in chain(range(5, 1000, 5), range(3, 1000, 3)))) | |
# To benchmark it | |
import timeit | |
timeit.timeit( | |
"sum(set(x for x in chain(range(5, 1000, 5), range(3, 1000, 3))))", | |
setup="from itertools import chain", | |
number=10000 |
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
#include <stdio.h> | |
unsigned int NumberIt() | |
{ | |
/* Create a persistant variable x and initialize it to 0 */ | |
static unsigned int x = 0; | |
for (x++; x < 1000; x++) { | |
if (x % 5 == 0 || x % 3 == 0) { | |
return x; | |
} |
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
#include <stdio.h> | |
unsigned int x = 0, state = 0; | |
unsigned int NumberIt() | |
{ | |
/* Create a persistant variable x and initialize it to 0 */ | |
switch (state) { | |
/* case 0: Replaced by default*/ | |
case 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
#include <stdio.h> | |
#include <x86intrin.h> | |
#define NUMBER_OF_TRIES 1000000 | |
int main() | |
{ | |
register unsigned long lResult, lLoop, i; | |
for (lLoop = 0; lLoop < NUMBER_OF_TRIES; lLoop++) { |
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
/* To compile with: gcc euler1_s6.c -nostartfiles -s -O3 -o euler1_s6 */ | |
/* How many 3, 5 and 15 are there in 999 (below 1000) */ | |
#define QTY3 ( 999 / 3 ) | |
#define QTY5 ( 999 / 5 ) | |
#define QTY15 ( 999 / 15 ) | |
/* Their sums */ | |
#define SUM3 ( 3 * ( QTY3 * (QTY3 + 1) / 2 ) ) | |
#define SUM5 ( 5 * ( QTY5 * (QTY5 + 1) / 2 ) ) | |
#define SUM15 ( 15 * ( QTY15 * (QTY15 + 1) / 2 ) ) | |
/* The answer */ |
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 time | |
import threading | |
import sched | |
import signal | |
class myAsyncSched(object): | |
"""Asynchronous scheduler""" | |
def __init__(self): | |
self.s = sched.scheduler(time.time, time.sleep) |
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
""" | |
Example of how to move randomly two servos plugged in the 5th and 6th channel | |
(slot 4 & 5) of a Pololu Micro Maestro 6. | |
This script requires pyserial. | |
""" | |
from random import randrange, uniform | |
from time import sleep | |
from struct import pack |
OlderNewer