Skip to content

Instantly share code, notes, and snippets.

View edmund-h's full-sized avatar

Edmund edmund-h

  • New York City, NY, US
View GitHub Profile
@edmund-h
edmund-h / HackerRankSetup.Swift
Last active May 21, 2019 15:47
Swift Setup for the HackerRank Environment
func multiLineInputSetup() {
//Use this for multiple line inputs. The problem for which I generated this had the first term in its sequence as the number of lines of input. If this isn't available, you could just build a while loop that switches on whether a string can be instantiated with readLine()
let fileName = ProcessInfo.processInfo.environment["OUTPUT_PATH"]!
FileManager.default.createFile(atPath: fileName, contents: nil, attributes: nil)
let fileHandle = FileHandle(forWritingAtPath: fileName)!
guard let s = readLine(), let count = Int(s) else { fatalError("Bad input") }
var output = ""
for _ in 1...count {
guard let s = readLine() else {continue}
@edmund-h
edmund-h / generateRandomDate.swift
Last active August 13, 2021 17:47
A function to create a random date in Swift 3
// credit to @eirnym, adapted this from their OBJC code: https://gist.github.com/eirnym/c9526a045556e4d8464b41a367843e3c
// generates a random date and time in the past, limited by daysBack (a number of days before today)
// also generates a random time to go with that date.
// original request: http://stackoverflow.com/questions/10092468/how-do-you-generate-a-random-date-in-objective-c
func generateRandomDate(daysBack: Int)-> Date?{
let day = arc4random_uniform(UInt32(daysBack))+1