Skip to content

Instantly share code, notes, and snippets.

import math
def isPrime(n):
for i in range(2, math.sqrt(n)):
if n % i == 0:
return False
return True
import prompt
import predicate
import random
DartThrown = prompt.for_int('Enter number of darts to throw', is_legal= predicate.is_positive)
count = 0
for i in range(DartThrown):
#print('Dart Thrown')
x = random.uniform(-1, 1)
echo 'Initializing crawler.'
crawler
while [ 1 ]; do
echo 'Boo. Crawler crashed. Restarting'
crawler
sleep 1
done
# author -- Gio Borje
import random
class GeneticProcessor(object):
def __init__(self, population_size, fitness_fn):
self.population_size = population_size
self.fitness_fn = fitness_fn
def next_gen(self, population):
@Hydrotoast
Hydrotoast / rhs.c
Created April 17, 2013 06:17
RHS Evaluation
int sum = 1;
for (int i = 0; i < 100; i++)
sum = sum + 1
return sum // returns 101
#ifndef EVENT_H
#define EVENT_H
#include "DiscreteClock.h"
#include "SimulationState.h"
#include <functional>
class EventHandler;
#ifndef BASECLASS_H
#define BASECLASS_H
#include <string>
#include <iostream>
template <class Derived>
class BaseClass
{
public:
from math import sqrt
def prob10(mass, height, radius, mom_of_inertia, friction_work):
g = 9.8
# potential energy
mgh = mass * g * height
# total work after descent
work = mgh + friction_work
# No progress
def algo1():
while turn != i:
# no-op
# crit section
turn = j
# remainder section
# No progress
def algo2():
#include <thread>
#include <mutex>
class semaphore {
public:
semaphore(unsigned int count) : count_(count) {}
void wait() {
std::lock_guard<std::mutex> lock(mutex_);
while (!count_)