JohnLM 27 Posted February 15 Oh my gosh. Appoligies. I thought I was in 2024 but somehow selected 2019 and didn't realize it !!! 1 Share this post Link to post
corneliusdavid 227 Posted February 15 LOL! No worries. Now it makes sense. I found Day 10 of 2024 to be fairly simple. It's one of the few I actually completed both parts 1 and 2. I haven't had time to finish 2024 nor look at any prior years. Share this post Link to post
JohnLM 27 Posted February 15 I didn't realize I was still in 2019. I mean, I must have been browsing in it some time ago and forgot, and randomly selected a day to have a looksees. Oh well. Now, I've invested time in it and was in the middle of counting the asteroids in the examples they listed. So I was creating a counter and had trouble with it up to now. Still at it. I'm very slow. My brain is fried. Anyway, I'm in the middle of debugging that code when you guys were posting. Oh, and but the question(s) still remain, LoL. . . Share this post Link to post
JohnLM 27 Posted February 15 (edited) Okay, I got the counter working finally. I should have taken this route, as I knew it was the easiest method to do but I wanted to do it a better way (I thought would be more than one way--I'm sure there is) and that just took me to many dark places. I don't know the tricks and techniques you all know. So... at least I can count chars. And as for the reason why I wanted to count them-the asteroids? Well, just because I wanted to know how many there were in the examples that 2019/Day-10 had shown. function astCounterGrid(m1: tmemo): integer; var r,c : integer; aC : integer; // asteroid counter; s : string; ch : char; begin aC:=0; result:=0; for r:= 0 to m1.Lines.Count-1 do begin s := m1.Lines.Strings[r]; for c:=0 to length(s) do begin ch:=s[c]; if s[c]='#' then inc(aC); end; end; result := aC; end; procedure TForm1.btnCountAsteroidsClick(Sender: TObject); begin edit1.text := astCounterGrid(memo1).ToString; end; Edited February 15 by JohnLM typos Share this post Link to post
corneliusdavid 227 Posted February 15 6 minutes ago, JohnLM said: don't know the tricks and techniques you all know. So... at least I can count chars. Even if some tricky function were called to return the number of characters in a string, at some lowest point, there would still need to be an iterator to check each character. The only thing I'd say about your code is you have an unnecessary variable (ch) and character assignment (ch := s[c]). I suppose one "trick" to make your code shorter would be to replace all periods with blanks leaving a line with just hashtags; then you could simply get the Length of the line to get the count of asteroids in that line, something like this (not tested): s := StringReplace(m1.Lines.Strings[r], '.', '', [rfReplaceAll]); Inc(ac, s.Length); Share this post Link to post
JohnLM 27 Posted Saturday at 10:26 PM (edited) Oh, how clumsy of me. I was aiming for {ch:=s[c]; and then {if ch='#' then}, . . . but realized I could use {if s[c]='#' then} and didn't remove the other code. And still, your idea (technique) is better. function astCounterGrid1(m1: tmemo): integer; var r,c : integer; aC: integer; s : string; begin aC:=0; result:=0; for r:= 0 to m1.Lines.Count-1 do begin s := m1.Lines.Strings[r]; for c:=0 to length(s) do if s[c]='#' then inc(aC); end; result := aC; end; // me; my updated version Below, is CorneliusDavid suggestion, plus I added the capture for #13#10 end-of-line codes (when used in tmemo as a grid). function astCounterGrid2(m1: tmemo): integer; var aC: integer; s : string; begin aC:=0; result:=0; s := m1.Text; s := StringReplace(s, #13#10, '', [rfReplaceAll]); s := StringReplace(s, '.' , '', [rfReplaceAll]); Inc(ac, s.Length); result := aC; end; // carnelious suggestion and my updates Both routines produce the same results. They capture the total asteroid counts for all the examples: Best is 3,4 because it can detect 8 asteroids : had 10 Best is 5,8 with 33 other asteroids detected: had 40 Best is 1,2 with 35 other asteroids detected: had 40 Best is 6,3 with 41 other asteroids detected: had 50 Best is 11,13 with 210 other asteroids detected: had 300 I often use the tmemo component as a "grid" to help me with visualization, though it does add to the extra work to compensate for it, like when accounting for the #13#10 char codes that are added. Had I used an multi-dimentional array[1..5, 1..5] of char, then the #13#10 would not be there and we could eliminate the line with: s := StringReplace(s, #13#10, '', [rfReplaceAll]); Edited Sunday at 12:17 AM by JohnLM correction to array[ ] 1 Share this post Link to post
JohnLM 27 Posted Sunday at 12:47 AM Okay, so back to the original question from page 2. I have made some updates to the grid, below. The red lines are where the puzzle said it was blocked by [2,2] (where you see the red square). To me, it appears that location [4,0] (the orange line) would be one of the Asteroids in view. But I'm not so sure. see 2nd image below this one. << 1st image >> My question was which coordinate is the 8th asteroid? Q1- is it [4,0] - orange line? Q2- or is it [3,4] - the yellow highlighted cell? It has a '#' in it, per the example on 2019/Day10 puzzle. Given this 2nd image I custom made to help explain my understanding of direction(s) of travel. Note, I have now updated the squares to be more evenly and uniformatly placed visually. This should help to guide the direction of paths one can travel in more precise I think. Thus, it is clear to me that [4,0] can not be one of the 8 asteroids. Also, most of the others as well. Only a few will travel and be detected, per the coordinates (the lines) I have shown, below. << 2nd image >> I have more to say, but I am out of time and very late for work. Share this post Link to post
corneliusdavid 227 Posted Monday at 01:47 AM On 2/15/2025 at 4:47 PM, JohnLM said: My question was which coordinate is the 8th asteroid? There's a key phrase in the explanatory text for this problem: "The asteroids are much smaller than they appear on the map, and every asteroid is exactly in the center of its marked position." So if we assume a scale like a baseball field is the square area and a golf ball in the very middle is the asteroid, then the only time an asteroid would block the view from another asteroid is if there is a DIRECT line through it; in other words, only vertical, horizontal or diagonal lines crossing another asteroid. Therefore, any asteroid whose view angle to another asteroid does not fit that is assumed to be visible. And therefore, On 2/15/2025 at 4:47 PM, JohnLM said: Q2- or is it [3,4] - the yellow highlighted cell? yes, I believe this is correct. Share this post Link to post
JohnLM 27 Posted Monday at 09:16 AM Well, it's quits for this aoc2019/day10 puzzle. As has turned out, this was a math puzzle, requiring Trignometry and other science/math-related knowledge which I do not have. There is no way I can do this, especially part 2, which is well over my head. Actually, I searched for and watched several YT videos on the aoc2019/day10 puzzle, mainly to find out if someone would go into details relating to my questions. And some of the details vaguely answered my questions, but enough for me to realize that this was not for using with the last "square" grid I posted but was for much finer x,y points in space and requiring higher levels of math/trig, etc.. Thus, this was way over my head. The language used in those videos were in Rust, Python, and some other that I never heard of. But I don't look at them for the source code. I mainly watch them for additional details and explanations of the puzzles which I needed for this puzzle. Anyway, at least I gave it a shot. As for that last grid <<2nd image>> in my previous post, I'm going to keep that as a reference to help me build some functions for searching through them. I have the feeling that they will come in handy in future puzzles and other endeavours. Share this post Link to post