Skip to main content
36 events
when toggle format what by license comment
S Dec 30, 2022 at 19:02 history suggested Glorfindel CC BY-SA 4.0
broken link fixed
Dec 30, 2022 at 17:42 review Suggested edits
S Dec 30, 2022 at 19:02
Aug 10, 2021 at 1:43 history edited theorist CC BY-SA 4.0
deleted 105 characters in body
Aug 9, 2021 at 22:38 comment added theorist @att #&@@Solve[(q=s~Array~{#, #}).q==#2,Integers]&@@{2, m2} fails for m2 = {{1, 0}, {0, 1}} (because of the way the output is ordered, taking the first part won't work in this case). Thus I will need to revert to Last@Solve[(q=s~Array~{#, #}).q==#2,Integers]&@@{2, m2}
Aug 8, 2021 at 0:48 comment added theorist ....extracts the individual element. More precisely, according to the documentation, “f@@expr or Apply[f,expr] replaces the head of expr by fApply always effectively constructs a complete new expression and then evaluates it.” By constrast, "Map[f,expr] or f/@expr applies f to each element on the first level in expr." Though they are similar in that, like with Apply, "Map always effectively constructs a complete new expression and then evaluates it."
Aug 8, 2021 at 0:01 comment added theorist @Jonah Not saying you're wrong, but I don't think of it that way. Compare the result of using @@ (f@@{a,b,c}=>f[a,b,c]) with that of /@ (f/@{a, b, c}=>{f[a],f[b],f[c]}). With Apply (@@), the list as a whole becomes the argument of f, while with Map, each individual element of the list becomes the argument of f. Thus if anything, it’s Map that "destructures the list" into individual arguments. I.e., the reason #2&@@{a,b,c}=>b is because the pure function #&2 is being applied to the list as a whole, not to individual elements of it. It's the #&2 function that....
Aug 7, 2021 at 21:32 comment added Jonah @theorist tyvm. I think the part I was missing is that @@ is essentially destructuring the list into args.
Aug 7, 2021 at 20:33 comment added theorist @Jonah #&@@ selects first, not last. It applies the pure function #& to the list that follows. MMA interprets #&as the first element of a list (because # means #1). Consider: # & @@ {a, b, c}=>a; #1 & @@ {a, b, c}=>a; #2 & @@ {a, b, c}=>b; #3 & @@ {a, b, c}=>c
Aug 7, 2021 at 15:16 comment added Jonah How exactly does #&@@ select last?
Aug 6, 2021 at 0:23 history edited theorist CC BY-SA 4.0
added 131 characters in body
Aug 6, 2021 at 0:17 comment added theorist @att Ah, I see. We were discussing your solution, so that was my focus. But you switched from talking about your solution to mine. Yes, that will certainly work for mine, thanks!
Aug 5, 2021 at 19:38 comment added att Just a straightforward change to your current submission, #&@@Solve[(q=s~Array~{#,#}).q==#2,Integers]&. The first example fails because & has lower precedence than #, so q in Solve is taken to be a scalar; the second case only gets the first row of q.
Aug 5, 2021 at 5:35 comment added theorist @att Sorry, could you show me the complete syntax you had in mind with #&@@? I assume you meant it to be used as a prefix version of [[1]], i.e., #&@@a as a replacement for a[[1]]. But while, for m = {{25, -58, 57}, {0, 7, -4}, {0, -24, 31}} , (q = s~Array~{#, #}) /. Solve[q . q == #2, Integers][[1]] & @@ {3, m} does work, that's not the case for either (q = s~Array~{#, #}) /. #&@@ Solve[q . q == #2, Integers] & @@ {3, m} or#&@@(q = s~Array~{#, #}) /. Solve[q . q == #2, Integers] & @@ {3, m} .
Aug 5, 2021 at 4:21 comment added att #&@@ instead of Last@ for -1
Aug 4, 2021 at 21:08 history edited theorist CC BY-SA 4.0
deleted 4 characters in body
Aug 4, 2021 at 21:06 comment added theorist @att I like what you did—getting rid of the replacement rules by actually making use of them, thus leaving only numbers, is very clever. But you still need to add Last@(adding 5 bytes for a total of 48), or some other modification, to ensure it provides only one soln for all input matrices. E.g., try m3={{25,-58,57},{0,7,-4},{0,-24,31}};(q=s~Array~{#,#})/.Solve[q.q==#2,Integers]&@@{3,m3}. [If more than one soln were acceptable, I could reduce mine to 45–5=40 bytes.] OTOH, if the Dude of many syllables :) required the output look like a conventional matrix, yours would be the way to go.
Aug 4, 2021 at 21:00 history edited theorist CC BY-SA 4.0
added 288 characters in body
Aug 4, 2021 at 4:33 comment added att Print@@Characters@"Z" (replacing the Z here with the symbol in question), for instance, yields \!\(\*TemplateBox[{},"Integers"]\)
Aug 4, 2021 at 4:23 comment added att (q=s~Array~{#,#})/.Solve[q.q==#2,Integers]& for 43 with nicer output. The fancy Z is just the REPL prettyprinting Integers.
Aug 4, 2021 at 3:17 history edited theorist CC BY-SA 4.0
edited body
Aug 4, 2021 at 1:10 history edited theorist CC BY-SA 4.0
added 1 character in body
Aug 4, 2021 at 1:04 history edited theorist CC BY-SA 4.0
deleted 9 characters in body
Aug 4, 2021 at 0:56 history edited theorist CC BY-SA 4.0
added 4 characters in body
Aug 4, 2021 at 0:23 comment added theorist @cairdcoinheringaahing Makes sense to me. I removed that latter section from the post, to clean things up.
Aug 4, 2021 at 0:20 history edited theorist CC BY-SA 4.0
added 51 characters in body
Aug 3, 2021 at 21:48 comment added caird coinheringaahin g @theorist I'm not entirely sure on the current defaults, but my personal opinion is that if there's no way to find out how many bytes Mathematica considers that to be, then you can't really claim it as your solution. The 54 byte one is fine tho :)
Aug 3, 2021 at 21:46 comment added theorist @ovs Yes it does, thanks! I previously tried Solve[q=Array[s,Dimensions@#].q==#, Integers], which doesn't work, but didn't think of adding the parentheses. I'll update the post with your suggestion in a few hours.
Aug 3, 2021 at 21:43 comment added theorist @cairdcoinheringaahing Yes, in this case it seems it's a special character specific to Mathematica. How do Code Golf rules handle this? Is it considered to be simply an alternate way Mathematica has of displaying Integers in its UI, and thus effectively equal in byte count to it?
Aug 3, 2021 at 21:41 comment added ovs Does Last@Solve[(q=Array[s,Dimensions@#]).q==#,Integers]& work for 52?
Aug 3, 2021 at 21:31 comment added caird coinheringaahin g Looks like Mathematica doesn't like (the unicode character): tio.run/…
Aug 3, 2021 at 21:23 history edited theorist CC BY-SA 4.0
deleted 126 characters in body
Aug 3, 2021 at 21:01 history edited theorist CC BY-SA 4.0
added 362 characters in body
Aug 3, 2021 at 20:46 history edited theorist CC BY-SA 4.0
added 26 characters in body
Aug 3, 2021 at 20:41 history edited theorist CC BY-SA 4.0
added 26 characters in body
Aug 3, 2021 at 20:34 history edited theorist CC BY-SA 4.0
added 421 characters in body
Aug 3, 2021 at 20:29 history answered theorist CC BY-SA 4.0