Ad
  • Custom User Avatar

    I submitted the solution above and one slightly refactored variation 9 years ago. I definitely did not copy from StackOverflow and I claim my solution original. I have no idea how a number of people came up with the exact solution of mine. Note that you can see other solutions once you solved a kata. Interestingly many of the accounts above where suspended.

  • Custom User Avatar

    It does not matter. Any modern C compiler can optimize abs(x) and x < 0 ? -x : x equally. gcc 12 compiles both into the exact same code sequence.

    sh-5.2$ cat foo.c
    #include <stdlib.h>
    
    int f(int x) {
      return abs(x);
    }
    int g(int x) {
      return x < 0 ? -x : x;
    }
    
    sh-5.2$ gcc -O2 -S foo.s
    sh-5.2$ cat foo.s
    .file	"foo.c"
    	.text
    	.p2align 4
    	.globl	f
    	.type	f, @function
    f:
    .LFB11:
    	.cfi_startproc
    	movl	%edi, %eax
    	negl	%eax
    	cmovs	%edi, %eax
    	ret
    	.cfi_endproc
    .LFE11:
    	.size	f, .-f  
    	.p2align 4
    	.globl	g
    	.type	g, @function
    g:
    .LFB14:
    	.cfi_startproc
    	movl	%edi, %eax
    	negl	%eax
    	cmovs	%edi, %eax
    	ret
    	.cfi_endproc
    .LFE14:
    	.size	g, .-g
    	.ident	"GCC: (Debian 12.2.0-14) 12.2.0"
    	.section	.note.GNU-stack,"",@progbits
    
  • Custom User Avatar

    No expensive at all in the grand scheme of things. This is Python, it is slow to begin with.

  • Custom User Avatar

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

  • Custom User Avatar

    It does not matter. In python there is only one integer 0. -0 and 0 is the same thing.

  • Custom User Avatar

    sqrt() is computed using floating point is prone to precision error. Without round(), int() just truncates the result. If you result of sqrt is 1.9999999, int(1.999999) will be 1 instead of 2.

  • Custom User Avatar

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

  • Custom User Avatar

    Test case is broken: In 'The quick br----he lazy dog', the first part is 12 characters and the second 11 characters. The question says that the second part should be longer if glue cannot be place exactly in the middle.

  • Custom User Avatar

    function names in python answer template and test template are not the same.

  • Custom User Avatar

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

  • Custom User Avatar

    Instructions say "increases by a fixed 0.5 percent at the end of every two months."

    but that example have rate of loss changing by 0.5% every month:

    "End of first month percent of loss: 1, end of second month percent of loss 1.5, end of third month still 1.5, end of 4th month 2 and so on ..."

    Please fix either one.

  • Custom User Avatar

    Python test case and uses get_num but code template uses getNum.

  • 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

    Is the submission test broken:

    Falsifiable (after 3 tests and 4 shrinks):
    expected: Just 0
    but got: Nothing
    [0]
    Positive {getPositive = 1}
    -1

    -1 is not valid and I expect Nothing is the correct answer instead of Just 0

  • Loading more items...