Skip to content

Instantly share code, notes, and snippets.

@lwchkg
lwchkg / main.cc
Created May 20, 2017 16:40
A Monte-Carlo based solution of Google Code Jam question "Proper Shuffle" (2014, Round 1A, Question C)
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <random>
#include <cmath>
@lwchkg
lwchkg / microbit_mario2_overworld.ts
Last active July 28, 2024 12:52
Mario 2 overworld melody for Micro:bit MakeCode. I have confirmed that the pitches of all notes are correct. Some duration of long notes may need adjustment.
const mario2Start: string[] = [
"g5:4","f#:8","f:4","d:8","b4:4","a:8","g#:4","g:12","g5","g4:18","r:6",
]
const mario2Body: string[] = [
"g5:8","c:4","e:8","g:12","c:4","e:8","g:4","b4","eb5","g","b:8","a:24","r:4",
"g5:8","bb4:4","d5:8","g:12","bb4:4","d5:8","g:4","c#","e","g","b:8","a:20","r:4",
"b:4","c6:8","b5:4","c6:8","a5:12","c6:4","b5:8","a:4","g:8","f#:4","g:8","e:12",
"c#:4","d:8","e:4","f:8","e:4","f:8","b4:12","e5:4","d:8","c:28","r:24",
"r:8","e5:16","g:12","a:8","c6:28","a5:8","g:4","e:8","c:4",
"d:8","e:4","d:8","e:4","d:8","a4:8","r:4","d5:16",
@lwchkg
lwchkg / solar_position.dart
Created January 30, 2023 22:12
Dart implementation of NOAA sunrise, sunset and solar position calculator. At this stage apparent solar elevation is not implemented.
import 'dart:math';
import 'package:timezone/timezone.dart' as tz;
enum SolarPosition { beforeSolarNoon, afterSolarNoon }
// Common elevation of the sun, in degrees.
const apparentHorizon = -0.833;
const civilTwilight = -6.0;
const nauticalTwilight = -12.0;