• 0 Posts
  • 9 Comments
Joined 1 year ago
cake
Cake day: June 16th, 2023

help-circle


  • APL

    I’m using this year’s AoC to learn (Dyalog) APL, so this is most likely a pretty terrible solutions. I would’ve liked to use instead of of my imitation of a while loop with a recursive function, but I couldn’t figure out how to get to the number of iterations ⍣ performed to arrive at the destination. If someone here knows how to do that (or has other suggestions for improvement) I’m open for suggestions.

    ⎕IO ← 0       ⍝ use 0-based indexes
    I←⌷⍨∘⊃⍨⍤0 99  ⍝ "sane" indexing
    ⎕PP←17        ⍝ print integers with up to 17 significant digits without use of scientific notation
    
    input←⊃⎕NGET'inputs/day8.txt'1
    instructions←⊃input
    p←↑{0 2 4 I{6⍴⎕CSV⍠'Widths'(3 4 3 2 3 1)⊢⍵'S'1}⍵}¨ 2↓input
    nodes←,1↑[1]p
    L←(⍳⍴nodes) ∘.{nodes[⍺]≡⍵ 1 ⌷p} ⍳⍴nodes
    R←(⍳⍴nodes) ∘.{nodes[⍺]≡⍵ 2 ⌷p} ⍳⍴nodes
    S←(⊃(+.×)/{'R'≡⍵:R ⋄ ⍵≡'L':L}¨⌽instructions)
    ⎕←(≢instructions) × {⍺←0 ⋄ ⍵[⍸'ZZZ'∘≡¨nodes]: ⍺ ⋄ ⍺+1 ∇ S+.×⍵}'AAA'∘≡¨nodes                             ⍝ part 1
    ⎕←∧/(≢instructions) × {⍺←0 ⋄ 0≡+/⍵[⍸~('Z'∘=⊢/)¨nodes]: ⍺ ⋄ ⍺+1 ∇ S+.×⍵}¨{(⍳≢nodes)=⍵}¨⍸('A'∘=⊢/)¨nodes  ⍝ part 2
    


  • APL

    I’m using this years’ AoC to learn (Dyalog) APL, so this is probably terrible code. I’m happy to receive pointers for improvement, particularly if there is a way to write the same logic with tacit functions or inner/outer products that I missed.

    input←⊃⎕NGET'inputs/day4.txt'1
    num_matches←'Card [ \d]+: ([ 0-9]+) \| ([ 0-9]+)'⎕S{≢↑∩/0~⍨¨{,⎕CSV⍠'Separator' ' '⊢⍵'S'3}¨⍵.(1↓Lengths↑¨Offsets↓¨⊂Block)} input
    ⎕←+/2*1-⍨0~⍨num_matches ⍝ part 1
    ⎕←+/{⍺←0 ⋄ ⍺=≢⍵:⍵ ⋄ (⍺+1)∇⍵ + (≢⍵)↑∊((⍺+1)⍴0)(num_matches[⍺]⍴⍵[⍺])((≢⍵)⍴0)}(≢num_matches)⍴1 ⍝ part 2
    

  • I’m aware that the person is disabled, but they explicitly stated in their comment that “there’s currently no reason for someone to switch to public transport” and that “all this is going to do is annoy and upset people”. That to me implied that they didn’t think of cycling as an alternative to driving a car at all, which is understandable given that they probably can’t cycle. So all I did was offer the perspective of someone that does cycle and has to ride on busy streets because there are no bike lanes in hope that they’d appreciate that perspective just as much as I’d appreciate someone giving me their perspective when I’m missing something due to my personal circumstances.

    I agree that there need to be alternatives to cycling in place for those that can’t or don’t want to cycle. Its all about capacity planning, though. If you assume that 20% of your population will use bikes for short to medium distances you’ll have to plan with much more frequent and larger busses or even consider building subway or train infrastructure to get all these people to their destination than if you assume that 70%-80% will use their bikes. So as a transportation planner you’ll need to make a judgement call on how you want the future of transportation to look like in the area you’re responsible for, but I don’t think the choice to make biking the backbone of transportation is necessarily to the detriment of everyone else. To the contrary, the public transport might be less crowded if most people use their bikes, so that for example folks in wheelchairs or those with trouble walking have it easier to get on and off.




  • I was forced to stop using WhatsApp a while back because they simply stopped supporting my phone, and I sure as hell wasn’t going to buy a new one just to use WhatsApp. I came to the conclusion that anyone that doesn’t bother reaching out e.g. via SMS isn’t a real friend anyway, and indeed it hasn’t affected me personally much. There are some people I’ve lost contact with completely now, but we didn’t have proper conversations when I still had WhatsApp anyway, so not much was lost.