Fine.
I've just spent a little time solving part 2, using a slight tweak to
my verb for part 1.
I did use recursion, having said it wasn't necessary earlier (!) before
I realised part 2 existed.
My part 1 runs in under a millisecond using about 35kb, while part 2
takes about 40 ms in
about 70 kb.
Mike
On 11/12/2016 00:00, Brian Schott wrote:
[Mike, Sorry to break into your thread, but the Subject and some content
makes it seem appropriate.]
Pascal,
I have been viewing you solution at the following link. I am intrigued by
your use of the conjunction R (RB also). It looks like you are using the m
and n arguments of the conjunction as if you would use x and y for a dyadic
verb and do not use any x and y for the conjunction.
I am not familiar with using only the m and n, but still doing math with
them. So my first question is, am I right, so far?
My second question is, why are you using a conjunction and not a verb? I
want to know if it's more than just a personal preference, or is a verb
processed at the wrong time in J's execution, but a conjunction is more
adaptable? Or something like that.
http://adventofcode.com/2016/day/9
On Sat, Dec 10, 2016 at 1:19 PM, 'Mike Day' via Programming <
[email protected]> wrote:
[snip]
On 10/12/2016 16:47, 'Pascal Jasmin' via Programming wrote:
posted a slightly different solution on wiki, but the original did get
correct answer, even though it took too long. An assumption that turns out
to be correct to speed it up is that expanding a "substring" expands within
the confines of that substring. The assumption is sensible if the input is
in fact the result of a compression routine. With this assumption, you can
recurse on just the substring to be expanded without expanding it (major
slowdown in original code) and then just multiply the result by the number
of repeated expansions. Very similar to original posted code. both parts 1
and 2.
p1 =: 4 : 0
o =. ''
while. (# y) > e =. ')' i.~ y do.
b =. '(' i:~ e {. y
i =. ". every 'x' cut y{~ b + >:i. <:e -b
o =. o , ',' , (": b) , ', ' , (": {: i) , (x {:: ' R '; ' RB ') , quote
({.i) {. (>:e )}. y
y =. ({.i) }. (>:e) }. y
end.
o , ',' , ": # y
)
R =: 2 : ' m * # n'
RB =: 2 : ' m * (1 +/@:".@:}.@:p1 n)'
echo +/ ". }. 0 p1 LF -.~ a NB. part1
echo +/ ". }. 1 p1 LF -.~ a NB. part2
----------------------------------------------------------------------
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