Speed Coding 2016 – Q2 Solution


20 July 2016, by

This post explains the solutions to Question 2 of our speed coding 2016 competition. If you haven’t yet read the question, head back and have a go now.

The quickest answer that came through to this question was from Matthew Richards (again). He solved the problem in 15:55 and used C#. Here’s his solution:

    private static void Main(string[] args)
    {
      var icon = (Bitmap)Image.FromFile(@"c:\test\OldGooglePlus120x120.png");

      for (int x = 0; x < icon.Width; x++)
      {
        for (int y = 0; y < icon.Height; y++)
        {
          var oldColour = icon.GetPixel(x,y);
          var newColour = Color.FromArgb(GetAlpha(x - icon.Width/2, y - icon.Height/2), oldColour.R, oldColour.G, oldColour.B);
          icon.SetPixel(x, y, newColour);
        }
      }

      icon.Save(@"c:\test\Output.png");
    }

    private static int GetAlpha(int x, int y)
    {
      int count = 0;

      for (int i = 0; i < 16; i++)
      {
        for (int j = 0; j < 16; j++)
        {
          var calc = Math.Pow(Math.Abs((x + (i/16.0)) / 60.0), 5) + Math.Pow(Math.Abs((y + (j/16.0)) / 60.0), 5);
          if (calc <= 1) count++;
        }
      }

      return Math.Max(count - 1, 0);
    }

This question was solved in more or less the same way by everyone, so you likely also completed it in a similar way (let us know if not!)

If you managed to complete this problem in under 20:09, then you would have placed in our top 5!

Tags: , , ,

Categories: Social, Softwire, Technical

«
»

Leave a Reply

* Mandatory fields


7 − = one

Submit Comment