Created
December 7, 2018 19:05
-
-
Save wshearn/6f5217e59eb8646a3489e5e84cf97bf6 to your computer and use it in GitHub Desktop.
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 haxe.Timer; | |
import sys.io.File; | |
class Main { | |
static var charDiff:Int = 32; | |
static function removeFromAray(array:Array<String>) { | |
var endCheck = array.length - 1; | |
for (x in 0...endCheck) { | |
if (array.length <= x) { | |
break; | |
} | |
var currentChar = array[x].charCodeAt(0); | |
var nextChar = array[x+1].charCodeAt(0); | |
if (currentChar == (nextChar - charDiff) || | |
currentChar == (nextChar + charDiff)) { | |
array.splice(x, 2); | |
return array; | |
} | |
} | |
return null; | |
} | |
static function main() { | |
var stamp = Timer.stamp(); | |
var data = File.getContent("input").split(''); | |
data.remove(""); | |
var changed:Bool = false; | |
var partOne:Int = 0; | |
while (true) { | |
changed = false; | |
var newArray = removeFromAray(data); | |
if (newArray != null) { | |
data = newArray; | |
changed = true; | |
} | |
if (!changed) { | |
break; | |
} | |
} | |
partOne = data.length; | |
var stopStamp = Timer.stamp(); | |
trace("Part 1 Result: " + partOne); | |
trace("Part 2 Result: " + ); | |
trace("Time in seconds it took to run: " + (stopStamp-stamp)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment