Skip to content

Instantly share code, notes, and snippets.

@emadshaaban92
Last active August 29, 2015 13:56
Show Gist options
  • Save emadshaaban92/9012626 to your computer and use it in GitHub Desktop.
Save emadshaaban92/9012626 to your computer and use it in GitHub Desktop.
function is_palindrome(int number){
word = Int.to_string(number)
word == String.reverse(word)
}
function pair_with(int elem, it){
Iter.map(function(el){ (elem, el) }, it)
}
function pairs(seq){
match(seq.next()){
case {none} : { next : function () { none } }
case {some:it} : Iter.append(pair_with(it.f1, it.f2), pairs(it.f2))
}
}
before = Date.now()
nums = Iter.init(999, function(int elm){ elm - 1 }, function(int elm){ elm > 100 })
combs = pairs(nums)
products = Iter.map(function(pair) { pair.f1 * pair.f2 }, combs)
palindrome_products = Iter.filter(function(num){ is_palindrome(num) }, products)
jlog(Int.to_string(Option.get(Iter.max(palindrome_products))))
//jlog(Int.to_string(Option.get(palindrome_products.next()).f1))
after = Date.now()
duration = Duration.in_milliseconds(Duration.between(before, after))
jlog(Int.to_string(duration))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment