These are chat archives for Codewars/codewars.com/kata-solving-help

3rd
Mar 2017
Marc KesslerWenicker
@MSKW76_twitter
Mar 03 2017 00:20
@jhoffner got a question about the dvdrental sql kata... downloaded the files for the tutorial and extracted the file and it's a bunch of .dat files which I'm not sure I can import on a mac (new mac user here) and google isn't helping much. A psql dump should be platform independent I thought but running this:
psql dvdrental < restore.sql results in a bunch of ERROR: could not open file "2177.dat" for reading: No such file or directory allthough I'm running from within the directory where I extracted the files to. Any idea and apologies for the silly question.
the tables get created though...
actually, just found a lead googling the problem again in a slightly different form.
Marc KesslerWenicker
@MSKW76_twitter
Mar 03 2017 00:40
@jhoffner figured it out, sorry for the direct ping
zardoxnet
@zardoxnet
Mar 03 2017 01:40

I need help with the Kata "Simple Fun #111: Reverse Brackets" I am trying to solve using PHP. Using the preg_replace_callback function to recursively find and replace the string found within the innermost parentheses and return what is inside that reversed and then move to the next outer most parentheses and reverse and return that.. and so on The parens is not to be included in output. For example: reverseParentheses("a(bcdefghijkl(mno)p)q" gives apmnolkjihgfedcbq. What I have now is the code returns ap)onm(lkjihgfedcq

1 new message since 3:07 AM on February 17th
Mark as read (esc)Mark as read
Channel #programming

Johnny
@JohnnyBizzel
Mar 03 2017 01:40
@zardoxnet that's a cute avatar!
zardoxnet
@zardoxnet
Mar 03 2017 01:40
Where I am at is the following solution: function reverseParentheses($s) { $regex = '#\([^(](.+)\)#'; if (is_array($s)) { $s = strrev($s[1]); } return preg_replace_callback($regex, 'reverseParentheses', $s); }
Johnny
@JohnnyBizzel
Mar 03 2017 01:42
@zardoxnet this is the JavaScript room not the PHP room!
zardoxnet
@zardoxnet
Mar 03 2017 01:43
it would probably be easier to solve in javascript. I am trying to brush up on doing things in PHP. Sorry I did not realize this was for questions on Javascript only... the room just stats it is for "kata-solving help"
Johnny
@JohnnyBizzel
Mar 03 2017 01:43
@zardoxnet sorry my mistake!
I jumped rooms.
@zardoxnet And sorry, my level of PHP is not that advanced!
zardoxnet
@zardoxnet
Mar 03 2017 01:47
It appears that all languages are lumped together into "kata-solving help"... I do not see a separate "codewars.com kata-solving help in PHP" room... is there one?
Where I am at is the following solution:
function reverseParentheses($s)
{
    $regex = '#\([^(](.+)\)#';
    if (is_array($s)) {
        $s = strrev($s[1]);
    }
    return preg_replace_callback($regex, 'reverseParentheses', $s);
}
Johnny
@JohnnyBizzel
Mar 03 2017 01:50
@zardoxnet what is the challenge? That link just goes to issues.
zardoxnet
@zardoxnet
Mar 03 2017 01:50

Simple Fun #111: Reverse Brackets

You are given a string s that consists of English letters and brackets. It is guaranteed that the brackets in s form a regular bracket sequence.

Your task is to reverse the strings in each pair of matching brackets, starting from the innermost one step by step(remove the brackets at the same time).

reverseParentheses("a(bcdefghijkl(mno)p)q" gives apmnolkjihgfedcbq. What I have now is the code returns ap)onm(lkjihgfedcq
Johnny
@JohnnyBizzel
Mar 03 2017 01:52
That link doesn'twork. This is what I am seeing http://www.codewars.com/kata/all-i-needs-a-platform-man
Johnny
@JohnnyBizzel
Mar 03 2017 01:53
found it with google
@zardoxnet I am rubbish with regex. What is it doing?
zardoxnet
@zardoxnet
Mar 03 2017 01:59
My code now...for the call reverseParentheses("a(bcdefghijkl(mno)p)q" returns ap)onm(lkjihgfedcq
It should be "apmnolkjihgfedcbq" but for some reason the regex is grabbing the parens of the innermost parens
zardoxnet
@zardoxnet
Mar 03 2017 02:51
I could not get it to be recursive... so I used a while loop, which is not ideal but I passed.
function reverseParentheses($s)
{
    while (strpos($s, '(') !== false && strpos($s, ')') !== false) {
        $s = preg_replace_callback('/\(([^(|).]+)\)/', function ($m) {
            return strrev($m[1]);
        }, $s);
    }
    return $s;
}
zardoxnet
@zardoxnet
Mar 03 2017 02:57
It seems many of the other coder's solutions also used a while loop, and I did not see anyone solve it with just regex and recursion.
FlashHero
@FlashHero
Mar 03 2017 20:17
function findOdd(A) {
for(var i=0; i<A.length; i++){
if(A.indexOf(A[i])===A.lastIndexOf(A[i])){
return A[i];
}
}
}
FlashHero
@FlashHero
Mar 03 2017 20:30
Given an array, find the int that appears an odd number of times.