« first day (314 days earlier)      last day (4635 days later) » 

4:00 PM
Did you really need regexes for that?
 
@RMartinhoFernandes I tried without first, and it worked, but it was ugly as hell.
And since this is only for demonstration purposes, I prefer readability.
 
Maybe cause you did it wrong.
 
> The capacity for dead matter to behave as though it were alive, as expressed in fictional/mystical representations of the "undead", is not known to science at this time.
Seriously.
 
@Xaade I doubt you can do it more succinct without regexes.
 
Science! shakes fist
 
4:01 PM
Try this, have an algorithm loop that finds an opening bracket, search for its matching closing bracket, if it can't find it fail. Then substring, pass it to the recursive call, then after that, look for another opener, and end success if none found.
 
@Xaade How do you search for the matching closing bracket (as opposed to any closing bracket)?
 
@FredOverflow if {, search for }
 
The closest one?
 
You repeatedly replace the strings "{}", "()" and "[]" with the empty string.
 
@CatPlusPlus The closest one in (() is the wrong one.
@RMartinhoFernandes That's exactly what my Java program does...
 
4:03 PM
Repeat until the replacements don't produce a different string.
 
@FredOverflow But you start with the innermost.
 
@RMartinhoFernandes Again, that's exactly what my Java program does.
 
@Fred Oh, I see....
That's easy @Fred, you return the last one that matches the opener you're looking for unless you find an identical of the opener.
 
twitter.com/#!/SashaGrey/status/106936908462034944 I wonder weather there is any scientific base here or this is just another bullshit like most "alternative medicine"
 
For example. If you have this string {}}{} and see the {, return the last } before the next {, unless you haven't found a }.

So in the case of {{}{}, you wouldn't fail yet at the second { because you haven't seen a } yeet.
So the substring { } }{} would be passed to the recursion.
 
4:07 PM
@FredOverflow There: ideone.com/ee4BK . No regexes were harmed during the making of this program.
 
Yeah, replacing {} is easier to code, probably faster too.
 
@RMartinhoFernandes Congratulations, your program does three times as many passes as mine.
 
No regexes!
 
so what?
 
Als
oops i got booted from chat...what did i miss?
 
4:09 PM
14 mins ago, by FredOverflow
Yes I know, Java sucks, but this problem is so much easier to solve with regular expressions.
You picked Java because of regexes!
 
@FredOverflow However, at the same time, I can instantly know what he's doing by reading the code. Regexes obfuscate the intent of the algorithm.
 
Your program is better because it uses C# instead of Java? Because C++ doesn't have a replace method on strings.
 
@Nils I always think people are a bit harsh on acupuncture. I mean, stuff like homeopathy is obviously just BS, but with acupuncture, there's at least some logical cause and effect. You poke someone with a needle, and it's obviously going to stimulate some nerves if nothing else. It may not be as controllable or beneficial as acupuncturists like to say, but at least you're doing something that has a concrete and measurable effect on the patient
 
@FredOverflow I know :( I would have used C++ if it had.
 
Let's face it, std::string just plain sucks.
 
4:10 PM
@Xaade And in Java you have to obfuscate the regexes themselves!
 
Als
@jalf: Acupuncture eh...poking people with needles...if it didn't have that name people would discard it as kinky sex :P
 
@jalf - There was a brilliant article in our local paper once that had the headline "Acupuncture got me pregnant", they missed a trick though with a tag line of "it was just a little prick"
 
@awoodland haha
 
Hey, I've got one too! ideone.com/jgZo1
 
4 mins ago, by R. Martinho Fernandes
No regexes!
 
4:12 PM
@RMartinhoFernandes To me it would depend on whether performance was an issue. If you're just doing one or two, then take the easier to read code route, if you're doing 1000s, then use the regex.
 
@RMartinhoFernandes Except, of course, for the fact that most people want to allow other "stuff" than just the parens, so (for example) a*(b+c) will show as "matched". In most cases to be at all useful, you also need to be able to ignore them under some conditions, so (for example) contents of strings won't count.
 
@JerryCoffin at that point you have to look at whether my inwards method is better or not.
 
Anyway, here is an O(n) solution that uses a stack, and that's what @Mahesh was originally asking for, right?
 
4:14 PM
@JerryCoffin I suggested using a stack back there.
Now you had no excuse for using Java!
Heresy!
 
@FredOverflow I like mine better. :P
Also, what the hell.
 
@RMartinhoFernandes I like to post Java solutions in C++ chat rooms so pupils at least have to translate the program into C++ on their own.
 
Yeah, right.
 
@FredOverflow Stacks work, but I like mine better. It would actually parse the order of ops at the same time.
 
Also, Eclipse was already loaded ;)
 
4:16 PM
Is bombing random rooms with unrelated questions already passe?
And now they're inviting random people to private rooms for that?
 
Als
Anyone of you wise folks would like to review this? I have not had any real good comments on this just lot of downvotes(on the answer), which makes me feel something is wrong in the answer or missing, comments to make it correct/better are appreciated really.
14
Q: How should I write ISO C++ Standard conformant custom new and delete operators?

AlsHow should I write ISO C++ standard conformant custom new and delete operators? This is in continuation of Overloading new and delete in the immensely illuminating C++ FAQ, Operator overloading, and its follow-up, Why should one replace default new and delete operators? Section 1: Writing a sta...

 
So you could actually math op on a string my way
 
@CatPlusPlus You're obviously a WCF expert.
 
I don't even know what that is.
 
do you people often need to write custom new/delete operators? I seriously can't remember the last time I saw a reason to, but maybe I'm missing out
 
4:17 PM
just out of curiosity (which is pretty much the only reason for me to try out cool language features)
 
@jalf unmanaged unstructured memory.
 
@FredOverflow - Thanks for the stack based solution.
 
@CatPlusPlus Windows Cat Foundation.
 
if you're structuring memory with an algorithm or by understanding user input, custom new and delete may be useful.
 
Haha, I got downvote on that singleton answer.
Singleton lovers are about.
 
4:21 PM
@jalf I've written more allocators than new/delete operators
 
@FredOverflow - Perfect solution using "stack". I didn't think of it ;)
 
@CatPlusPlus which singleton question?
 
0
Q: What is wrong with this singleton?

PaulCurrently I'm using a rather simplistic implementation of a singleton. However, I've never seen anything like this suggested on the web, which leads me to believe there might be something wrong with it... class Singleton: def __init__(): raise ... @staticmethod def some(): ...

 
Als
@jalf: For diagnostics.....but not in production code
 
@CatPlusPlus So which are more dangerous: zombies or singleton lovers?
 
4:22 PM
@JerryCoffin Singleton lovers.
 
I just quickly scrolled down, and by the wiki links and other stuff...
YOU GUYS ARE WEIRD
 
What's wrong?
 
nothing
 
Als
@hexa: huh
 
@hexa Of course -- we wanted you to feel welcome and at home here...
 
4:24 PM
@hexa Did you see my userscript yet?
 
2
Q: How to see lowered c++

RecessionConeI'm trying to improve my understanding of how C++ actually works. Is there a way to see how the compiler lowers my code into something simpler? For example, I'd like to see how all the copy constructors are called, how overloaded function calls have been resolved, all the template expansion and...

 
If you want weird.
 
@hexa upboat and pile of?
@JerryCoffin <3
 
Als
@RMartinhoFernandes: Lowered sounds like Below the belt :P
 
I love that the "promotional code" from the dev days ad makes it so easy to guess how to get higher discounts
 
Als
4:26 PM
what do you guys think about this
1
Q: How does this code to forbid inheritance work?

sharptoothI found some rather strange code: class Base { public: virtual bool IsDerived() const { return false; } }; class Derived : public Base { public: bool IsDerived() const { return true; } }; Derived* CastToDerived( Base* base ) { // private and protected inheritance from Derived is pr...

strange Question I think
 
Seems totally pointless.
 
Als
@RMartinhoFernandes: glad someone spoke
i thought everyone ran away!
 
I was trying to convince myself I wasn't missing something
but there's definitely something strange in that neighborhood.
 
Als
@awoodland: Yeah, well i posted the answer and then thought since no one seems to get that, I was thinking i made an ass of myself
okay din din time for me....you guys don't you break anything i will be back!
 
@Fredoverflow - One more question. Can I ?
 
4:33 PM
@Als I'm playing security analyst today -- breaking things is my job. Enjoy your supper.
 
Ok. I am having an integer array. How could I find the least combination of numbers that would lead to a given sum ?
Any algorithm ?
 
In computer science, the subset sum problem is an important problem in complexity theory and cryptography. The problem is this: given a set of integers, is there a non-empty subset whose sum is zero? For example, given the set { −7, −3, −2, 5, 8}, the answer is yes because the subset { −3, −2, 5} sums to zero. The problem is NP-complete. An equivalent problem is this: given a set of integers and an integer s, does any non-empty subset sum to s? Subset sum can also be thought of as a special case of the knapsack problem. One interesting special case of s...
 
That is known as the knapsack problem.
The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the count of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most useful items. The problem often arises in resource allocation with financial constraints. A similar problem also appears in combinatorics, complexity theory...
Okay, here is another solution to the balanced parenthesis problem:
isBalanced input = isBalanced' input []

isBalanced' [] [] = True
isBalanced' [] _ = False

isBalanced' ('(':input) stack = isBalanced' input (')':stack)
isBalanced' ('[':input) stack = isBalanced' input (']':stack)
isBalanced' ('{':input) stack = isBalanced' input ('}':stack)

isBalanced' _ [] = False

isBalanced' (i:input) (s:stack) = (i == s) && (isBalanced' input stack)
 
@Mahesh The short answer is that the only known way to get the best answer is to try every possible combination and pick the best one.
 
@FredOverflow Why does markdown let me down again?
 
4:44 PM
@FredOverflow Because that's its primary reason to exist! :-|
 
Anyway, 8 lines of code. Can anyone beat Haskell? :)
 
@Jerry mentioned SNOBOL above.
 
@FredOverflow SNOBOL4: BAL(string) : s(balanced)
 
Come on, that's cheating, right? ;)
 
Als
Ok back
and what did ya all break?
 
4:54 PM
@JerryCoffin Ok
 
@FredOverflow Okay, if you don't like that, perhaps a version in J would be better: checkBalanced =: _1 -.@e. bracketDepth.
 
ouh ce Knapsack problem.. I studied that a while ago.. but forgot how we solved it.. and how the method was called..
 
@Nils A* is probably the most common for a solution that balances reasonably good results with getting done in a reasonable period of time...
 
we did something simpler.. humm but it doesn't come into my mind
probably too tired anyway
 
5:29 PM
@Mahesh Here is a solution in Haskell:
import Data.List (subsequences, sortBy)
import Data.Function (on)
solve target = sortBy (compare `on` length) . filter (\x -> sum x == target) . subsequences
> solve 8 [1, 2, 3, 4, 5]
[[3,5],[1,3,4],[1,2,5]]
 
@FredOverflow - Thanks for the solution.
 
Confidentiality statement: This message is intended for the intended recipient only.
WTF?
 
Oh .. It means .. Welcome To Facebook
 
@Mahesh Oh wait, you don't actually need the lambda:
import Data.List (subsequences, sortBy)
import Data.Function (on)
solve target = sortBy (compare `on` length) . filter ((== target) . sum) . subsequences
 
@FredOverflow Pretty.
I'm working on a Bra*nfuck solution.
:)
 
5:33 PM
@RMartinhoFernandes Why are you censoring the i instead of the u? :)
 
@FredOverflow - I am intended to know the algorithm. To the interviewer I can't give a solution, that uses library algorithm. I amn't sure though.
But thank you for your help and wiki link
 
@Mahesh Can you choose the language?
 
Ok. It's one of the Amazon interviews question.
So, probably interviewer expects to say the algorithm
than for the language of implementation.
But C++, Java is preferable. And I am fond of C++ :)
@FredOverflow - Messages were intended to you
 
hi
 
hi
 
5:43 PM
@Mahesh Have you touched template meta-programming yet? ;)
 
@FredOverflow - No
I think I have to improve alot
 
Don't worry, you won't need template meta-programming in your day-to-day work.
Unless your name is Stephan T. Lavavej ;-)
 
@FredOverflow Luckily I amn't. But wish to be him one day :)
@FredOverflow - Time complexity of your Haskell solution ?
 
sbi
@FredOverflow OTOH, std::string is almost indefinitely better than everything we had before.
@FredOverflow You say tomato...
My take on "Is the C programming language still used?"
 
I really hope Herb Sutter does another GoTW series now C++11 is finalised
 
sbi
5:56 PM
@awoodland Such things had their time and their place, and when that time or place is gone, there's nothing you can do to get them back, and even if you try, it will never be the same. However, that doesn't mean there can't be something else just as good.
 
@Mahesh O(2^n)
@sbi Were there any attempts to improve std::string after the first standard?
@sbi Aren't C, C++ and C# basically the same language? ;-)
 
@FredOverflow I can't think of any improvement that doesn't consist in making the class not as bloated. That wouldn't be backward compatibility friendly however.
 

« first day (314 days earlier)      last day (4635 days later) »