Advents of Code (programming challenges)
|
12-24-2022, 10:02 AM
Post: #21
|
|||
|
|||
RE: Advents of Code (programming challenges)
(12-19-2022 03:37 PM)pier4r Wrote: I was also intrigued by Plus42, although I am not sure that the formula language allows programming (if I understood, it should be more of a super solver like the HP 17B ). The Plus42 formula language offers a few features that make it significantly more flexible than the one in the 17B/19B/27S upon which it is based: FOR, SEQ, and the ability of functions to call other functions. That said, I'm not going to recommend using the Plus42 equation language as a general-purpose programming language. It may be interesting to see how far it can be pushed, but that's another story! |
|||
12-24-2022, 11:01 AM
(This post was last modified: 12-24-2022 11:08 AM by pier4r.)
Post: #22
|
|||
|
|||
RE: Advents of Code (programming challenges)
Thank you Thomas.
"and the ability of functions to call other functions." Do you mean functions defined with the equation editor or functions built in the calc (thus those in free42). Or both ? Is there an example of function call somewhere? Wikis are great, Contribute :) |
|||
12-24-2022, 11:30 AM
Post: #23
|
|||
|
|||
RE: Advents of Code (programming challenges)
There are no examples on my web site, but the functionality is documented near the end of the section "Functions", under https://thomasokken.com/plus42/#equations.
An example of a named function calling itself could be FAC(N):IF(N<=1:1:N*FAC(N-1)) The same syntax can be used for calling one function from another. |
|||
12-24-2022, 07:14 PM
(This post was last modified: 12-24-2022 07:24 PM by pier4r.)
Post: #24
|
|||
|
|||
RE: Advents of Code (programming challenges)
So far the code for Day14 (no part is complete, that is simply for the input) is the following:
Code:
With the large input it says "out of memory" and this annoys me to no end. Not because the input is too large, or better it can be said so, but then there could be always another system with less memory, for example the casio 9860 GD has 61kb of memory if I am not wrong, in comparison the 50g has plenty. The real reason is that the 50g has plenty of storage. First there is the ERAM that has those 128kb extra that cannot be really addressed. I know it is a limitation of the emulated OS, but still is super annoying, because the ram is there. Second one could make a sort of "paging", for example making a list that contains part of the larger data structures (including overlapping and metadata) that get swapped in and out to ERAM or Flash storage ( unfortunately emu48 cannot simulate a SD card and thus it would be difficult to emulate paging there using SDfiler ). Anyway such swapping function would take quite a while as well and I instead would like to proceed with the problem. In other words, would it be a system like the 48G Series, with a maximum of 128kb of ram, I would accept it without being annoyed, but with the 50g one could do more but the system makes it complicated. Really a bummer. It could well be that there are approaches that are less memory intensive (my solutions are rarely optimal), yet I still think that the calculator could support even my solutions, had the ERAM be shared with the user. It is a pity because I really enjoyed trying to use functions that normally I barely used in the past, like manipulating strings, matrices and complex numbers. The matrix I am using to map the "state" of the system uses 102k of ram. If I would do only stackrobatics I think I could squeeze it in (otherwise it needs to be in memory AND reported on the stack). Only I don't enjoy stackrobatics. Wikis are great, Contribute :) |
|||
12-25-2022, 09:19 AM
(This post was last modified: 12-25-2022 09:19 AM by pier4r.)
Post: #25
|
|||
|
|||
RE: Advents of Code (programming challenges)
I was able to proceed further. I simply tried to save on port 1 (that is still ram) the largest variables I could identify.
I am unsure whether it really helped, as I think the variable is still pushed to the stack if needed, but maybe having the values on the stack and in a variable (local or global) is too much. I thought that the same value would be referenced instead of being there twice, but actually it seems there twice or something similar, as otherwise the port0 free space would have been enough. Thus I can get the map state in a large matrix (102k), now I need to actually solve part1 and 2 (of Day 14). Code:
Wikis are great, Contribute :) |
|||
12-26-2022, 04:52 PM
Post: #26
|
|||
|
|||
RE: Advents of Code (programming challenges)
(12-25-2022 09:19 AM)pier4r Wrote: Thus I can get the map state in a large matrix (102k), now I need to actually solve part1 and 2 (of Day 14). I haven't yet started on day 14, but as a result of your posts I took a look at it to see how I might approach it. The Input Data Whenever I see x-y pairs in these problems, I think about storing the input data as complex numbers. As long as the numbers aren't primarily single-digit figures, the internal representation of complex numbers will usually save space over a list of 2 reals. The number of pairs for each line varies, so to reduce the storage footprint I'd make each input line a sublist. They only need to be accessed in a sequential manner at the beginning when the map is being populated, so that would be a good candidate. Given the above considerations, I'd start out by storing the input data as a "list of sublists" with the innermost sublists having complex numbers as the elements. If that ended up being too large, I'd consider having real/approximate numbers as the innermost elements, coded as XXXX.YYYY to "compress" the data. I don't think it's needed in this case, but that would be the fallback plan. The Map Data This is where things get more interesting. I would guess that the author intentionally chose to use x-y values in certain ranges to deliberately force participants to have to go through a translation step. You could create an array of "0..maxX+1, 0..maxY+1", but that would allocate a lot of space that would never be used (at least with the data they provided when I acquired it). That might simply be "annoyingly wasteful" on a computer that has lots of memory, but on a 50g that becomes severly limiting or potentially impossible depending on the actual max values. By setting up the map with the top left corner as (minX-1, minY-1) and the bottom right corner as (maxX+1, maxY+1), you can significantly reduce the memory footprint needed. I may actually take this a step further by storing the map as a string instead of an array. There's a limited range of values needed for each element of the map, and a string could easily accommodate them. So the map cell addresses would need two separate translations: once at the beginning of the program when the map is populated with rock structures, and then a conversion of x-y values to string offsets while processing the falling sand. A pain, perhaps, but converting the cell indices to a single offset is pretty easy. Of course, I could change my mind entirely by the time I get to that problem. But that's what strikes me as a potential method that I would pursue for that one. |
|||
12-26-2022, 07:46 PM
Post: #27
|
|||
|
|||
RE: Advents of Code (programming challenges)
Thank you, and in fact I did it.
The input was stored as array of complex numbers. Why an array? Because it is quick to populate/edit compared to a long list (this is something I want to exploit in an "array processing" thread, that then never got momentum). Especially if the dimension at first is predetermined. Thus I first allocate an array of dummy complex numbers. Then I go through the input and I say the (x,y) as complex numbers (one can see the suggestion also by the 50g AUR where complex numbers are used as x,y of a picture) Then I trim the array with the actual numbers. While I read the input, I also noticed the minX and maxX (one can see those as global values). So that I can trim the map starting from the first X that has actually rock in it. The Y instead is from 0 (actually 1) to the maxY since one does not know where the sand will accumulate (surely there will be pesky crannies). Then I go through this array and I start to build the matrix given the dimensions above. And the map is the hard part to store. As the array of input complex numbers will be discarded after building the map, is the map that has the larger weight (as far as I could see) and I couldn't keep it as global variable, because as soon as it went to the stack too, there was no space left (where I was expecting only a reference rather than a copy). Moving the storage to port 1 - while recalling it every now and then to the stack - helped. Now I need to find time to complete P1 and P2. Then let's see if day15 is doable. Another approach could be that I skip to the less difficult days first (from around the 20th) and then I go back to the hard ones. Wikis are great, Contribute :) |
|||
12-28-2022, 11:18 PM
(This post was last modified: 12-28-2022 11:22 PM by pier4r.)
Post: #28
|
|||
|
|||
RE: Advents of Code (programming challenges)
I am able to run part 1 now. It needs around 200k free on port0 and 105k free on port1 (and many hours of computing, but that is ok overnight or during the week). Nonetheless I can pass the small example but in the large input there is a bug somewhere, although examining the matrix (saved to map the state) it seems all fine. Surely I am off by a subtle quantity.
Moreover the next problems that should (!) be easy for 2022, according to the stats on the site, are: day 18 and day 25, the rest should be at least like day 14 if not worse. Wikis are great, Contribute :) |
|||
01-14-2023, 10:27 PM
Post: #29
|
|||
|
|||
RE: Advents of Code (programming challenges)
I still have to debug day 14 - my idea is: pick a program that works, execute it on my input, check the result in terms of the map (the sand falling), find the differences with the map generated on the 50g, fix my program. Somewhat time consuming.
Anyway since I was trying to solve some other things I (re)realized (as I forgot) that the 50g has something that approximates a regexp substitution, the MATCH operations. Although those apply on simbols, I am not sure whether one can freely move from strings to single quoted strings. Wikis are great, Contribute :) |
|||
01-21-2023, 09:56 AM
Post: #30
|
|||
|
|||
RE: Advents of Code (programming challenges)
I was thinking. Is there a way (in RPL) to store the compact map (without the unneeded columns) in something different than a matrix with integers or reals?
I was thinking about GROB objects or pictures, but those would be difficult to debug, as far as I know, as a pixel can either on or off. Would be great if one could create a sort of bitmap but not only with bits, rather with, say, 4 values. Wikis are great, Contribute :) |
|||
01-21-2023, 06:43 PM
(This post was last modified: 01-21-2023 06:43 PM by John Keith.)
Post: #31
|
|||
|
|||
RE: Advents of Code (programming challenges)
I can't imagine doing so in UserRPL but it would be possible in assembly language. I would guess that an array of nibbles (4 bits, 16 possible values) would be the best trade-off of size vs speed, since the Saturn-based calculators use nibble addressing.
|
|||
12-01-2023, 10:09 AM
Post: #32
|
|||
|
|||
RE: Advents of Code (programming challenges)
As Info. The new season of AoC started. I won't pick it up for a while (due to other commitments), but maybe someone wants to do it "live" so to speak.
I still have 2022 to finish (debugging in userRPL is not that quick for me) Wikis are great, Contribute :) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)