« first day (1596 days earlier)      last day (3242 days later) » 

12:06 AM
these nag brackets
rrhhhh
when i mass all these brackets , i can make a code of same length
 
@NathanMerrill Can you chain additions for Code Bots 3?
 
 
1 hour later…
1:21 AM
-1
Q: Write a program containing a syntactically valid phallus

Robert D. JohnsonAs a simple example: 8==D is a valid expression in many languages. A more impressive entry might be a program containing (_))::::::::::D, although I'm not sure how you could do this without syntax errors. Your entry doesn't have to be a complete expression, but it does have to be part of a vali...

 
grc
1:33 AM
^ wow...
I wonder if there's an esolang for that
 
I knew this day would come eventually.
 
2:24 AM
@grc Replace the D with |) and you got perfectly valid CJam.
 
grc
my computer died right after I said that :/
 
 
2 hours later…
4:28 AM
JavaScript and I will never understand each other...
{}+{} -> NaN
Array(2).join(NaN) -> "NaN"
Array(6).join({}+{}) + ", Batman!" -> ?
"[object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object], Batman!"
 
grc
4:49 AM
@Dennis {}+{} == ({}+{}) -> false
 
@grc I expected that one. NaN==NaN -> false
 
grc
({}+{}) isn't NaN
it seems to use string concatenation in that context
but addition in {}+{}
 
@grc Expected it for the wrong reason then...
({}+{}) -> "[object Object][object Object]"
 
grc
[]+{} -> "[object Object]" and {}+[] -> 0
maybe the latest xkcd is actually referring to js?
 
My initial thought was JS, but then again that's the only language I know which lets you do "42"/6
 
4:56 AM
Not sure. But whatever he tries to come up with, it can't be much worse than existing languages.
And JavaScript is right at the top.
 
grc
php is worse imo
<?
function foo() { echo "hello"; }
$s = "foo";
$s();
?>
hello
 
OK, it's at the top, but it's not alone.
 
@Dennis The first {} is a block. Then it evaluates +{}, which attempts to convert the empty object to a number, which it's not, so it returns NaN.
[]+{} first converts [] into a string by joining its elements with , (resulting in ""), then string-concatenates {} to get "" + "[object Object]".
In {}+[], the curly braces are again an empty block, and +[] results in 0.
tl;dr JS is weird
 
grc
would that be a video card issue?
 
@Doorknob I get that. But why is {}+{} not NaN in Array(6).join({}+{})?
 
grc
5:07 AM
before I go to askdifferent
@Dennis {} doesn't get treated as a block in that context
 
@grc Because join expects a string?
That PHP code is awesome, by the way.
 
grc
I think it's the parentheses
 
@grc That's almost certainly the graphics card.
 
grc
aw :(
 
@Dennis Because a block would be a syntax error there. Your first example is parsed as
{
    'nop';
};
+{}
where the first {} is interpreted as a block (like one that would come after if, for, etc.).
In the second one, you can't have a block there, so JS assumes it's an empty object.
 
5:18 AM
@Min_25 Thank you for the proof! I look forward to fully understanding it :)
 
grc
interesting that {"abc": 0} gives a syntax error
 
@grc Yeah, because it's parsed as a block. Wrap it in parens if you want an object
 
@Doorknob Ah, that makes sense.
Still, "[object Object][object Object], Batman!" was a bit anticlimactic.
 
Array(16).join('wat' -1) + " Batman!" does work (from the appropriately named lightning talk, "Wat")
 
Yes, that's where I got the idea from.
And I thought, hey, {}+{} gives NaN. That would be even funnier.
Joke was on me.
 
5:25 AM
Heh, you could still use +{}.
 
@Doorknob So the first {} would be a syntax error, but the second isn't. And I just thought I got it...
 
@Dennis When you wrap it in parens—({}+{})—, the first pair of braces cannot be interpreted as a block (or it would be a syntax error). So JS assumes it's an empty object instead. The second pair of braces couldn't be a block even outside of parens (+{ console.log('test'); } wouldn't make any sense), so it's always interpreted as an object. Applying unary + to an object results in NaN.
 
@Doorknob OK, I got it. So it all boils down to JS desperately trying to make sense of the code.
 
Morning all
 
I think I prefer Python's approach to this: In the face of ambiguity, refuse the temptation to guess.
@CoolGuy Morning, I guess. (It's 1:30 here. :P)
 
5:40 AM
4
Q: Build a one-word search generator

Joe Z.The word BANANA appears exactly once in this word search: B A N A A N B B A B A N A B A N A N A B N N A A N N B A A A N N N A A N N N B A A N N N B A N A N A A B A N A N B A N A N B B A The word search above contains only one occurrence of the word BANANA, but a lot of similar words, like BANA...

 
grc
@Dennis I think this challenge was where I first saw it
 
@MitchSchwartz hi.. do you understand this random walk Min_25 describes?
 
6:26 AM
@MartinBüttner Really? For Java? I don't think the paper would be publishable in anything above an undergrad journal, although I suppose I could give one of them a try if I make it sufficiently expository. More likely I'll put it up on my personal site and then link to it from OEIS.
 
 
2 hours later…
8:26 AM
Damn, I broke my 280+ days visit streak on PPCG ...
 
 
1 hour later…
9:52 AM
I have an proposal I'd like to float: If you're going to post an answer in one language that's an exact golf of another language's answer, you should make it community wiki.
 
@isaacg What if someone comes up with an answer independently which just happens to be the same as one in another language?
 
Then it's fine.
I'm thinking of cases like this one:
1
A: Visual Long Multiplication

MaltysenPyth - 79 bytes A translation of @AlexeyBurdin's answer. Can probably be golfed a lot more. AzHmu++Gm1sH]Zd]Z,_zwK+lzlHJmm\ KK .e.eX@J+kY+-Yklz@" \/x"+byZHzjbmjk:d2_1:J1_2 Takes input as two numbers, newline separated. Explanation coming soon. Try it online here.

 
10:11 AM
my two codes arent of same algorithm , and they are all C
and whats community wiki btw
 
It basically means no one gets rep for the question.
 
for the answer of question ?
 
10:29 AM
@PeterTaylor Sorry, I normally don't Java. But isn't there some weird catch that I have to name the file after the class or something? That gets me every time.
 
10:58 AM
Yes, that's right.
 
11:14 AM
@Lembik not entirely, but vaguely
x and y should refer to the two dot products are keeping track of, and returning to (0,0) in n steps means that they are both zero after adding n elements to the arrays
i'm not sure how that handles the "wrap-around" between the first step and the last step, or maybe i'm not thinking about that properly
 
 
1 hour later…
12:41 PM
i've made a bit of progress understanding the combinatorics. i can almost get matching results with (pari/gp) sum(i=0,n,if(i%2,0,binomial(i,i/2)^2*binomial(n,i)*4^(n-i))) -- it matches for odd n but not even n
the reasoning behind that expression is that, we iterate over the number of non-zero steps "i", which has to be even in order to get a path back to zero, and the horizontal and vertical components are independent 1d random walk problems, so binomial(i,i/2)^2, then there are binomial(n,i) ways to place those i moves, and then 4^(n-i) ways to choose the zero moves, but obviously there's a mistake somewhere
 
1:04 PM
the expression above for even n gives an answer that is binomial(n,n/2)^2 less than the right one, hm
 
0
Q: ASCII rhombus challenge

AlmirHy guys. I'm new one on this, and this is my first programming puzzle & code golf question. Take some time, and try to code, in your favourite programming language, this rhombus. EXAMPLE When i input 2 or 3, that your code output this: * * * * * * * * * * * * ...

 
^^ we're burning through the ASCII art challenges so quickly, we'll have none left for the future!
 
@MitchSchwartz binomial(n,n/2)^2 is a very large number!
@MitchSchwartz do you understand how it handles the wrap-around?
 
i wonder if wrap-around is the reason for the discrepancy
 
@MitchSchwartz going back to square one... his formula gives exactly the same result as your code, right?
so we are still assuming it is correct?
 
1:15 PM
it may be something like: if you don't use every single node, then there's only one way to resolve the first and last steps, but if you use every node then there are two ways
you ask strange questions
you saw for yourself his code and my code give the same answers
 
@MitchSchwartz sorry didn't mean to be strange.. I just used his code blindly without checking it actually implemented the formula
 
i think my expression sum(i=0,n,if(i%2,0,binomial(i,i/2)^2*binomial(n,i)*4^(n-i))) + if(n%2,0,binomial(n,n/2)^2) may be a bit easier to compute, idk
 
also two eyes are better than one!
 
i think it is probably worth leaving a comment with that
or maybe an email
 
thanks very much again!
I am very grateful you are looking at my problems
it's really great to have some interested
s/some/someone
@MitchSchwartz I was planning on adding a bounty to codegolf.stackexchange.com/questions/51624/… as soon as I am allowed
 
1:33 PM
(email sent)
 
what did you ask in the end?
 
i just told him about the expression that i found, and that i didn't understand why the extra binomial(n,n/2)^2 is needed, and linked him to that chat transcript, and said i would keep looking at it
 
cool
do you think it is possible to get a closed form for j =2 too? It looks to my naive eyes like the same route Min_25 suggested should be doable
but I really need to understand the j=1 solution properly first
I like Min_25's addition of the exponential generating function... but it just adds another mystery :)
 
i'm not sure. i think there is an obstacle that would need to be overcome, which is that we need to consider not just e.g. A[i] = A[i+1], but also A[i-1]
 
Please forgive my naivety but I was hoping it would "just" turn into a 3d random walk instead
where the cases are A[i]=A[i+1]=A[i+2], A[i]=A[i+1] != A[i+2] etc
but maybe that is too hopeful
perhaps I should say I am definitely not sure either
 
1:52 PM
well for j=1 there are 4 reachable points and always exactly 1 way to get to each (ignoring the boundary). for j=2 there are 8 potentially reachable points, but only half of them are actually reachable depending on the sign of the previous array element, so i'm not sure how that would be reasoned about
(only talking about non-zero moves)
i have lack of experience here, but i was wondering whether we could use markov chains to get around that
 
2:34 PM
@TheNumberOne yes you can
@Sparr I made it so that Copy $label A works
 
Is that switch on or off?
 
What? I find it to be in the off position....
 
On
I have those in my house,
 
hit the top to turn on, hit the bottom to turn off, that's how i've always encountered them
 
2:39 PM
But I find it awkward because it is the opposite for me :/
 
It's quite different from the toggle switches.
 
In my house, that would be off
 
@Sp3000 , Same here.
 
But it really depends on the switch - like I have some XOR lights at the top and bottom of a set of stairs, so they can be either
 
@Mitch I don't know how "binomial(i,i/2)^2*binomial(n,i)*4^(n-i)" works now... It seems that this combinatorial approach is different from mine.
 
2:41 PM
OK, it's just inconsistent. That sucks.
 
@Min_25 oh thanks for replying :) it is based on the random walk idea, as i was having trouble following your computation of c(n)
 
(btw to add a bit to the light switch thing, apart from our stair lights the reason why the rest of them would be off for that picture is because if you flick it on, you can see a red spot at the top of the switch to indicate that it's on)
 
i thought, since there is one way to get to each of (x+1,y+1), (x+1,y-1), (x-1,y+1), (x-1,y-1), then we can separate horizontal and vertical
 
My solution use the 90-degree rotated coordinates; X = x+y, Y = x-y
Then, use X-moves i times and Y-moves (n-i) times to move from (0, 0) to (0, 0).
 
oh interesting, thank you for explaining
i will keep trying to understand why i need a corrective term over what i originally thought would work
 
2:52 PM
There [x^0](1/x + 2 + x)^n = [x^n](1 + 2x + x^2)^n = [x^n](1+x)^{2n} = C(2n, n) ways to move from (0) to (0) and there are a(n, i) sequences A that allows us to use exactly i X-moves and (n-i) Y-moves. So, c(n) = sum a(n, i) * C(2i, i) * C(2(n-i), n-i), where a(n, i) = [x^i]((x+1)^n + (x-i)^n))
s/(x-i)^n/(x-1)^n
 
my setup is using i non-zero moves and (n-i) zero moves
(zero move means go from (x,y) to (x,y) [4 ways], if it wasn't clear)
 
How to correlate i non-zero moves with the sequence A ?
 
3:08 PM
well i didn't understand what the A[i] = A[i+1] check means when we are making the very first move, and so i was only thinking of the random walk part, treating it as an equivalent problem so that we could forget about A (but this is probably a mistake)
maybe, i will write a quick script for random walk brute force code, to see if n=2 gives 24 ( which is c(2) ), or 20 (which is my formula without the corrective term)
i am getting 20: ideone.com/UwHdfP
 
3:32 PM
whats the challenge of the day now
 
@Min_25 i am thinking that if B contains a 0 then the random walks can be put in 1-to-1 correspondence with the valid solutions, but if B contains no 0 then there are two ways to do that, and it would be provable by considering the boundary (first and last moves) in some way
i mean, two valid solutions for every valid random walk
 
3:48 PM
about the bug which generates more possible errors , how about not declaring variable , and using it in all the line ?
lines*
 
4:11 PM
@Mitch I think it works if a(n, i) is binomial distribution, which is true for odd n (if we consider the symmetry) but not true for even n.
 
@Dennis, codegolf.stackexchange.com/q/51659/194 not a dupe? Seriously?
 
i think whole question is dupe (regardless of answers)
oh i forgot , who cares what do i think
 
Wow, I read that as a single name Jason C, Dennis
 
What is it a dupe of?
 
@BrainSteel codegolf.stackexchange.com/q/1956/194 (See also comments on the new question and on Dennis' answer)
 
4:31 PM
It's pretty close to being a duplicate, yeah...
 
4:46 PM
@PeterTaylor I didn't realize my reopen vote would be binding or I wouldn't have "voted" given the conflict of interest. Still, I'm adamant that it's not a duplicate of the question you linked to, since producing the largest error message and the largest error output (combining all error messages) are two completely different things.
 
21
Q: How Did I Explode A Saucepan?

TasteExplosionI am a complete amateur when it comes to the world of cooking. My recent attempts to teach myself have unfortunately lead to me needing to ask: How did I explode my saucepan? I'd put some garlic/onion/olive oil in the saucepan and left it on low heat to soften on my electric hob. After about f...

5
 
I am fairly sure this wasn't supposed to happen. That's hilarious.
 
He found the base ingredient of grenades .. Onions
 
 
2 hours later…
6:28 PM
the corrective term is related to a bug i made when writing the original dp code; i had for A in 1,-1 instead of for A in ( (1,-1) if N else [a] ), and printing n/2 for that code gives same sequence of numbers (the formula without the corrective term)
 
6:46 PM
@MitchSchwartz I think I have missed something important
could you give me a quick update please?
 
6:56 PM
@Lembik i'm still trying to get to the bottom of proving that my alternate formula is correct, and why the C(n,n/2) term is needed
for even n
 
@MitchSchwartz ah ok.. it was great Min_25 came back to chat I thought
maybe he is thinking about the j=2+ and the joy of X too :)
@MitchSchwartz do you understand his proof now?
@MartinBüttner nice planar graph answer!
 
well C(2n,n) counting 1d random paths is straightforward, but i don't know how i am supposed to be thinking about a(n, i)
 
@Lembik thanks... I really just picked the first thing I found on Wikipedia though
 
@Lembik i can see that it is the same as if(n%2 != i%2, 0, 2*binomial(n,i)) but i don't see how it gives the number of valid A sequences. i guess i could have asked Min_25 but i didn't want to bother him with having to explain things that are supposed to be obvious, if that makes sense
i mean, the number of A sequences with the property he specified
i'm not used to using polcoeffs to solve counting problems, my combinatorics experience is not enough
 
7:13 PM
@Dennis meta.codegolf.stackexchange.com/q/777/194 If there's an existing question, all of whose answers are good answers to the new one, and one of which only requires minor modification to be unbeatable in the new one, then by the standards of this site it's a dupe.
There are sometimes grey areas, but this wasn't one.
 
7:24 PM
@MitchSchwartz mine neither!
 
7:51 PM
Are you guys still trying to understand Min_25's formula?
I think I've understood all of it now so I could make a post if anyone wants to see it
 
ok i had seen this before but forgotten -- you can use e.g. [x^m]( (1+x+x^2+x^3) * (1+x+x^2) * (1+x) ) to find the number of ways to choose m balls if you are given e.g. 3 blue balls, 2 green balls, and 1 yellow ball
@feersum if you feel inclined, sure :)
 
ok
 
8:06 PM
somehow didn't get around to learning about generating functions before
 
gtg for now
 
@feersum thank you
 
@feersum why not edit it into Min's answer?
 
yes seems offtopic answer
 
8:24 PM
@feersum thank you!
@feersum of course now I am going to ask you if you can extend it to j=2 as in my other question :)
@MartinBüttner I have to say.. I am amazed by the quality of work that is happening in relation to my question
 
@Lembik this question of yours , ae you sure of the existence of linear complexity of O(n+n') , that perform desired task ?
5
Q: Longest common substring

LembikThis challenge is about writing code to solve the following problem. Given two strings A and B, your code should output the start and end indices of a substring of A with the following properties. The substring of A should also match some substring of B. There should be no longer substring of ...

 
@Agawa001 absolutely.. I list some methods in the "Useful information" section don't I?
 
and noone cud implement it :D
 
@Agawa001 what do you mean? I even include links to code
 
i see the links , and i see that the most efficient method is arborescent
 
8:33 PM
for golfing the easiest route is to make the suffix array I think I think
@Agawa001 I am not sure I understand
 
trees
 
that is one way.. the other way is the suffix array
which I think will be easier to golf
 
no
suffix array is O(nlog(n))
 
"Section 2 of cs.cmu.edu/~guyb/realworld/papersS04/KaSa03.pdf gives a linear time suffix array construction algorithm and Appendix A has C source code. "
it was first improved to O(n) in about 2003 I think
@Agawa001 I hope the links are useful if you get the chance to follow them
 
@Lembik but i see the code is there (all safe and sound and complete)
it s C++ , at the bottom of the paper
 
8:39 PM
@Agawa001 yes in appendix A
My hope was that would give a good start to what is a hard golfing problem
well.. harder than average :)
 
im just consuling ur rich magazine :D
 
I have no idea what that means!
but thanks anyway :)
 
magazine (list of ur challenges)
 
oh ok
@Agawa001 I hope they are not too painful to look at :)
ur can't be much faster to type than your is it ? :)
 
@Lembik indeed, that was quite impressive. also, that's how I feel about the diamond tilings ;)
 
8:45 PM
@Lembik standards of golfing (i think it came as a habit after few time spent in PPCG)
 
@MartinBüttner I look forward to reading that! But then I already knew Peter Taylor was a genius. I didn't know we had more than one :) I also really like the collaborative effort to solve a hard problem.
(apologies to everyone who is clearly a genius who I have left out by accident)
 
@Lembik an idea crossed my mind about using hash table , do you say that patterns are between 23 and 127 ? or unicode is receivable also ?
 

« first day (1596 days earlier)      last day (3242 days later) »