Author Topic: Advent of Code  (Read 111523 times)

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #225 on: 08 December, 2016, 09:11:21 am »
Array index munging today. With a bit of input parsing thrown in.
"By creating we think. By living we learn" - Patrick Geddes

Oaky

  • ACME Fire Safety Officer
  • Audax Club Mid-Essex
    • MEMWNS Map
Re: Advent of Code
« Reply #226 on: 08 December, 2016, 12:13:24 pm »
There is some pretty rank coding on display there..

It is deliberately perverse,  this guy has form for it.  I believe it was the same person who posted a solution for one day of last years AoC using a Synacor challenge VM.
You are in a maze of twisty flat droves, all alike.

85.4 miles from Marsh Gibbon

Audax Club Mid-Essex Fire Safety Officer
http://acme.bike

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #227 on: 08 December, 2016, 04:04:54 pm »
I wasn't talking about the sheer brutality of the explicit regexs but some of the other code snippets that get posted.
"By creating we think. By living we learn" - Patrick Geddes

red marley

Re: Advent of Code
« Reply #228 on: 08 December, 2016, 04:55:49 pm »
One of the things I like about AoC is that it works with multiple levels of coding skill and experience and on multiple levels. I can use it with my first year computing students as well as get experienced computer science academic colleagues interested. Some solutions can be created with spreadsheets and even on paper, while others benefit from highly specialised languages. Inevitably there will be some pretty clumsy attempts being shared - but again, this is one of the rewarding educational aspects of the challenge, seeing how not to approach a problem as well as what works.

Oaky

  • ACME Fire Safety Officer
  • Audax Club Mid-Essex
    • MEMWNS Map
Re: Advent of Code
« Reply #229 on: 08 December, 2016, 05:59:26 pm »
I wasn't talking about the sheer brutality of the explicit regexs but some of the other code snippets that get posted.

Ahhh,  I understand now.

I saw one solution posted in which I could see a clear bug (that I knew to be a bug because I initially did the same myself, but it was smoked out of my code by the unit tests I'd written).  The author was fessing up to that bug (and another one) which individually would have got him the wrong answer, but coincidentally conspired to cancel out.
You are in a maze of twisty flat droves, all alike.

85.4 miles from Marsh Gibbon

Audax Club Mid-Essex Fire Safety Officer
http://acme.bike

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #230 on: 09 December, 2016, 08:05:10 am »
Ah, definitely a step up. Part one done - straightforward once I remembered to
(click to show/hide)

Part 2 is readily tractable but just need to think a little bit further.
"By creating we think. By living we learn" - Patrick Geddes

Re: Advent of Code
« Reply #231 on: 09 December, 2016, 08:09:15 am »
My computer is busted, trying to solve them on a phone would be a challenge too far. I'll have to catch up at the weekend   
Quote from: tiermat
that's not science, it's semantics.

red marley

Re: Advent of Code
« Reply #232 on: 09 December, 2016, 09:02:00 am »
Day 9 (decompression)

(click to show/hide)

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #233 on: 09 December, 2016, 09:25:58 am »
Day 9 (decompression)

(click to show/hide)
"By creating we think. By living we learn" - Patrick Geddes

Re: Advent of Code
« Reply #234 on: 09 December, 2016, 09:49:07 am »
My computer is busted, trying to solve them on a phone would be a challenge too far. I'll have to catch up at the weekend

;D  I made the mistake of starting one on the phone because it looked pretty easy.  I did succeed, but it was quite painful.

red marley

Re: Advent of Code
« Reply #235 on: 09 December, 2016, 11:07:29 am »
I fail to see how an infinite length string could be produced from finite input with that decompression method.

(click to show/hide)

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #236 on: 09 December, 2016, 11:32:24 am »
I fail to see how an infinite length string could be produced from finite input with that decompression method.

(click to show/hide)

OK, I see where you are going with that but you are wrong. given that a compressed string must be formed from an uncompressed string, and given the uncompressed string is [A-Z]+ the compressed string given in your example will never occur. I admit that an invalid string can break the algorithm, but a simple check that all processing instructions are complete (ie contain N characters after the instruction where the instruction is (NxY)) should suffice.
"By creating we think. By living we learn" - Patrick Geddes

red marley

Re: Advent of Code
« Reply #237 on: 09 December, 2016, 11:49:30 am »
I would agree if Eric Wastl was generating the potentially tens of thousands of compressed files used by this challenge by applying the compression algorithm to multi-gigabyte originals, that would be all you need to guarantee a 'good' compression sequence. But clearly, the scale of this means he will have been generating the compressed strings directly and algorithmically, and that was my point about his input generating challenge being a significant one.

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #238 on: 09 December, 2016, 12:06:00 pm »
But all you need to do is generate a string of valid commands from other valid commands. it is straightforward. You don't need to start with the uncompressed file.

"By creating we think. By living we learn" - Patrick Geddes

red marley

Re: Advent of Code
« Reply #239 on: 09 December, 2016, 12:17:42 pm »
I'm probably digging myself into a hole here by failing to understand the elegance of your suggested approach to input generation, but :

(5x2)ADVENT generates a valid (finite) uncompressed sequence. And (5xn) is in principle a valid compression command, where n is any integer. But (5xn) applied to that valid sequence renders it invalid. What would be a simple way of detecting such invalid modifications (other than the trivial case of always inserting a non-compression sequence of at least 5 characters after a compression command)?

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #240 on: 09 December, 2016, 01:24:30 pm »
You ensure that n is len(what follows the command) or greater.

So (5xn)ADVENT is fine but as (5xn)ADVENT is of length 10, the smallest thing that can be included is (10xn)(5xn)ADVENT. Anything less is invalid

So to generate the input you cna basically reverse the grammar definition


text := [Expansion]?[text][text]?

Expansion :=  (Zxlen{following text}) where Y is the length of the following [text] and Z >1

buildtext :
    text = null
    loop until break:
         text = text + random select:
             (random integer x length of)buildtext
             character in [A-Z]
            break
    return text

so text=buildtext will give you, for suitable random parameterisation, a valid compressed string.



  • for given models of random
"By creating we think. By living we learn" - Patrick Geddes

red marley

Re: Advent of Code
« Reply #241 on: 10 December, 2016, 07:39:01 am »
^---- Nice. (I think, but I've become distracted by the day 10 challenge)

red marley

Re: Advent of Code
« Reply #242 on: 10 December, 2016, 07:52:57 am »
Day 10 (bot dancing)

The challenges are getting more interesting, and finally varying a little more from the pattern matching that has dominated the first week or so. With the possible exception of the first day, I think the difficulty curve over time is better than last year as it feels more of a steady increase in effort.

As for today...
(click to show/hide)

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #243 on: 10 December, 2016, 09:49:03 am »
(click to show/hide)
"By creating we think. By living we learn" - Patrick Geddes

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #244 on: 11 December, 2016, 12:26:06 am »
And a dotified version of the solution to today's

dotfile by David Martin, on Flickr
"By creating we think. By living we learn" - Patrick Geddes

Re: Advent of Code
« Reply #245 on: 11 December, 2016, 08:14:49 am »
Is the order of applications of the bot rules important?

I got the first part, once some of the chips end up at outputs, I've got 14 bots, each holding one chip, and nothing further happens.

Any suggestions?
Quote from: Kim
Paging Diver300.  Diver300 to the GSM Trimphone, please...

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #246 on: 11 December, 2016, 08:36:57 am »
Yes, you have to give the bots the inputs and they only transfer when they have both chips to compare. The graph is acyclic.

(click to show/hide)
"By creating we think. By living we learn" - Patrick Geddes

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #247 on: 11 December, 2016, 08:41:46 am »

The first proper hard one today.
(click to show/hide)
"By creating we think. By living we learn" - Patrick Geddes

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #248 on: 11 December, 2016, 02:38:07 pm »
There is a recursion depth issue. Still bruteforcing it. There may be a way to optimise the strategy but I haven't worked out how to do that yet. This is taking some time. maybe I should set a search order based on energy minimisation?

ETA: Part 1 done. Part 2 adds substantially and my approach may not be suitable. There has to be a smarter way of doing this but I don't see it.

As a measure of difficulty I should plot my leaderboard position against time. It might be quicker to do a binary search of the final answer, waiting a minute between each input than to calculate the answer using my 'crawl the whole net' approach.

ETA:
There is a smarter way.
(click to show/hide)

However, it still looks like a binary search on the correct answer is quicker than brute forcing it.
"By creating we think. By living we learn" - Patrick Geddes

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #249 on: 11 December, 2016, 04:58:27 pm »
Brute force mostly won the day. Got to a position that was a maximum of 6 off but wasn't sure if it was optimal. It wasn't. Iterated back through the odd numbers till I got the right one. There is a one then five then ten minute delay between answer submissions..
"By creating we think. By living we learn" - Patrick Geddes