!cxPCiPlsXnajakSrqd:matrix.org

Array languages

880 Members
General discussion about APL-like array languages. See #array:matrix.org for other rooms24 Servers

Load older messages


SenderMessageTime
23 Jan 2025
@_discord_870115701279584326:t2bot.iodiscodoug I haven’t thought about this specific problem. Just offering a general heads up. I’m actually not a fan of the big O constraints in leet problems. They feel artificial and take the focus away from the problem domain. 21:31:11
@_discord_160673472530350080:t2bot.ioludvikgalois I have mixed opinions about it. The big O constraints in leet problems are a strong hint at the kind of solution they're looking for. On the other hand, it just makes an already artificial thing feel even more artificial 21:32:53
@_discord_304605065715384321:t2bot.iofiuzeri yes, exactly. I think it should be the previous row of b that decides what entries of a[ceil(log(n))-k] to select, and then that gets maxxed with the previous row of c 21:33:36
@_discord_870115701279584326:t2bot.iodiscodoug ludvikgalois To your earlier point about mutability. Most array languages have some amend operations which is functional mutability if you don’t hold onto a reference. So that’s not necessarily out of bounds. 21:34:56
@_discord_304605065715384321:t2bot.iofiuzeri so probably each row b and c can be computed independently 21:35:20
@_discord_136899955574046721:t2bot.iodzaima (discord) but it won't bring you closer to array-iness 21:35:53
@_discord_870115701279584326:t2bot.iodiscodoug That’s true. Though I might take a broader view of array-iness. 21:36:26
@mlochbaum:matrix.orgMarshall I don't feel like c should be needed at all, isn't it guaranteed to be less than input[i] anyway? 21:36:32
@_discord_870115701279584326:t2bot.iodiscodoug It feels like random access should be on the table. 21:36:50
@_discord_136899955574046721:t2bot.iodzaima (discord) problems arise when you want to do some other operation between each mutation, which is trivial with a traditional loop but must be worked-around in array-y code 21:38:58
@mlochbaum:matrix.orgMarshall bqn)
{𝕊t: (↕≠𝕩) ¬˜ 1{𝕨≥≠𝕩?↕≠𝕩; (𝕨×t>⊏⟜𝕩)⊸+(2×𝕨)𝕊𝕩⌈(𝕨⥊∞)«𝕩}∞«𝕩} ⟨73,74,75,71,69,72,76,73⟩
21:46:19
@bqnbot:matrix.orgBQNBot Marshall ⟨ 1 1 4 2 1 1 2 1 ⟩ 21:46:24
@mlochbaum:matrix.orgMarshall Recursion, pass a[k] on the way down and b[k] back on the way up. 21:47:37
@_discord_304605065715384321:t2bot.iofiuzeri neat! in the meantime I just about got
a:{|(,x),x{x|shl[y;x]}\-1_((#x)>)(2*)\1}
21:48:42
@_discord_160673472530350080:t2bot.ioludvikgalois Very cool. But missing a post-processing step to fix it up so that those which "point past the end" are 0 21:50:50
@mlochbaum:matrix.orgMarshall Yeah so substitute (¬˜×(1-˜≠)⊸>) for ¬˜ I guess. 21:53:18
@mlochbaum:matrix.orgMarshall Oh, and t> should be t≥. 21:56:19
@mlochbaum:matrix.orgMarshall Using 101 instead of , this is nearly 10x faster than that old O(70×n) BQN solution on the input 30 + 1e4•rand.Range 71. 21:58:18
@dzaima:matrix.orgdzaima here's a horrible mess I managed to write, that has some bugs still but I can't be bothered to figure out why: {𝕊a: k←⌈0.5+2⋆⁼n←≠𝕩 ⋄ t←{⌊˝˘∘‿2⥊𝕩}⍟(↕k-1) 𝕩 ⋄ {0¨⌾((∞=𝕩)⊸/)𝕩} (↕n) -˜ ⌊´ {r ← (⌈(1+↕n)÷2⋆𝕩) 2⊸×⊸{𝕨+a>(𝕨⌊¯1+≠)⊸⊏𝕩⊑t}˜´ ↕𝕩 ⋄ ∞¨⌾((a≥a⊏˜r⌊n-1)⊸/) r}¨ ↕k} 22:20:49
24 Jan 2025
@loke:dhsdevelopments.comloke I did an O(n^2) solution in Kap: { n←≢⍵ ⋄ n | 1 + ((1⍳⍨)⍤1) ⍉ (>1↑)«<[1]»↓ (⌽≤⌻⍨⍳n)×(⍳n)⊖n/⍪⍵ } 03:39:14
@dzaima:matrix.orgdzaima for an O(n^2) solution I had this BQN: {{⊑0∾˜/𝕩>⊑𝕩}¨ ¯1↓↓𝕩} 04:01:41
@loke:dhsdevelopments.comlokeVery nice. My approach can be reduced by a bit but laying out the data better, but I doubt I could get it down to anything less than two times your size.04:09:33
@loke:dhsdevelopments.comloke * Very nice. My approach can be reduced by a bit by laying out the data better, but I doubt I could get it down to anything less than two times your size.04:09:59
@dzaima:matrix.orgdzaima here's a different approach, Kap: {0⌈ (n | +/ ~∨\ ⍵ ×⍥(<⌻⍨) i) - i←⍳n←≢⍵} 04:10:11
@loke:dhsdevelopments.comlokeWhat the actual? I'm always shocked (in a positive way) when I'm bested by someone's (usually yours) Kap solutions.04:11:13
@dzaima:matrix.orgdzaima taking some inspiration from your solution: {n| 1 (⍳⍨⍤1) i⌽ ⍵ ∧⍥(<⌻⍨) i←⍳n←≢⍵} 04:13:13
@dzaima:matrix.orgdzaima placing the zeroes is the most annoying part, otherwise there's the nice {1 (⍳⍨⍤1) (⍳≢⍵) ⌽ <⌻⍨ ⍵} 04:19:47
@dzaima:matrix.orgdzaima here's one way to fix that up: {((⌽i)>)⍛× 1 (⍳⍨⍤1) (i←⍳≢⍵) ⌽ <⌻⍨ ⍵} 04:23:39
@loke:dhsdevelopments.comlokeI'm supposed to port some SQL stored procedures right now. Instead I can't stop thinking about this one :-)04:29:00
@loke:dhsdevelopments.comlokeI was just going to drop my straightforward solution and then get back to work.04:29:18

There are no newer messages yet.


Back to Room ListRoom Version: 6