FrankKair / polyglot-euler

📜 Project Euler solutions in various programming languages
MIT License
74 stars 14 forks source link

Crystal Go Lua Swift 036 #65

Closed FrankKair closed 6 years ago

FrankKair commented 6 years ago

How the solution works

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 and Swift compose a range with select/filter and sum/reduce. Go and Lua use a for loop with an if statement.

Performance

Crystal

Real time: 1.942 s
User time: 2.288 s
Sys. time: 0.237 s
CPU share: 130.07 %

Go

Real time: 0.460 s
User time: 0.225 s
Sys. time: 0.104 s
CPU share: 71.69 %

Lua

Real time: 0.826 s
User time: 0.810 s
Sys. time: 0.006 s
CPU share: 98.73 %

Swift

Real time: 4.753 s
User time: 3.865 s
Sys. time: 0.139 s
CPU share: 84.24 %