O'Halloran numbers: Difference between revisions

Add Swift implementation
(Add Kotlin implementation)
(Add Swift implementation)
Line 1,265:
}
}
</syntaxhighlight>
{{out}}
<pre>
Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:
8 12 20 36 44 60 84 116 140 156 204 260 380 420 660 924
</pre>
 
=={{header|Swift}}==
{{trans|Scala}}
<syntaxhighlight lang="Swift">
import Foundation
 
func main() {
let maximumArea = 1_000
let halfMaximumArea = maximumArea / 2
 
var ohalloranNumbers = Array(repeating: true, count: halfMaximumArea)
 
for length in 1..<maximumArea {
for width in 1..<halfMaximumArea {
for height in 1..<halfMaximumArea {
let halfArea = length * width + length * height + width * height
if halfArea < halfMaximumArea {
ohalloranNumbers[halfArea] = false
}
}
}
}
 
print("Values larger than 6 and less than 1,000 which cannot be the surface area of a cuboid:")
for i in 3..<halfMaximumArea where ohalloranNumbers[i] {
print(i * 2, terminator: " ")
}
print()
}
 
// Running the main function
main()
</syntaxhighlight>
{{out}}
338

edits