last day (19 days later) » 

2:49 PM
room topic changed to Chat minigolf: Current problem: checkio.org/mission/brackets (no tags)
room topic changed to Chat minigolf: Codegolf mini-puzzles! (no tags)
room topic changed to Chat minigolf: Participate in codegolf mini-puzzles together! (no tags)
Current problem: checkio.org/mission/brackets . Function or program okay (function need not be named "checkio"). Return truthy/falsy value.
Hello! I'm going to get coding :P
 
3:06 PM
Should we work in the same language? (Also I'm a bit busy, won't be super responsive :p )
 
Ahaha well initially what happened was grc, xnor and I were golfing down the same few Python solutions. I'm not sure if everyone knows Python though
 
I know it well enough ;p
 
But I thought if someone didn't know Python did, say, CJam, then people who didn't know CJam could learn a bit of that
def B(s):
 S=[""]
 for c in s:
  if c in "{([":S+=[{"{":"}","(":")","[":"]"}[c]]
  if c in "})]":
   if c != S[-1]:return 0
   S.pop()
 return len(S)<2
Ahaha that's so ungolfed - is there something better than a dict for Python?
 
I was trying
Using a string with both sets of brackets
And checking if .find() % 3 was the same
 
Oooh interesting
 
3:20 PM
It's pretty long and I don't think it works with something like "(asdf" but... :P
oh, no formatting :/
def c(s,S=[],b='{[(}])'):
    for C in s:
        if C in b:S+=C
    while S:
        if b.find(S[-1])%3==b.find(S[-2])%3:
            S.pop();S.pop()
        else:return 0
    return 1
 
Hmm I've always wondered - does PPCG have some sort of rule that your function should work find on consecutive runs?
Because otherwise the mutable default argument might be a problem
 
Huh, I have no idea :P
 
Oh wait you're using += ... I think that creates a new list?
 
I don't think it changes anything here, though (size length)
 
Hm k
 
3:24 PM
Also it does break on second run :P
 
Ahaha damn
 
Actually it's behaviour is quite funny
 
I think you could probably do something like if b[b.find(S[-1])%3]==S[-2]:
 
Since the list is emptied when it succeeds, it works if the previous answer was true :P
Also that's smart
 
:P so you only need to clear the list before the next run! :D
 
3:27 PM
Hrm, not working...
 
Well that makes this 144:
def B(s):
 S=[""];Q=")]}([{"
 for c in s:
  if c in"{([":S+=[Q[Q.find(c)%3]]
  if c in"})]":
   if S[-1]!=c:return 0
   S.pop()
 return len(S)<2
 
Oh, I had bug >_<
 
Ah D:
 
I forgot I was running the check at the end, not as I got them :P
 
:P
 
3:34 PM
Also, what's up with the len(S)<2?
 
There's an empty string at the base of the stack
So all match = len 1, remaining bracket = len 2
(basically so I could do S[-1] without worries)
 
this problem sounds like a job for a .net regex
 
Ahaha can you use regexes in a short way in .NET?
 
Test cases from CheckIO: pastebin.com/vRbMLAjm
 
3:41 PM
@Sp3000 for the purposes of PPCG regex-only answers would be valid
 
Well I mean, how do you invoke regexes in .NET? I'm assuming it's not import re :P
(never used .NET so I don't know what a full program looks like)
 
yes, of course, if you actually do it in .NET, it's quite a lot of boilerplate characters... but if this was a PPCG challenge, I'd answer with only the regex.
you'd need a class, and a function inside
 
Ah k :o
Didn't think of regexes, maybe that's even shorter in Python
... maybe PCRE (I don't think Python can do recursion...)
 
either that or balancing groups
but recursion is probably shorter
 
Hmm I'm not sure how to collapse the three types of brackets together though
 
3:54 PM
Warg formatting
def c(s,S=[],b='{[(}])'):
 for C in s:
  i=b.find(C)
  S+=C*(i>-1)
  if i>3:
    if b[b.find(S[-1])%3]!=S[-2]:return 0
    S.pop();S.pop()
 return not S
 
Seems to fail on {[(3+1)+2]+}
 
Rats, and I had just got it to 131 ;p
 
:P
My regex is at 95 chars and it's half broken :(
 
I feel incredibly dumb.
i> 2
def c(s,S=[],b='{[(}])'):
 for C in s:
  i=b.find(C)
  print i
  if i>2:
    if b[i%3]!=S[-1]:return 0
    S.pop()
  else:S+=C*(i>-1)
 return not S
131 bytes I think
 
You left a print i in there :P
But it seems to work (huzzah)
 
4:08 PM
XD
Hrm, it might not work for "})]" or something...
Yeah
 
Ah list index
I'll add that to the cases :P
 
Ok, just add an and S to the i>2 line
I think that should fix it..?
 
Each run isn't independent I'm finding :/
(Funny thing is })] sometimes passes due to a bracket left in by the last run)
 
XD
I pass all of these (on the first run ;) ):
h="((5+3)*2+1)"
i="(3+{1-1)}"
j=']]()'
k='{[(3+1)+2]+}'
 
Hmm well... this is awkward. I can't use anchors for a recursive regex
 
4:13 PM
(By pass I mean get correct answer...)
 
(same way I used the word pass :P)
@MartinBüttner Is there a way in PCRE to match something iff there's something already in a specific group?
Oh (?(1)yes|no), same as Python it seems
 
4:31 PM
regex101.com/r/yN3yJ0/2 how to anchor :/
So it's about 4am over here so I should probably head off to sleep :) Will see if I can get some progress tomorrow
Also @FryAmTheEggman I'll do the function thing later for square roots, my brain hasn't been working well today and I'm still not quite convinced xnor's suggestion's correct ( though I'm pretty sure it is)
 
 
5 hours later…
9:18 PM
@Sp3000 yes.
@Sp3000 wrap everything in ^(...)$. replace (?R) with (?1)
 
Wow, that get 55.
Nice :)
 
it can also be shortened at the cost of efficiency
unrolling the loop is nice for that, but it requires you to double the negated character class
 
9:52 PM
40 bytes:
^(([^][(){}]|\((?1)\)|\[(?1)]|{(?1)})*)$
might be possible but hard to beat with CJam
 
10:07 PM
That's tiny! Nice :)
I have to go now, hopefully this room doesn't totally die, it was fun :)
 

  last day (19 days later) »