Sherlock and The Beast

  • + 0 comments

    Why mix output logic with determination of x and y?

    Why use loops to build string (or Stringbuilder)? Obfuscates code.

    Here is my solution:-

      static void decentNumber(int n)
    {
        int x = 0;
        int y = 0;
        for (int i = n; i >= 0; i--)
        {
            if (i % 3 == 0 && (n - i) % 5 == 0)
            {
                x = i;
                y = n - i;
                break;
            }
        }
    
        var res = y == 0  && x==0? "-1" : new string('5', x) + new string('3', y);
        Console.WriteLine(res);
    }