Ad
  • Custom User Avatar

    You may be right, but I like to avoid boilerplate whenever possible. In my opinion it enhances readability to use situational syntactic sugar like this: because it can only be used in certain circumstances, its use highlights that you are in those circumstances.

  • Custom User Avatar

    Perfectly servicable and efficient. Wouldn't best practices encourage adding a return line? Obviously not necessary for such simple code.

  • Default User Avatar

    Two ways to calculate avg. expense: 1. sum up all the expenses then take average; 2. take average over differce of balances from start to the end.

    It seems only the second way works, but why the first one not? due to precision issue?? With R, it matters when rounding. Should this be mentioned somewhere in the description?

  • Default User Avatar

    I had the same problem like yours...no clue

  • Default User Avatar

    What is the rule for rounding here? I tried many rounding methods. I have no idea why 45.525 is expected to 45.53, while 45.105 is expected to 45.10???

    I used %.2f with sprintf in R. I am going mad with the rule ........

  • Default User Avatar
  • Custom User Avatar

    ifelse is a vector operator, so you should probably use:
    break_chocolate <- function (n, m) {
    ifelse(min(m,n)==0, 0, m*n-1)
    }

    and the function will return for every pair of elements from each vector!

  • Default User Avatar

    Then forget about my question. Thank you all the same :). Mine is just a suggestion to make things harder, since that might be related to the parse/deparse of expression in the input.

  • Default User Avatar

    I am sorry but I don't see very well your problem. When in R the input is 0.67 it is 0.67; it's not the result of an operation with large decimals. If you want you can toString(it).

  • Default User Avatar

    I mean, 0.67 as input might be either a result rounded from others with large decimals or just 0.67 itself. When it is written as "0.67", then it can only interpreted as 0.67, as parsed input for different languages.

    I see there is a package that can take care of making a decimal into the fractional manner. For practice purpose, I guess it might be better not to use additional packages to pass the task (making task more complex a bit :P)

  • Default User Avatar

    can refer to exact the one as unique

    I don't understand what you mean and what your problem is. Note: in R there are packages which use rational...

  • Default User Avatar

    Thanks for fast reply!

    One more thing, I guess there might be a concern of precision of decimal as input for different languages, and hence a string input (e.g., "3/4" or "0.67", instead of 3/4 or 0.67) can refer to exact the one as unique. How do you think? :)

  • Default User Avatar

    Sorry, I will add something in the description for R.
    In R the input is a rational or a decimal, the output is a string.
    Examples: dotest(3/4, "1/2,1/4") or dotest(12/4, "3") or dotest(0.67, "1/2,1/6,1/300").
    Thanks for your post.

    PS: I modified the description. Is it clearer for you?

  • Default User Avatar

    Which format of output should be with R language? It seems, for example, the string "1/2,1/4" as output does not work.
    Also, it is mentioned the input is a string, but the test example gives it as numeric, which is confusing