Skip to content

Instantly share code, notes, and snippets.

@Roshankumar350
Last active February 17, 2021 17:31
Show Gist options
  • Save Roshankumar350/d161320138c2e8c33b229e71811786a3 to your computer and use it in GitHub Desktop.
Save Roshankumar350/d161320138c2e8c33b229e71811786a3 to your computer and use it in GitHub Desktop.
Day 1 of Advent Code
func findIndexOf(targetSum sum: Int, in inputArray: [Int]) -> (Int,Int) {
//Output index
var indices: (Int,Int) = (-1, -1)
//count of input array
let inputArrayCount = inputArray.count
for (index, eachElement) in inputArray.enumerated() {
for sartIndex in index..<inputArrayCount {
if eachElement + inputArray[sartIndex] == sum {
indices.0 = index
indices.1 = sartIndex
break
} else {
continue
}
}
if indices.0 != -1 || indices.1 != -1 {
break
}
}
return indices
}
let indicess = findIndexOf(targetSum: 2020, in: inputArray)
print(inputArray[indicess.0] * inputArray[indicess.1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment