Skip to content

Instantly share code, notes, and snippets.

View gavinsykes's full-sized avatar

Gavin Sykes gavinsykes

View GitHub Profile
@gavinsykes
gavinsykes / problem_t_test.js
Created November 30, 2021 22:05
Testing script in JavaScript
import { readFileSync } from 'fs';
const expectedAnswers = JSON.parse(readFileSync('problem_1/problem_1_expected_answers.json', 'utf8'));
import { euler_1 } from './problem_1.js';
let successfulTests = 0;
const failedTests = [];
expectedAnswers.forEach((expectedAnswer) => {
console.log(`Input of ${expectedAnswer.input} should yield ${expectedAnswer.expected_answer}`);
@gavinsykes
gavinsykes / generate_answers.py
Created November 25, 2021 16:48
JSON Answer Generation Script for PE Problem 1
from json import loads, dumps
from os import path
from problem_1 import euler_1 as euler_function
def main():
with open(path.dirname(__file__) + '/problem_1_expected_answers.json','r') as expected_answers_file:
current_expected_answers_data = expected_answers_file.read()
current_expected_answers = loads(current_expected_answers_data)
expected_answers_file.close()
for i in range(41,1001):
@gavinsykes
gavinsykes / problem_1_test.py
Last active February 17, 2022 12:14
Example of a Python Project Euler testing script (commented)
from json import loads
from os import path
from problem_1 import euler_1 as euler_function
# This allows for a bit more portability, rather than changing the name of the function every time I import this file to a new problem, just run euler_function each time.
def main():
# Get the expected answers and load them into a list
with open(path.dirname(__file__) + '/problem_1_expected_answers.json','r') as expected_answers_file:
expected_answers_data = expected_answers_file.read()
expected_answers = loads(expected_answers_data)
@gavinsykes
gavinsykes / problem_1_expected_answers.json
Created November 25, 2021 15:41
Example of what an expected answers JSON file will look like
[
{"input": 1, "expected_answer": 0},
{"input": 2, "expected_answer": 0},
{"input": 3, "expected_answer": 0},
{"input": 4, "expected_answer": 3},
// And so on and so forth
]
@gavinsykes
gavinsykes / genStarPathData.js
Last active July 30, 2021 15:39
Generating SVG path data for a star in JavaScript
const genStarPathData = (points,cx,cy,radius) => {
let radii = {
outer : radius, // this will be given to us when the function is called,
inner : radius * Math.cos(2 * Math.PI / points) / Math.cos(Math.PI /points)
/*
Wait, why Math.PI instead of 360 and 180? Well I remembered this time before
putting too much work in - JavaScript works in radians, not degrees!
π radians = 180° */
};
/* Now to redo the whole methodology as we can't really have an xpoints and
@gavinsykes
gavinsykes / example_machine_specs.json
Created July 7, 2021 08:31
Example JSON returned from get_env.py
{
"os": "Darwin",
"os_release": "19.6.0",
"os_version": "Darwin Kernel Version 19.6.0: Mon Apr 12 20:57:45 PDT 2021; root:xnu-6153.141.28.1~1/RELEASE_X86_64",
"machine": "x86_64",
"processor": "i386",
"cpu_freq": 1800,
"memory": 8589934592
}
@gavinsykes
gavinsykes / get_env.py
Created July 6, 2021 16:02
Python script to get a machine's specs and output them into a JSON file
import platform
import psutil
import json
uname = platform.uname()
cpu = psutil.cpu_freq()
mem = psutil.virtual_memory()
environment = {
def fullprint(challenge,fun,arg,filepath):
import time
import csv
import platform
import psutil
import sys
timing = {}
timing['start'] = time.time()
if arg:
result = fun(arg)
@gavinsykes
gavinsykes / working_language_extensions_example.json
Created June 15, 2021 18:07
Working Languages for Project Euler Problems
[
{
"name": "C",
"type": "programming",
"extensions": [
".c",
".cats",
".h",
".idc",
".w"
@gavinsykes
gavinsykes / get_working_language_extensions.py
Created June 15, 2021 17:59
Small tool to get all the file extensions for various languages
#############################################################################
# Use the list below to determine which languages you will be working with, #
# then run this file to grab the language extensions and put them into #
# languages.json for the rest of this program to use. #
#############################################################################
#############################################################################
# Special thanks to Peter Pisarczyk and Aymen Mouelhi for their hard work #
# in putting together such comprehensive lists! #
# https://github.com/ppisarczyk #