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
// MIT License | |
// Swift that converts a string note (eg. "A4") to a frequency (eg. 440.0). | |
// Inspired by https://gist.github.com/stuartmemo/3766449 | |
static func noteToFrequency (note: String) -> Double { | |
let notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"] | |
let octave = Double(String(note.last!))! | |
var keyNumber = Double(notes.firstIndex(of: String(note.dropLast()))!) | |
if (keyNumber < 3) { | |
keyNumber += octave * 12 + 1 |
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 java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.Scanner; | |
import static java.lang.System.out; // allow use of out.println() without System | |
public class ProblemName { | |
// CHANGE FILE NAME FOR EACH PROBLEM! | |
private static final String inputFileName = "filename00.dat"; | |
private static Scanner scan; |