Closed FrankKair closed 6 years ago
Simple iteration filtering double base palindromes.
(1..limit).select { |x| x.double_base_palindrome }.sum
Crystal and Swift use patten matching (case/when, switch/case respectively) to decide which base palindrome to call. Go and Lua use a an if statement.
Crystal
Swift
Go
Lua
Crystal and Swift compose a range with select/filter and sum/reduce. Go and Lua use a for loop with an if statement.
Real time: 1.942 s User time: 2.288 s Sys. time: 0.237 s CPU share: 130.07 %
Real time: 0.460 s User time: 0.225 s Sys. time: 0.104 s CPU share: 71.69 %
Real time: 0.826 s User time: 0.810 s Sys. time: 0.006 s CPU share: 98.73 %
Real time: 4.753 s User time: 3.865 s Sys. time: 0.139 s CPU share: 84.24 %
How the solution works
Simple iteration filtering double base palindromes.
Crystal
andSwift
use patten matching (case/when, switch/case respectively) to decide which base palindrome to call.Go
andLua
use a an if statement.Crystal
andSwift
compose a range with select/filter and sum/reduce.Go
andLua
use a for loop with an if statement.Performance
Crystal
Go
Lua
Swift