Ad
  • Custom User Avatar

    upd: OMFG I did it! I fucking did it!!

    So, after creating those posts I decided to take a break and went to read "The C Programming Language" by Kernighan & Ritchie and suddenly I got reminded that strlen() function reads through the whole string in order to find out it's length. That got me thinking: "Hmm... My program is actually using this function every time it has to translate a bit of BF code into C code... Hmm... AM I SURE, this is the right thing to do, concidering input size can reach up to a million characters? ABSOLUTELY FUCKING NOT!!" So I went back to my stack solution and refactored it to calculate C code idx using log10 for the character length of counts.

    After that, my timeouts were gone! But now it would fail on super_input 8, so I did some investigation by compiling and running a local version of this code — it gave me a Segmentation Fault, so I figured out the only way this could happen is if I didn't allocate enough space for resulting C code string. So I raised the size of the buffer and voilà! All green! Wo-hooooooow! I feel like such a hacker now... :)))

    (I'm only using static size array to avoid millions of realloc-s, but will see if I can make it dinamic since it only takes 3 seconds to run my code now.)

  • Custom User Avatar

    By the way, how many tests are there? Maybe there is a way to optimize one of my solutions to pass it? I tried to modify the stack to use a doubly linked list so I don't have to reverse it but that caused it to crash on (*root)->prev = stack_node; somehow. Weird...

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Tried two different approaches — both of them pass 53 tests and then timeout (super_input 6 of 6).

    For anyone considering solving this kata: this is NOT A 4kyu KATA! It seems like the only way to solve it and not get a timeout is to somehow transpile the whole thing on the fly in one pass — something that should have been mentioned in the description. :|

    I'm gonna post both of my solutions in comments to this post just in case...

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Do I get a "Silent Assassin" tho? ))

  • Custom User Avatar

    Nice kata! I finally managed to solve it in a clean concise way... :)

  • Custom User Avatar

    The problem was with my countK() implementation - for some reason it caused the random test cases to check against wrong values for puzzle, I've unlocked the solutions and used g964's one instead. But luckily it should be fixed now!

  • Custom User Avatar

    Thanks! I am at peace now... )))

  • Custom User Avatar

    Good question! Good question indeed... ))

  • Custom User Avatar

    It's funny how you managed to guess the language just by reading a short problem description... Yes it was indeed C! This demonic language somehow always finds new ways to screw with my head... ((

  • Custom User Avatar

    Can someone please explain to me why we can't change the input string (strng) and have to create a duplicate? It's not passed as const. I was very "surprised" to find out that my program kept crashing not because of some logical error in one of the functions but because the input string was read-only...

  • Custom User Avatar

    Holly shit! And here I thought my solution was smart... Mad props to you man!

  • Custom User Avatar

    I know I'm pretty much going to hell for these nested ternaries...

  • Loading more items...