Lorentz Vedeler

Maintaining same version number for multiple .net-assemblies

If you want several projects to always have the same version number, this is a pretty neat trick:

  1. Remove AssemblyVerison and AssemblyFileVersion from existing AssemblyInfo.cs files
  2. Add a CommonAssemblyInfo.cs file to one of the projects containing just:
        using System.Reflection;
    
        [assembly: AssemblyVersion("2.3.1.0")]
        [assembly: AssemblyFileVersion("2.3.1.0")]
    
  3. In the other projects add existing item choose the CommonAssemblyInfo.cs, but remember to add it as a link (click on the arrow on the add button)

Using Chrome with the Lenovo Yoga 2 and other high DPI touch screen laptops.

I recently got a hold of a new Lenovo Yoga 2. The laptop is awesome, but not all applications work that well with the high DPI display.. Chrome is unfortunately one of them – with the default settings that is.

To remedy the situation, we are going to apply some experimental features (what could go wrong?).

  1. Enable HiDPI Support
  2. Enable Touch events
  3. Enable Touch optimized UI
  4. Enable Pinch scale
  5. Enable Touch initiated drag and drop

Close Chrome
Right click the icon and go to properties -> Compatability -> check Disable display scaling on High DPI settings.

The KeyedCollection

This week I found a cool
Net-class in the System.Collections.ObjectModel namespace; the KeyedCollection.

It’s very much like a dictionary, except you it enumerates the items instead of a key-value pair. If your item-class has a natural key, all you have to do is derive from the abstract KeyedCollection-class and implement the GetKeyForItem method.

public class SchoolClass : KeyedCollection<uint, Student>
    {
        protected override uint GetKeyForItem(Student newStudent)
        {
            return newStudent.Number;
        }
    }

Euler Problem 92

Here’s my solution to Euler problem 92. The code is pretty simple, it tries to shortcut the sequence by storing every number in a chain along with the number that recurs.

class Euler92:
    def __init__(self):
        self.knownSeq = {}

    def ChainNumber(self,n):
        currentSeq = []
        while not n in [1,89]:
            currentSeq.append(n)
            if(n in self.knownSeq):
                n = self.knownSeq[n]
            else:
                n = SquareDigits(n)
        for x in currentSeq:
            self.knownSeq[x] = n
        return n

    def Solve(self, n):
        return len([x for x in range(2,n) if self.ChainNumber(x) == 89])
        
def SquareDigits(n):
        return sum(map(lambda x: int(x)**2, str(n)))

Euler Problem 59

This is my solution to Euler problem 59 in python. It is pretty straight forward and relies on the heuristics of the problem. Initially it filters out every key that will only produce printable characters for all its corresponding positions in the encrypted text. It then proceeds to combine these keys and check for actual, common English words in the text.

from math import ceil
import string

def test():
    asciis = open('cipher1.txt', 'r').read()
    encCodes = [int(s) for s in asciis.split(',')]

    asciiSum = 0
    
    pKeys = plausibleKeys(encCodes, 3)
    for k0 in pKeys[0]:
        for k1 in pKeys[1]:
            for k2 in pKeys[2]:
                text = "".join(applyKey([k0,k1,k2], encCodes))
                if(properStringProbability(text)):
                    print(text)
                    asciiSum = sum([ord(c) for c in text])
    return asciiSum

def plausibleKeys(encCodes, keyLen):
    pKeys = {
        0: [x for x in range(255)],
        1: [y for y in range(255)],
        2: [z for z in range(255)]
        }

    for i, c in enumerate(encCodes):
        for k in pKeys[i % keyLen]:
             if chr(c ^ k) not in string.printable:
                 pKeys[i % keyLen].remove(k)
    return pKeys

def properStringProbability(string):
    cnt = 0
    for word in ["the", "and", "have", "that", "you"]:
        cnt += string.count(word)        
    return cnt > 5


def applyKey(key, asciiText):
    return [chr(x ^ int(y)) for (x,y) in zip(key * int(ceil(len(asciiText) / 3)),asciiText)]