Archive for the ‘Uncategorized’ Category.

Silverstone GD05 Case review

I recently purchased a Silverstone GD05 case, this is a mATX case which is sold without a powersupply. It’s relatively pricey ( 80GBP ). Here are my notes on the case.

It’s pretty bulky for a desktop case by modern standards but there isn’t too much wasted space internally.

There are three large internal case fans, which given their size are surprisingly quiet. I found it a little odd that one of the case fans is directly behind the 5.25″ drive bay, pushing air into a flat sheet of metal. Another curious design decision is that the power supply fan inlet in under the case. All the fans are sucking air into the case the air gets blown out of the back and top of the case. One fan can be controlled by the motherboard, for the others an adapter is supplied:

However this means they run at full speed all the time. In my case the fan connected to the motherboard is running significantly slower. However I’m currently only using the on board video. With a decent modern GPU or 2 installed you might find the cooling gets pushed a little harder.

It was a bit of a struggle getting the ATX port faceplate in, and even when installed it bulges out in an unsatisfying manner:

Another curious thing is the PCI faceplate mounted directly above the PSU. I suppose this could be for installing external PCI or eSATA ports?

Overall it’s a reasonable case, there’s enough space for a powerful desktop without it being a full tower. The build quality is “ok” but I’d hoped for more for 80 quid. I hate the “silver effect” buttons of the front. I’d like to find a standard PC case with the build quality of a Mac at a reasonable price, but they don’t seem to exist…

Euler Problem 3 Python Solution

The problem is to find the largest prime factor of 600851475143.

Some ugly python and an ugly solution. Clearly not very computationally efficient as I’m recalculating primes each time. There are also other computationally more efficient solutions out there in any case. This is just here for my reference:

import math

def getprimes(input):
  i = input #math.sqrt(input)

  vals = range(2,int(i))

  for n in vals:
    for j in xrange(n+n,int(i),n):
      if j in vals:
        vals.remove(j)

  vals.reverse()
  return vals

input = 600851475143L

primes_max = 100

while 1:
  primes = getprimes(primes_max)
  #print primes
  p = 0
  for i in primes:
    if input%i == 0:
      print "factor: ",i
      input = input/i
      p = 1


  if primes_max > math.sqrt(input):
    if p == 0:
      print "factor: ",input
      break

  primes_max = primes_max + 1000
  print primes_max

Euler Problem 1 Python Solution

I wanted to start playing with python a bit more so I thought I’d take a look at the project Euler problems. The first problem is to find the sum of all numbers between 1 and 999 that are divisible by 3 or 5.

After solving it and looking on the forums I was kind of shocked that most solutions used loops, iterating over every number between 1 and 1000. A more efficient solution is to use the sum of an arithmetic progression. Which I would have thought is high school Maths (I still needed Wikipedia to prompt me, ho hum). Anyway Here’s my solution:

max = 999

maxthree = ((max/3)*3) + 0.0
maxfive = ((max/5)*5) + 0.0
maxfifteen = ((max/15)*15) + 0.0

multhree = ((maxthree/3)/2)*(3+maxthree)
mulfive = ((maxfive/5)/2)*(5+maxfive)
mulfifteen = ((maxfifteen/15)/2)*(15+maxfifteen)

print multhree + mulfive - mulfifteen

I’d guess about 95% of the solutions used loops.
This is my favourite solution from the forum:

Here is a solution that is reasonably efficient but it works for any list of possible factors, without being overcomplicated (in Java). It took me about 50 minutes to write it.

import java.io.*;
import java.util.*;
import java.lang.Math;



public class Euler1 {


   public static void main(String[] args) {

      // Eueler project problem 1
      // find the sum of all numbers less than N (1000) that are multiples of a given list of factors (3 and 5)
      // the program seeks a balance between speed, memory use, generality and program simplicity

      int[] factors = {3,5};
      int N = 1000;

      int sum = computeSum (factors, N);

      System.err.println(sum);

   }


   public static int computeSum (int[] factors, int N) {

      // efficient calculation using the fact that the pattern of multiples repeats
      // use the produce of the factors as the period length, 
      // the least common multiple would be more efficient but complicates the program

      int M = 1;
      for(int j=0; j<factors.length; j++) {
         int f = factors[j];
         M *= f;
      }

      int k = (N-1)/M;    // number of repeated periods
      int r = (N-1)%M+1;  // remaining length;

      // use average of sum over first and last period time k, plus sum over the remaining numbers 

      int sum = (bruteSum(factors, 1, M+1)+bruteSum(factors,(k-1)*M+1,k*M+1))*k/2 + bruteSum(factors, k*M+1, N);

      return sum;
   }

   public static int bruteSum(int[] factors, int N0, int N1) {

      // computes the answer using a straightforward but inefficient brute force method 

      int sum = 0;
      
      for(int i=N0; i<N1; i++) {
         boolean isAMultiple = false;
         for(int j=0; j<factors.length; j++) {
            int f = factors[j];
            if(i%f == 0) isAMultiple = true;
         }

         if(isAMultiple) {
            sum += i;
         }

      }

      return sum;
         
   }
}

Convert DNA string to binary

Getting fed up with writing this, so here’s some basic code to do it:

#include <iostream>

using namespace std;

uint32_t dna_number(string s) {

  uint32_t num = 0;

  for(size_t n=0;n<s.size();n++) {

    num = num << 2;
    if(s[n] == 'A') num += 0;
    if(s[n] == 'C') num += 1;
    if(s[n] == 'G') num += 2;
    if(s[n] == 'T') num += 3;

  }
  return num;
}

int main(int argc,char **argv) {
  cout << dna_number("AAAAA") << endl;
  cout << dna_number("AAAAC") << endl;
  cout << dna_number("AAAAG") << endl;
  cout << dna_number("AAAAT") << endl;
  cout << dna_number("AAACA") << endl;
  cout << dna_number("AAACC") << endl;
  cout << dna_number("AAACG") << endl;
  cout << dna_number("AAACT") << endl;
  cout << dna_number("AAAGA") << endl;
  cout << dna_number("AAAGC") << endl;
  cout << dna_number("AAAGG") << endl;
  cout << dna_number("AAAGT") << endl;
  cout << dna_number("AAATA") << endl;
  cout << dna_number("AAATC") << endl;
  cout << dna_number("AAATG") << endl;
  cout << dna_number("AAATT") << endl;
  cout << dna_number("AACAA") << endl;
}