• (disco) in reply to NedFodder
    NedFodder:
    Oh great, it's started. How long until we see GolfScript and Brainf*ck?

    Nothing can beat jsFuck, only Discourse. Tried to paste this code converted to JsFuck:

    function reverse(s) {   return s.split('').reverse().join(''); } alert(reverse("JsFuck is TRWTF!!!"));
    

    But it was almost 100000 characters, exceeding the maximum post length 3 times.

    Check it out here: http://www.jsfuck.com/

  • (disco) in reply to NedFodder
    NedFodder:
    Oh great, it's started. How long until we see GolfScript and Brainf*ck?

    I swear when I read the article in my reader the source code was in brainf*ck. probably a joke Remy put in. I was hardly impressed to see it was horrible VB instead.

  • (disco) in reply to Gaska

    https://github.com/golang/example/blob/master/stringutil/reverse.go

  • (disco)

    Scala stolen from StackOverflow:

    def reverse(s: String) = ("" /: s)((a, x) => x + a)
    
  • (disco) in reply to ben_lubar

    My favourite thing about Ben's golang snippets is the oneboxer doesn't even get to the code.

  • (disco) in reply to trithne

    https://github.com/golang/example/blob/master/stringutil/reverse.go#L18-L27

  • (disco) in reply to accalia
    accalia:
    enterprise‽

    ENTERPRISE‽

    Enterprise: [image]

  • (disco)

    These days, I'd have half a mind to write a string on a piece of paper, and then turn the paper upside down on the desk and say "Done."

    Followed by, "I feel uncomfortable working with a company who cannot come up with a good password hashing algorithm, and especially one that wants me to implement it by hand."

  • (disco) in reply to ben_lubar

    Go's not one-liner? Lame.

  • (disco) in reply to Gaska

    http://play.golang.org/p/MZcvgGLF_P

    func reverse(s string) string {
    	o := make([]rune, utf8.RuneCountInString(s))
    	i := len(o)
    	for _, c := range s {
    		i--
    		o[i] = c
    	}
    	return string(o)
    }
    
    func main() {
    	fmt.Println(reverse("The quick brown 狐 jumped over 💛 the lazy 犬"))
    }
    
  • (disco) in reply to riking
    riking:
    make([]rune, utf8.RuneCountInString(s))
    Da majigs.

    Still, using a function doesn't count as one-liner unless it's in standard library.

  • (disco) in reply to Gaska

    It's basically the same as new char[strlen(s)], except with 32-bit chars (no surrogate pairs!) and a unicode-correct strlen.

  • (disco) in reply to riking

    I know what it is. I'm just saying the name is stupid. Especially that everyone else calls it code points.

  • (disco) in reply to vita10gy

    I was given this exact same question when I was interviewed for a job I recently started.

    The interviewers know that there are built in functions for this and they know that you know this as well (and tell you not to use them).

    This test is not designed to prove your knowledge of a language or a framework. It's about proving that your mind can handle the thought process to write them should they not exist.

    String reversing is still probably a bad example because most languages will already have a function for it, but chances are you will need to write code in your job which which is way more complex for which no function currently exists.

    This is what the test is for.

  • (disco) in reply to NedFodder
    NedFodder:
    I bet Discourse would have taken an MD5 hash of the string and used a ***rainbow*** table to find the reversed string.

    I'm fairly certain rainbows wouldn't have anything to do with it.

  • (disco) in reply to SimpleSimon
    SimpleSimon:
    The interviewers know that there are built in functions for this and they know that you know this as well (and **tell you not to use them**).
    Do I have to wind up my own string class too? And my own stdout printer? What about font renderer? Window decorations? Assembly language? Transistors?
  • (disco)
    <?php
    
    /**
     * Returns a string containing the characters of the input string in
     * reverse order. Null is returned on invalid input.
     * 
     * @param string $input the string to reverse.
     * @return the reversed string or null if the input is invalid.
     */
    function reverse($input)
    {
        if ($input === 'ABCDE')
            return 'EDCBA';
    
        return null;
    }
    
  • (disco)

    On an unrelated note: WTF Discourse keeps cycling between comments #3, #7 and #8 on my tablet. Had to use my computer to read the reactions (and post this rant).

    OT: I think his solution is actually a nanosecond faster in execution than e.g.

    -join[regex]::Matches('abcde',".",'RightToLeft')

    Optimized code, what more do you want!

  • (disco)

    I'd post the solution in Unary, but it would probably go over the character limit for a post

  • (disco) in reply to Jaloopa
    Jaloopa:
    Unary

    That's insane...

  • (disco) in reply to Keith

    When golfing Unary code, it's not uncommon to remove 10100 characters

  • (disco)

    I'm sorely tempted to give them a recursive algorithm (please excuse quasi-PL/1 pseudocode syntax):

    reverse: function(string) returns char(*) if length(string)=0 then return '' else return reverse(substr(string,2)) || substr(string,1,1)

  • (disco) in reply to PJH
    PJH:
    I'm fairly certain rainbows [wouldn't have anything to do with it][1].

    I already hated clowns before I saw that picture. Now I've lost my appetite for breakfast. Thanks.

  • (disco) in reply to NedFodder

    You're welcome.

  • (disco) in reply to Jaloopa

    Wow, you managed to find a domain that's blocked here (for being a dyndns provider, if I read the error correctly).

  • (disco)

    Found an interesting bit of Discomath relating to this:

    http://i.imgur.com/qObKGfx.png

    In creating this, I forgot that that check means, can award to a single person more than once.

    That's more of a Discobehavior

  • (disco) in reply to JazzyJosh
    JazzyJosh:
    Found an interesting bit of Discomath relating to this:

    that's not is the badge awarded multiple times IIRC. that's can the badge be awarded multiple times....

  • (disco) in reply to accalia

    2 slow 4 my edit

  • (disco) in reply to JazzyJosh
    JazzyJosh:
    2 slow 4 my edit

    hmm.... but who hanzo'd whom?

    your edit hadn't loaded on my page when i posted mine. :-P

Leave a comment on “Backwards Interview”

Log In or post as a guest

Replying to comment #:

« Return to Article