part2 uses the pattern of starting with an initial state and going through a list of items, transforming the state at every step: ⊃f/(⌽items),⊂initial
f takes the old state as ⍵, the current item as ⍺, and returns the new state
in our case the "items" are a list of booleans indicating the presence of 1..max(a) in the input, and the "state" is the number of paths to the last 3 integers
we start with 0 0 1 because there are no paths to ¯2 and ¯1, and there is a single path to 0 (the empty path)
Welp, today was a disaster. Spent like 30 minutes on part 1 trying graph-based solutions before realizing you can just sort and look at differences. Then another 90 minutes on part 2 trying partitions/differences/all sorts of things before realizing it's probably a DP problem :|
I'm not very good at explaining things but I figured that the only possible difference in paths occur between the 3s, so by getting the length of the consecutive 1s, you can work it out
CMCrestricted-source: Implement a Select function equivalent to {(⊂⍺)⌷⍵} without using any primitive functions. E.g. (⍪'babe')≡2 1 2 5 Select ⍪'abcdef'
@rak1507 Operators, user-defined functions/operators, and various syntactic elements like assignment parentheses, control structures, guards, error guards, constants, etc.
@Adám - I'm looking at going back to cleaning up that old APL StarTrek game, now that I'm starting to have time again. As I remember, it was generating random integers by emulating the old BASIC RND() function, but not really. Dyalog's ?⍵ will return a random integer in ⍳⍵ for ⍵≠0, and a random value in the range [0,1) for ⍵=0. Do I get a "better" distribution if I use ?⍵ for ⍵≠0, or ⌊⍵×?0?
@JeffZeitlin I don't think it matters. You know you can ask the OS for random numbers, which means sharing the pool with all other applications, and therefore pretty much true randomness?
@rak1507 - Using ?⍵ was in fact my first inclination, but then I got to thinking about some of the known flaws in algorithms that generate integers, so it occurred to me to inquire.
@rak1507 Operators, user-defined functions/operators, and various syntactic elements like assignment parentheses, control structures, guards, error guards, constants, etc.
Here's something weird, a←a∘← then a 10 produces a syntax error about changing nameclass, which is expected, but then if I do a and a 10 again, it doesn't error
@FrownyFrog wrong - maybe, even though it always produces correct results. like rak1507's solution, it takes advantage of a fact about the input that wasn't mentioned in the problem description (no 2s and no long runs of 1s). i think aoc's author is to blame - either for not specifying the problem fully or for not generating good enough tests.
@rak1507 It is bug 17228 in the interpreter: When the interpreter needs to call a callback function to print something, it should create a ⎕ORed clone of the item to print and pass that, but instead it does an in-place ⎕ORing and so a side effect of printing with a callback is that the item that was printed changes from being a function to be a ⎕OR.
I saw that the only differences were 3s and 1s while doing part 1, I guess it isn't that clear but the fact that it only asks for the product of them kinda gives it away
if there weren't a requirement (or expectation) for a solution to work with other peoples' inputs, my solution for day10 would be: 101920 1511207993344 (just print the result)
@ngn specifying the input specification would just be boilerplate and duplicate information to the specification
(furthermore, this works-for-your-input-only mindset goes along with wanting everyone to make their own solution, and teaches to exploit unnamed properties)
for instance, i know that in project euler any problem can be solved with ints that fit in 64 bits (except, of course, explicitly bigint problems). they wrote that down once, pertaining to all problems, so you don't have to worry about overflows.
@ngn each problem would have a separate reasonable input size limit. Sure, you could say a general maximum of, say, 1mb, but having to write that down somewhere is just stupid
@ngn project euler often includes "random" numbers, specifying some single input or a bound. If you don't consider those inputs to the same level as AOC, you'll end up allowing a PE solution to be just outputting the constant answer, or need to care about those numbers being >1e100
@dzaima you're making it sound like i'm alone in this. have you looked at the forums after you solve a PE problem? people usually post reasonable, parameterized solutions, not just print(answer)
@ngn what people post is how they got to the answer, that it involves code with some parameterization is a side-effect of how the problems are written. If you got to it by just writing a string of digits inside a print statement, thinking of them quickly enough for there to be no need to explain how you arrived at it, that's a valid "solution"
sure, mkst's and rak1507's solutions aren't universal solutions, but they are the way how they arrived at a solution for their specific problem
@dzaima ok, i'll try to say it in a different way. in PE everybody has the same input and gets the same output. so if someone's hacky solution miraculously worked, it will work for everyone. this is not true for aoc.
@dzaima "problem" makes that seem weird, "task" may be better
when solving an AOC, you have one task - get an answer, optionally posting how you got it afterwards. Nothing in that specifies anything about the input not being part of the problem statement, any possibility of any other inputs, or even that there are others solving it. Anything other is something you decided to do (even if many others did too), so can't really blame anyone but yourself (or others you're copying)
@ngn the solution might not work for everyone because the task it solves is different, but the goal of showing how you got your answer is completed nonetheless
@dzaima also, i'd blame the author of the problem for not narrowing down the set of valid inputs, rather than the solvers who took advantage of random observations in order to get to the answer sooner
@Razetime i don't really care, it's not the end of the world. it just might be a wrong solution.
@ngn I mean, you can blame the author for many, many things - posting at an inaccessible time, writing in only english, not being more suited for $programming_language, encouraging doing $thing_you_dont_like_doing, having a dark-themed site, having the option to show your score to others, having the option to not show your score to others, and many more things.
@dzaima thing is, none of those were the goals of AOC. The goal is to give a fun task, and that's achieved
@dzaima i would argue it's more important, it has direct impact on how you solve the challenge.
about other things: english is an obvious choice. the timing would be inconvenient for someone, no matter which hour you choose. problems so far have been language-agnostic
if this was the acm icpc i would be furious because of the underspecified input
@ngn and input format description & restrictions being in the problem text would waste everyone's time reading something that they absolutely don't care about while doing the single goal of aoc - solve the task
@ngn and that is acceptable, because that actually harms achieving the intended goal. Whereas for AOC the only thing you have to do is get an answer for a specific, known, input
if you want to achieve something unintended (get a solution that guaranteed works for everyone), you're to blame if that is hard. Same if I wanted to solve acm icpc by doing it on pen&paper - I'd definitely be furious about the number of calculations I'd have to do
@ngn tl;dr: aoc isn't acm icpc; if you want it to be, then look elsewhere
This is unrelated, but how do you change the prefix/meta key to something like CapsLock (which doesn't have a character representation) instead of a backtick in RIDE?
Run KeyTweak (you can search for it, available from lots of sources) and click CapsLock (key 30). Under "Keyboard Controls", "Choose New Remapping": "Right Alt".
@dzaima trying to, but nothing seems to work (only ever getting first reply message, and starting with RIDE_INIT=HTTP:127.0.0.1:8000 instead of CONNECT makes dyalog segfault when my app is closed (with no responses anyways))
@Adám the grapher just stores a reference to a function object to invoke for getting info. Kind of impossible to store a reference through JSON
@dzaima though i guess i could make a special DyalogFun extends Fun and have some manual pseudo-references (and something similar for arrays). at which point even interop between APL and BQN becomes possible and it would be quite fun to have a single app for Dyalog, dzaima/APL, and dzaima/BQN