a little faster too,

   timespacex '(-: |.)@("."0@":)"0  break2 \:~ ~. , */~ 100+i.900' 
0.0301696 3.56781e7

a disadvantage is that it returns the full list instead of empty if nothing 
found.

Robert, its kind of cheating to just assume that you will find the answer in 
specific range 

   timespacex '(-: |.)@("."0@":)"0  break2 \:~ ~. , */~ 900+i.100' 
0.00273696 1.58502e6 

this will scan all of them, but saving the creation of the whole list

 booltest=: [: -. [: *./ 0 = , NB. allows if. to return false under more cases

NB. for each item of x, create a small argument list for u
lazy =: 2 : (':';'for_i. x do. if. booltest o=. u i v y do. o return. end. 
end.')

   1 2 3 (20&<) break1 lazy * i.20 
22 (returns 2 * 11)

   (100 ([ + *) |.i.9) (-: |.)@":  break1 lazy (13 : '\:~ ~. , */~ x + y') 
i.100 
906609 

   timespacex '(100 ([ + *) |.i.9) (-: |.)@":  break1 lazy (13 : ''\:~ ~. , */~ 
x + y'') i.100' 
0.00444736 1.32493e6 



----- Original Message -----
From: Henry Rich <[email protected]>
To: [email protected]
Cc: 
Sent: Sunday, June 8, 2014 12:31:53 PM
Subject: Re: [Jprogramming] Project Euler Question 4

Tacit variant:

break2=:1 :'(": 13!:8 (15"_))^:u"u :: (LF taketo }.@(13!:12)@(''''"_) )'
    (-: |.)@("."0@":)"0 break2 \:~ ~. , */~ 100+i.900

Henry Rich

On 6/8/2014 12:05 PM, 'Pascal Jasmin' via Programming wrote:
> an optimization to short circuit on first true, while sorting them in order.
>
>   break1 =: (1 : 'for_i. y do. if. u i do. i return. end. end.')
>
>     (-: |.)@":  break1 \:~ ~. , */~ 100+i.900
> 906609
>
>     timespacex '(-: |.)@": break1 \:~ ~. , */~ 100+i.900'
> 0.0350227 3.56737e7
>     timespacex ' >./ (#~ (-: |.)@":"0) , */~ 100+i. 900'
> 0.26438 1.78811e7
>
> ----- Original Message -----
> From: Roger Hui <[email protected]>
> To: Programming forum <[email protected]>
> Cc:
> Sent: Sunday, June 8, 2014 11:10:07 AM
> Subject: Re: [Jprogramming] Project Euler Question 4
>
> Or apply the phrase to 900+i.100 instead of to 100+i.900.
>
>
>
>
>
> On Sun, Jun 8, 2014 at 8:07 AM, Roger Hui <[email protected]> wrote:
>
>> Slightly shorter if the formatted results are not converted back into
>> numbers:
>>
>>      >./ (#~ (-: |.)@("."0@":)"0) , */~ 100+i. 900
>> 906609
>>      >./ (#~ (-: |.)@":"0) , */~ 100+i. 900
>> 906609
>>
>> A different and perhaps less brutish method is to start with 6-digit
>> palindromes and see which ones have two 3-digits factors.
>>
>>
>>
>>
>> On Sun, Jun 8, 2014 at 8:00 AM, Henry Rich <[email protected]> wrote:
>>
>>> Brute force seems right for this problem.   You could write your solution
>>> as
>>>
>>>     >./ (#~ (-: |.)@("."0@":)"0) , */~ 100+i. 900
>>>
>>> Henry Rich
>>>
>>> On 6/8/2014 10:46 AM, Jon Hough wrote:
>>>
>>>> I am pretty pleased that I completed Project Euler Q4.
>>>> Question:
>>>>
>>>>
>>>> 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.
>>>>
>>>>
>>>> https://projecteuler.net/problem=4
>>>>
>>>>
>>>> My solution:
>>>>
>>>> base =. "."0 ":
>>>>
>>>> NB. Tests if y value is palindrome.
>>>> is_palindrome =. (# =)@:(=|.)@:base
>>>> NB. multiply all 3 digit nums (100 ~ 999)
>>>> mult =: (* is_palindrome"0) @ (*/)
>>>> NB. Create list of 3 digit nums.
>>>> list =. 100+ i.900
>>>>
>>>> (>./)@:, list mult list
>>>> Although I'm glad got the answer, I'm wondering if it could be made
>>>> terser, or if there is a much terser way to solve it? I went for a brute
>>>> force approach.
>>>> For comparison here is a Haskell answer I found:
>>>> maximum[a*b|a<-[100..999],b<-[a..999],reverse(show(a*b))==show(a*b)]
>>>> Regards.
>>>> ----------------------------------------------------------------------
>>>> For information about J forums see http://www.jsoftware.com/forums.htm



>>>>
>>>>    ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>
>>
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to