Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TEST
- creation
- make
- feature
- make is
- local
- first : INTEGER
- second : INTEGER
- product : INTEGER
- highest : INTEGER
- do
- highest:=0
- from
- first:=100
- until
- first>=999
- loop
- from
- second:=990
- until
- second<=109
- loop
- product:=first*second;
- if (ispalindrome(product) and product>highest) then
- highest:=product;
- end
- second:=second-11;
- end
- first:=first+1
- end
- print("The largest palindromic product of two 3digit numbers is: ")
- io.put_integer(highest)
- end
- ispalindrome(x:INTEGER):BOOLEAN is
- local
- forward : STRING
- reverse : STRING
- i1: INTEGER
- i2: INTEGER
- do
- forward:=x.to_string
- reverse:=x.to_string
- from
- i1 := 1
- i2 := reverse.count
- until
- i1 >= i2
- loop
- reverse.swap(i1, i2)
- i1 := i1 + 1
- i2 := i2 - 1
- end
- if forward.is_equal(reverse) then -- compare if they are the same
- Result := True
- else
- Result := False
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement