12:00 AM
@ConorO'Brien Ok imagine we have a rectangle object. We can upcast it to a polygon, since all rectangles are polygons, this succeeds. We can also downcast it to a square, but since while squares are rectangles we don't know if this particular rectangle is a square, so it might throw an error.
that's quite intelligent, cool!
I might have to look into F#
12:31 AM
@Pavel so :> casts it to a type it inherits, while :?> casts it to a type that inherits it?
@Pavel for a symbol for denoting an auto-closure-property head
12:44 AM
@Pavel so :?> is dynamic_cast
does it throw an exception or return null
12:55 AM
@quartata THrows
@Skidsdev Yes
@quartata Pattern matching what you're "supposed to" do btw
@Pavel does pattern matching get resolved at runtime for types
@quartata Runtime, but why would you use a type that's above the object you're matching on as your pattern
no i didnt mean for an upcast lol
You can't do downcasts at compile time though?
was thinking more like a template
1:10 AM
Ah! No, but if you define your function using the syntax function | pattern1 -> case1 | pattern2 -> case2 it'll make the function generic
@Deadcode I meant that I read the solution but couldn't see why it worked. I've gone through the algebra now to see that the division by k works. But still don't really understand it. FYI, the first part can be replaced by (?=(x((xx)*))\1*$), and then \2 instead of \3 1:42 AM @H.PWiz Thank you very much! That's -5 bytes. And the multiplication algorithm works because it's actually exactly like counting out the number of times the factor fits into the product. That's why it's important which factor is greater than or equal to the other one. Does result in a slight slowdown though (The -5 byte golf) @H.PWiz Here is an intuitive-level explanation of the algorithm. (Warning for others seeing this: Spoilers within for an advanced ECMAScript unary mathematical regex technique.) 2:23 AM @Deadcode Okay, is that a spoiler warning or clickbait? :P (not clickbait in a bad way, more like "okay I have to see this" [no sarcasm]) 2:41 AM Well, I mean, it's up to you :) I include the warning for people who truly want to figure it out on their own :) I'm really glad I had the opportunity to do so, and prove to myself that I could figure it out. 3:15 AM I would be really curious to see what kind of proof an actual mathematician would come up with that this unary regex multiplication algorithm always works. I never got around to asking teukon this question. @Deadcode Of the general one? How long is it? @H.PWiz Hi. Not sure what you're asking? How long is what? I think you would call it robust. (Do you want a proof of the robust one, and how long is the robust one) All the ones I use in posted regexes are robust... The shorter ones are robust under a certain constraint i.e. that one of the numbers is greater than or equal the other which can be replaced with a constraint that they're prime powers of the same base prime I don't see that as exactly the constraint for the one used in Proth numbers. 3:25 AM It's in the comments though one of the numbers is guaranteed to be >= the other II agree. But I don't think the multiplication works for that constraint What do you mean? One sec. BTW, did you notice I golfed abundant numbers down to 504 bytes? :) So close to breaking 500... The multiplication, as I understand it is: ^(x(x+))\*x(x*)=\1(?=\1*$)\3\2*$, which gives a false positive for 4*2=20 3:30 AM Where is that regex from? Oh, you wrote it? Modified from Proth numbers. Of course, I could have misunderstood it You need \4\2*$
I think
oh
never mind
you didn't capture B, only B-1
Okay, hold on.
@H.PWiz Okay the problem is, you're using a multiplication that only works if you have a .* before it, but you're using it on a constant. So it will find a match.
It's important that you cycle through all the possible values the product could have, starting with zero, and the smallest one that satisfies the conditions is your match.
And then you compare it against the product to see if it matches.
But that's actually not the most efficient way to do a correct-multiplication-statement matching regex.
It's just the best way to do it within the context of a larger regex, to actually calculate multiplication.
I should note that I believe that your proth numbers solution is robust, despite this
How generous of you ;P
I'm 100% sure it's robust.
How? (what other constraints on the inputs to the multiplication do you have?)
3:39 AM
It's kind of hard to explain. I'm not a mathematician. But I worked out why it works...
That's fine, that's pretty much where I am
Did that link to the Gist discussion post help at all?
I can't say, because I got quickly distracted, thinking about it myself
Here's some cryptic notes from when I recently re-proved this thing to myself. It probably won't help:
C = X * b
C - b = Y * (A-1)
C - b - (A-1) = Z * (b-1)

C = 0 mod b
C - b = 0 mod (A-1)
C - b - (A-1) = 0 mod (b-1)

b >= A

C = 0 mod b
C = A mod (b-1)

C=100, A=5
b=1:
b=2:
b=4:
b=5:
b=10: C=50, 140, 230, 320, ...
b=20: C=100, 480, 860, 1240, ...
b=25: C=125, 725, 1325, 1925, ...
b=50: C=250, 2700, 5150, 7600, ...
At the time, I proved it to myself without any doubt. I didn't hold in my mind the entire explanation, but I believe my earlier self on this
There's a chance this could be some variation of the Chinese remainder theorem.
@H.PWiz Do you want to see my division by sqrt(2) regex?
It has great examples of all the generalized operations
Not right now.
Thanks though
3:54 AM
I'd really like to post it on codegolf... there's currently no question where it'd belong. Should I post the question as a typical one? Take a nonnegative integer as input, divide it by sqrt(2) and return the rounded answer. You may choose the type of rounding (floor, ceiling, nearest with round half up, nearest with round half to even, or even arbitrary or random).
Submissions could be in any language, and I could submit my regex as one of the answers to my own question.
Anonymous
@Deadcode I would recommend specifying a rounding method in the challenge. Challenges where part of the spec is "choose one" are usually not as well-received as challenges where the requirements are fully specified.
@Mego I actually feel pretty strongly about that.
If there were a round-to-nearest requirement, for example, my regex would have to be much longer
I'd like to see what optimizations come from using the most convenient rounding method.
Would be much more interesting, too, seeing what kind of rounding gets used in each language.
1.5 -> 2.0, but 0.5 -> 0.0
3.5 -> 4.0, but 2.5 -> 2.0
huh, I've never heard of that before but ok
3:59 AM
It avoids the systematic error that would come from rounding 0.5 up all the time
that would skew the results a bit, if it's not of 0 probability to get exactly 0.5 as the fractional part
ah, interesting
Anonymous
It's sometimes called "banker's rounding". Python 3 uses it as the default rounding mode.
@Mego How about if I have a ranked list of rounding techniques, and require that the highest-ranked method giving an equal-length program is the one that be used. (Of course, to the best of the answerer's ability to determine.)
e.g. if ceiling results in the same program length as floor, they must use floor.
Anonymous
That would be complicated, and would probably lead to fewer answers being posted
Okay, then I'll leave it as use whichever rounding technique you choose. The only requirement is that the difference between the returned value and the precise value is always less than 1.
Should I use the sandbox?
Anonymous
4:05 AM
@Mego Am I supposed to leave a question in the sandbox when I ask it officially, or delete it from the sandbox, or move it from the sandbox?
Oh, it says right there.
Delete it.
Also, what I'm thinking I want to say is, "If your language has a built-in arbitrary precision integer type, either as part of the language or a standard library, you must use it. Otherwise, use the largest fixed-size integer type available, unsigned if possible."
Is that reasonable?
4:25 AM
@Deadcode haven't read whole context but downside with this is in JS there is a non-insignificant byte overhead when dealing with bigints along with different semantics compared to normal numbers
well that would be true in any language. The amount of overhead would vary, of course.
Anonymous
@Deadcode The usual (and default) requirement is native int size. So for C it's platform-dependent (usually 32 or 64 bits), for JS it's 53 bits (since Numbers are doubles), for Python it's arbitrary (since Python ints are arbitrary-precision), etc.
@Mego Well the truth is I'd like to see both types of answers.
Native int (or floating point if there's no int type), or bigint; answerer's choice.
Even submit both as separate answers, if you like.
Anonymous
You could do something similar to what I like to do: have the requirement be native ints, but encourage solutions using bigints
So basically, the requirement is for at least the precision of a native int?
Anonymous
4:39 AM
Yeah
4:50 AM
Is there a standard / common amount of time before a winning answer should be Accepted?
And for objective-winner code-golf challenges, is it more common for the Question submitter to Accept their favorite answer in the case of a tie, or Accept the highest-voted within that tie?
For PPCG, it varies but usually give it like a week or alternatively don't accept any answer.
Ties with no breaker also fall to your discretion, do whatever, be it timestamp, your favorite, or most popular
Anonymous
@Deadcode The default tiebreaker for PPCG challenges is that the answer that first reached the tied score wins
5:27 AM
0

Trapped Knight Sequence code-golfnumber Inspired by the very recent video The Trapped Knight - Numberphile, I came up with a challenge. Introduction The trapped knight sequence is a finite integer sequence of length 2016, starting from 1, and has the following construction rules: Write a num...

0

Divide by the square root of two The challenge is to implement a program or function (subsequently referred to as "program") that takes a nonnegative integer \$n\$ as input and returns \$n\over\sqrt{2}\$ as output, rounded to a nonnegative integer. You may take your input and output in any reas...

Oh, that happened automatically
Nice.

2 hours later…
7:10 AM
How often does it happen that someone finds a golf optimization that would exponentially slow down their program? What's generally done in this kind of situation?
Should it take precedence as the main version of the program in that answer, or be a footnote?
@Deadcode Golfed solutions often have terrible performance. Unless stated otherwise by OP, your solution doesn't have to terminate before the Universe does.
@Deadcode You can always add a note saying something like A solution that will actually terminate before the heat death of the Universe is…
7:46 AM
🐌

3 hours later…
10:33 AM
0

Challenge: Given a matrix input, determine the amount of diagonals and anti-diagonals with duplicated numbers. So if we have a matrix like this: [[aa,ab,ac,ad,ae,af], [ba,bb,bc,bd,be,bf], [ca,cb,cc,cd,ce,cf], [da,db,dc,dd,de,df]] All diagonals and anti-diagonals would be: [[aa],[ab,ba],[a...

1 hour later…
11:37 AM
0

I am very confused regarding the validity of the below program in c. I think it is logically incorrect but my teacher stresses it is. The code is int a, b, c; a=5; b=6; c=a>b; printf("%d", c); According to my teacher the output will be 0. Is it correct? I get it is zero if the condition is fals...

11:52 AM
Brazil's first openly gay congressman decided not to take up his term this year because he's being harassed and receiving death threats. The president's answer to this (on Twitter of all places) was a series of 3 emoji and the words "Today's a good day" followed by another emoji.
Can't wait to graduate and leave this fkn place
@J.Sallé I still don't understand why sexuality isn't a private matter.
12:18 PM
@Adám that was actually the least of the problems. Since Marielle's assassination (and even before that), many left-wing leaning politicians have been threatened by the militias who they fight against (especially here in Rio, where this congressman is from).
Naturally he's been dealing with harassment ever since he began his political career because of being gay. He was already kinda famous because he was a runner-up (iirc) in one of the earliest editions of Big Brother Brasil and also the first openly gay participant in the program.
Most of that harassment came from the current president, by the way, and his lunatic followers.
12:37 PM
U.S. to follow.... sadly.... with the state it looks like this is going

4 hours later…
4:15 PM
@H.PWiz It is the Chinese remainder theorem. Just did the math and it works out perfectly. You only need two moduli, with a difference of 1 (guaranteeing that they're coprime).
The reason the moduli need to be the larger of the two factors and that factor plus or minus one, is that this only guarantees a unique solution <= their product – and the product of the smaller factor times itself minus one is going to be less than the desired product (unless both factors are the same, i.e. a square), so there could be an unwanted solution.
Salesforce's help documentation has to be some of the worst UI I've seen from a large company. No fewer than four scrollbars, and things are cut off unless your browser window is large enough.
This is probably why teukon was able to figure it out so fast. He's a mathematician and he would have been familiar with the math of it. I worked it out at a more imperative-programming level, thinking about it as multiplexing two numbers to do the multiplication as repeated addition with a counter.
0

Hey guys 1 post here sorry if this is asked somwere else but i couldnt finde it. Like the title said i need a C code to replace the 1 row with the last row and 1 column with the last column in a matrix A [m][n]. Thanks for the help

4:33 PM
@Deadcode I felt like I cane up with a simpler proof. I might revisit it later tonight
4:51 PM
*came
You might note that choosing to use (x(\2x+?)) still works, but doesn't actually find 2^n
@H.PWiz Actually can't be bothered to go through it, Chinese remainder works fine
5:39 PM
Lol (from 2019 SO survey)
6:10 PM
Absurd res is absurd
6:23 PM
Res?
Resolution
Oh lol
Yeah my phone's screen is 1080p horizontally
Ah, gotcha
There are 1440p and even 2160p phones
Yeah, just that the resolution on the picture was 1080x1289, which is kinda unusual. Hence my comment.
6:30 PM
When you said "Absurd", I assumed you meant "Absurdly high"
Me too
CMC: Given a W x H matrix, output all its square sub-matrices of all sizes from 1 through min(W, H)
It does load very high on my setup. I think because the DPI scaling is odd or something.
[[1,2,3],[4,5,6],[7,8,9]] -> [[1],[2],[3],...,[9],[[1,2],[3,4]],...[[5,6],[8,9]],[[1,2,3],[4,5,6],[7,8,9]]]
Oh, all
well APL has ⌺ so yeah
6:35 PM
@Quintec but it does annoying things with edges :|
@dzaima Which is why I didn't post an answer, I'm too lazy :P
Yuck yuck yuck. I don't even want to think about doing that in PowerShell.
Following DJMcMayhem's proposal:
We've got a lot of bounties offered. I don't think we'll have enough categories to cover them all. What about offering second place bounties in each category? (250? 300?) — DJMcMayhem ♦ 1 hour ago
@Mr.Xcoder [[1,2],[4,5]] instead of [[1,2],[3,4]] right
@Mr.Xcoder There's no option for "Yes, I don't care which one"
I'm curious if anyone's opposed to the idea
Well there you go (not my vote)
@H.PWiz It is a simple proof. The algebra shows why the modulo has the value is has, i.e. with A*B=C, C-B=(A-1)*B, thus C ≡ B mod A-1, and the Chinese remainder theorem shows that the residues of the moduli A and A-1 uniquely determine the value of C within the range of 0..(A*(A-1)).
@Mr.Xcoder APL, 37 bytes. there's probably a way better solution without ⌺
@H.PWiz Works for what?
6:48 PM
I love the Chinese remainder theorem. It shows up everywhere. Don't know why this ring is isomorphic to that field over the rational numbers? Chinese remainder theorem. Don't understand why this function has real roots equal to the function when expressed in radians? Chinese remainder theorem. Don't know the average air speed velocity of an unladen swallow? You guessed it, Chinese remainder theorem.
:D
@AdmBorkBork Don't know why your parents refuse to move to America so you can keep an eye on them? Chinese remainder theorem.
Heh.
^^real story irl oof
6:51 PM
@H.PWiz Oh. Well what do you mean it works, but doesn't work?
BTW, I haven't proved the division algorithm yet.
Just the multiplication algorithm.
For multiplication, you need to find the smallest value that matches. For division, you need to find the largest value that matches.
Oh, I was looking at the division algorithm. I mean that it works, but not for quite for the same reason as the original
I tested it with a very large range of numbers and it works, but an empirical proof is of course not a proof.
(In native code, not regex)
Also I haven't proved yet why you can swap the A≥B requirement for A and B being prime powers of the same base.
But tested it with a large range of numbers too.
Oh, and here would be a really neat ECMA regex to figure out: Euler's totient function.
Not sure if it's possible.
Would be possible with scratch space, of course.
How can I retract a delete vote on an answer?
@BMO get the answer edited in one way or another
Chinese remainder theorem.
7:03 PM
Nvm, I think I already retracted and it's someone else's..
I spoke the magic words and Leaky arrived.
@dzaima Thanks, but I think I already removed it :S
7:24 PM
@Mr.Xcoder IMO that makes Best of PPCG a little more formal
like, now it's not just a bunch of bounties we give, but actually a competition
8:00 PM
That's why I voted "No." You don't win an award for coming in second at the Academy Awards, or the Grammy Awards, etc.
Why not three places? Gold (500), silver (250) and bronze (100) makes sense
There's enough rep to do so for 9 categories and 11 categories posted, still not too much choice..
8:28 PM
CMC Given a rectangular non-jagged matrix, rotate the last row to be the first row, then rotate the last column to be the first column, shifting the rest of the elements as appropriate.
1 2 3
4 5 6
7 8 9
becomes
9 7 8
3 1 2
6 4 5
Stupid matrix language
0

Ambigous Locations on a Grid code-golf grid You have a little robot with four distance sensors. It knows the layout of a room, but it has no sense of orientation other than being able to lock onto the grid orientation. You want to be able to find out where the robot is based on the readings, ...

I mean ... right tool for the job
8:41 PM
9:23 PM
Can somebody help me make a Python interpreter for my cellular automation I randomly made?
A website (HTML, Javacript, etcetera) would also be helpful
How about to rearrange the matrix into magic square order? [[1,2,3],[4,5,6],[7,8,9]] → [[8,1,6][3,5,7][4,9,2]]
(could be any other rotation/flipping of the magic square if it golfs better)
@MilkyWay90 does it need to be python?
9:51 PM
My illegal string in PS kinda looks like a bird.
@Veskah May I see?
@downgoat no
So basically, if a live cell has 0, 1, 8, 7, or 6 neighbours, it dies
if it has 2, the cell to the top of it becomes alive, if it isn't already
3 is to thr giht
*right
4 is down
and 5 is left
the block (2o\$2o! in RLE)
is a glider
10:06 PM
10:18 PM
@MilkyWay90 what if a cell has one of those neighbor counts but another also wants to set it to alive?
Okay, attempt like 73 on illegal string might be good
if a cell has one of the other-modifying states, i assume by default it stays what it was before?
@Veskah Haha, cute. Reminds me a bit of a Secretary bird.
@flawr I can't tell if that's horrifying or amazing
10:33 PM
@Riker neither can I, but I thought you'd like the post anyway :)
@flawr indeed
@Deadcode I'd pet that bird (and probably lose fingers in the process)
11:09 PM
IsItGreyOrGray keeps cracking my illegal string ;~;
I'm too much of a law-abiding citizen I guess