Saturday, 27 September 2014

Euler 3

Quite challenging as you cannot brute force a solution, I tried, the solution takes a long time to run. Had a go with TDD for a change, actually made it easy to think the problem through, even though I came up with the wrong answer. My solution would only work when the largest prime is less than the square root of the argument value. Solution

Easiest solution to implement for me was trial division algorithm is implemented on the page in python this is easy to convert to C#. Implemented in the tests this took 1-11ms to run which isn't bad considering the numbers magnitude, 600851475143.

Lists and enumerable range types do have a limit in their sizes which isn't too bad, I was playing around the idea of a linq solution which I think would work for smaller numbers.

Trying to keep a clear head and getting out I went to the zoo.

red panda in enclosure with trees, panda is sat on wooden box

Sunday, 21 September 2014

Interviews are hard

The topic of software development is vast, trying to get everything together to at least make sure I know what I know. 

I did get asked about SOLID, annoying as I should have known all this and been able to rattle it out even though the understanding was there, full on mind blank. A refresher from Agile principles, patterns, and practices in c# ( working through at the moment ). Wiki SOLID.

Also asked about, database service providers and Entity framework.

A good site for practice is project Euler, lots of small puzzles some are quite complicated and require a bit of maths to get going.

Solutions to the first two

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace basics
{
    class Program
    {
        static void Main(string[] args)
        {       
            //If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
            //Find the sum of all the multiples of 3 or 5 below 1000.

            var aList = new List<int>();
            for (int i = 1; i < 1000; i++)
            {
                if (i % 3 == 0 || i % 5 == 0)
                {
                    aList.Add(i);
                }
            }
            Console.WriteLine(aList.Sum());
            Console.Read();
        }
    }
}

---------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace basics
{
    class Program
    {
        static void Main(string[] args)
        {
            //Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

            //1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

            //By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
            int first = 1, second = 1, third = 0;
            int sum = 0;

            while (third < 4000000)
            {
                // gen fibs
                third = first + second;
                first = second;
                second = third;

                // less than 4 mill and even add to sum
                if (third < 4000000 && third % 2 == 0)
                {
                    sum += third;
                }
            }

            Console.WriteLine(sum);
            Console.Read();
        }
    }
}
--------------------------------------------------------------- 


Good articles read this week

Monday, 15 September 2014

Solving and sorting

Been back to reading a lot again, How to solve it. The maths part of this book wasn't great as well the writing style being old text book. Colours, chapters and descriptions would have been nice rather than the maths equivalent of the old Haynes proverb, fitting is reverse of removal.

Book cover with white back ground and thinking man made of numbers

One of the things I did like was the idea that with all problems you need to get purchase on the problem at hand. This maybe by digging a screw driver into the problem, waggle it and look for signs, which seems quite foreign to me as a way of solving a maths problem.

There is also a lot of good common sense items,
  • Start at the end and work backwords
  • Did you use all the data.
  • What are the data (written that way all through the text)? Unknowns etc.
  • What is the condition?
  • Use auxiliary elements.
  • Use auxiliary problems to simplify until the ridiculous.
  • Have you solved something like the problem before?
After reading clean code, I should know quick sort, I did take a quick youtube refresher. I think I am making it harder than it should be.

Sunday, 7 September 2014

Cows are bigger in person

After being a bit down I read The clean coder and I am rejuvenated. Very handy tips on dealing with pressure and saying no. 

The interesting item recommended in work ethic is time outside of work dedicated to learning, the recommendation being 20 hours. The thing is this really isn't that much when pod casts are taken into account. I easily get through 3 hours a week with .net rocks and Hansel minutes, what does help is having a tech book and when not in the mood a not so tech book like clean coder.

Black book with white title and picture of purple nebula

Liked the parts about not rushing, as I have seen this a number of times and refactoring out crazy variable names.

I read about the woods being good all round for health and creativity so found Haldon forest park, early morning it is quite empty. Note the speed hump on the way out that has the claws to stop cars driving in the exit are brutal going the correct way over it.

trail spliting woods with mist

Cows are about and they would only move for excuse me, cows, manners matter.

two black cows on the trail




Other bits from this week, lots of the visual studio shortcuts work in SQL server management studio.

Words of the week

Niladac
Function with no arguments

Connascence

Change in part means a change in another part of the program, I think is the side effect of units which are tightly coupled.