Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 1.37 KB | None | 0 0
  1.                                                                      
  2.                                                                      
  3.                                                                      
  4.                                              
  5. class TEST
  6.  
  7.     creation
  8.         make
  9.    
  10.     feature
  11.         make is
  12.             local
  13.                 first : INTEGER
  14.                 second : INTEGER
  15.                 product : INTEGER
  16.                 highest : INTEGER
  17.             do
  18.                 highest:=0
  19.                
  20.                 from
  21.                     first:=100
  22.                 until
  23.                     first>=999
  24.                 loop
  25.                         from
  26.                             second:=990
  27.                         until
  28.                             second<=109
  29.                         loop
  30.                             product:=first*second;
  31.                             if (ispalindrome(product) and product>highest) then
  32.                                 highest:=product;
  33.                             end
  34.                             second:=second-11;
  35.                         end
  36.                     first:=first+1
  37.                 end
  38.                 print("The largest palindromic product of two 3digit numbers is: ")
  39.                 io.put_integer(highest)
  40.         end
  41.        
  42.         ispalindrome(x:INTEGER):BOOLEAN is
  43.             local
  44.                 forward : STRING
  45.                 reverse : STRING
  46.                 i1: INTEGER
  47.                 i2: INTEGER
  48.             do
  49.                 forward:=x.to_string
  50.                 reverse:=x.to_string
  51.                
  52.                 from
  53.                     i1 := 1
  54.                     i2 := reverse.count
  55.                 until
  56.                     i1 >= i2
  57.                 loop
  58.                     reverse.swap(i1, i2)
  59.                     i1 := i1 + 1
  60.                     i2 := i2 - 1
  61.                 end
  62.    
  63.                 if forward.is_equal(reverse) then       -- compare if they are the same
  64.                     Result := True
  65.                 else
  66.                     Result := False
  67.                 end    
  68.         end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement