No leetcode expects answers from the usual suspects, but it is still fun to 
find an answer in J anyway.

--- Original Message ---

From: "Mike Day" <[email protected]>
Sent: July 21, 2015 5:15 PM
To: [email protected]
Subject: Re: [Jprogramming] Substring sequences of a string

I've had a look at the Leetcode site. It turns out that it doesn't
admit J/APL/K etc solutions.  I found myself "submitting" an
empty Ruby shell!  (I'd thought the submit button would open
a new page...)

Their latest problem is very easy to solve in J, namely to list the
running minimum-over-3-item-windows in a numeric vector,
but they're looking for linear-time solutions using fancy
techniques which hardly matter to J-ers,  but might impress in a
C++/C/C#/Ruby/...  job interview.

Sorry - getting away from Jprogramming as such,

M

On 21/07/2015 08:29, Mike Day wrote:
> I came up with the same as Vijay - this variant allows
> you to vary the required length of the sub-string:
>
> s =: 'AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT'
> v =: ((~.#~1<#/.~)@(<\))
>
>    4{. 5 v s
> +-----+-----+-----+-----+
> |AAAAA|AAAAC|AAACC|AACCC|
> +-----+-----+-----+-----+
>
> What's your Project Euler Moniker, Jon?  I'm "Mike", as
> here.  It's a long time since I had solved 100% of the
> problems.
>
> Cheers,
>
> Mike
>
> On 21/07/2015 05:49, Vijay Lulla wrote:
>> Using slightly less space
>>
>> (~. #~ 1 < #/.~)@(10 ]\ ]) s
>>
>> On Mon, Jul 20, 2015 at 11:59 PM, Tikkanz <[email protected]> wrote:
>>> (i.~ ~: i:~) will find duplicates so how about:
>>>
>>>      ~.@(#~ i.~ ~: i:~)@(10 ]\ ]) s
>>>
>>> AAAAACCCCC
>>>
>>> CCCCCAAAAA
>>>
>>>
>>>
>>> On Tue, Jul 21, 2015 at 3:51 PM, Jon Hough <[email protected]> wrote:
>>>
>>>> This is a problem from leetcode.com (similar to Project Euler)
>>>> https://leetcode.com/problems/repeated-dna-sequences/
>>>> The problem is to find all 10 letter repeated subsequences from a DNA
>>>> string (made of C,G,A,T characters).
>>>> My solution:
>>>> func =: (I.@:(1&<)@:>@:(1&{)@:(~. ,: <"0@:(#/.~)) {
>>>> ])@:(<"1@:(10&(]\)))
>>>> e.g. s =: 'AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT' NB. see the link for this
>>>> definition
>>>> func s
>>>> ┌──────────┬──────────┐
>>>>
>>>> │AAAAACCCCC│CCCCCAAAAA│
>>>>
>>>> └──────────┴──────────┘
>>>>
>>>>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

----------------------------------------------------------------------
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