Skip to content

Instantly share code, notes, and snippets.

View thearn's full-sized avatar

Tristan Hearn thearn

  • NASA Glenn Research Center
  • Cleveland, OH
View GitHub Profile

The Project Euler Sprint Hack Nights

Project Euler Sprint Hack Nights are beginner friendly events where you can work on your own projects or engage in a friendly competition called the Project Euler Sprint.

The Project Euler Sprint is a friendly competition involving solving Project Euler ([http://projecteuler.net][projecteuler]) problems for points. Project Euler is a series of increasingly difficult computational math problems that must be solved with code (generally speaking - we've had some impressive solutions in pen and paper as well as on an Excel spreadsheet).

Each problem is harder than the last, so each problem is worth its problem number in points. Problem #1 is easy, so it's worth 1 point, while problem #50 is much harder, but worth 50 points. You can form teams of 4 people and solutions can be in any language as long as it's coded there. More detailed rules below.

Sprint Rules

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thearn
thearn / fft_analysis.py
Last active August 29, 2015 13:58
FFT basics
import numpy as np
import pylab
# make some random data
x = np.random.randn(15)
# get length of data
n = len(x)
# compute PSD (square of the abs of the fft values)
from openmdao.main.api import Component
from openmdao.lib.datatypes.api import Float
import numpy as np
from itertools import combinations
class ActuatorDisc(Component):
"""Simple wind turbine model based on actuator disc theory"""
# inputs
from openmdao.main.api import Component
from openmdao.lib.datatypes.api import Float, Array, Str
from rk4 import RK4
import numpy as np
import pylab
# http://www.math.psu.edu/tseng/class/Math251/Notes-Predator-Prey.pdf
@thearn
thearn / array_squared_error.py
Created January 24, 2015 16:18
Array Squared Error Component
from openmdao.main.api import Component
from openmdao.main.datatypes.api import Float, Array
import numpy as np
class ArraySquaredError(Component):
"""
Computes the square of the norm of the distance (error) between two
n-dimensional arrays "current" and "target", with analytic derivatives.
Meant for use in models which seek to minimize the distance/error between
@thearn
thearn / ks.py
Created January 24, 2015 16:19
KS Component
import numpy as np
from openmdao.main.api import Component, Assembly, set_as_top
from openmdao.lib.datatypes.api import Float, Array
class KSComponent(Component):
"""
Aggregates a number of functions to a single value via the
Kreisselmeier-Steinhauser Function. Often used in the aggregation of
def doctor(self):
print "-- OpenMDAO Doctor --"
print 30*"-"
uncon_inputs = self.get_unconnected_inputs()
n_uncon = len(uncon_inputs)
if n_uncon > 0:
print "- Assembly contains %i unconnected inputs:" % n_uncon
for name in uncon_inputs:
print " " + name
@thearn
thearn / run.py
Created March 11, 2015 17:48
simple complicated component
from openmdao.main.api import Component, Assembly
from openmdao.main.datatypes.api import Float
from pyoptsparse_driver.pyoptsparse_driver import pyOptSparseDriver
from pyopt_driver import pyopt_driver
from simple import SimpleComp, SimpleCompNoDeriv
import time
class parallel(Assembly):
def configure(self):
@thearn
thearn / flexglove
Created April 11, 2015 22:21
Energy gauntlet
int flexSensorPin_0 = A0; //analog pin for flex sensor
int flexSensorPin_1 = A4; //analog pin for flex sensor
int hand = 0;
int x_pin = A2;
int y_pin = A3;
int z_pin = A6;
int accelSrc = 3;