Project Euler : Problem 004

Project Euler problems in Oforth . Feel free to post your own code.

Project Euler : Problem 004

Postby Franck » 26 Jul 2015 10:50

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 * 99.

Find the largest palindrome made from the product of two 3-digit numbers.

Code: Select all
// Here, brute force is used
// pe004 ( -- n ) : Returns largest palindrome
: pe004
| i j |
   0 999 100 -1 step: i [
      i 100 -1 step: j [
         i j * dup asString dup reverse == ifTrue: [ max ] else: [ drop ]
         ]
      ] ;
Franck
 
Posts: 144
Joined: 29 Oct 2014 19:01

Return to Project Euler in Oforth

Who is online

Users browsing this forum: No registered users and 1 guest