D2L Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

Set up a map of the symbol (just 9 characters in a row, left/right, top/bottom) to digit.

Read the input file, store the 3 keys you are looking for by appending to each key in a list (column / 3 tells you which one you are appending too).

I assumed no space in the input file between numbers, so it is a 9x9 file input file exactly.

./lednumbers.py led_image
860

#!/usr/bin/env python

import sys


SYMBOLS = [
"""\
 _
| |
|_|\
""",
"""\
 |
 |
 | """,
"""\
___
 _|
|__""",
"""\
___
__|
__|""",
"""\
| |
|_|
  |""",
"""\
___
|_
__|""",
"""\
__
|_
|_|""",
"""\
___
  |
  |""",
"""\
___
|_|
|_|""",
"""\
___
| |
|_|
__|"""]


def build_map():
    """Build a map of LED pattern to numeric value."""
    symbol_map = {}
    for i, symbol in enumerate(SYMBOLS):
        line = symbol.replace('\n', '')
        symbol_map[line] = i
    return symbol_map

if __name__ == '__main__':
    # open file with three digits
    lines = [line.strip('\n') for line in open(sys.argv[1]).readlines()]
    assert len(lines) == 3
    symbols = ['', '', '']
    row = 0
    for line in lines:
        assert len(line) == 9
        for i in range(9):
            symbols[i / 3] += line[i]
    symbol_map = build_map()
    for symbol in symbols:
        sys.stdout.write(str(symbol_map[symbol]))
    print ''

- Dan August 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

(deleted comment - I edited the code)

- Dan August 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

static long ReadDigitalNumber(string file)
        {
            char[,] digitalEight = new char[,] {
                { '|', '-', '|'},
                { '|', '-', '|'},
                { '|', '_', '|'},
            };
            char[,] digitalSix = new char[,] {
                { '|', '-', '-'},
                { '|', '-', '-'},
                { '|', '_', '|'},
            };
            char[,] digitalThree = new char[,] {
                { '-', '-', '|'},
                { '_', '_', '|'},
                { '_', '_', '|'},
            };
            List<char[,]> numbers = new List<char[,]>(3);
            string[] lines = File.ReadAllLines(file);
            int x = 0, y = 0, index = 0;
            foreach (string line in lines) 
            {
                index = 0;
                for (int i = 0; i < line.Length; i++) {
                    if (i != (line.Length - 1) && (i % 3) == 0)
                    {
                        if (i != 0)
                            index++;
                        y = 0;
                        if (numbers.Count < (index + 1))
                            numbers.Add(new char[3, 3]);
                    }
                    numbers[index][x,y] = line[i];
                    y++;
                }
                x++;
            }
            long result = 0;
            numbers.ForEach(digit =>
            {
                int[] match = new int[10];
                for (int i = 0; i < digit.GetLength(0); i++) {
                    for (int j = 0; j < digit.GetLength(1); j++) {
                        if (digit[i, j] == digitalEight[i, j])
                            match[8]++;
                        if (digit[i, j] == digitalSix[i, j])
                            match[6]++;
                        if (digit[i, j] == digitalThree[i, j])
                            match[3]++;
                    }
                }
                if (match[8] == digit.GetLength(0) * digit.GetLength(1)) 
                {
                    if (result > 0)
                        result *= 10;
                    result += 8;
                }
                if (match[6] == digit.GetLength(0) * digit.GetLength(1))
                {
                    if (result > 0)
                        result *= 10;
                    result += 6;
                } 
                if (match[3] == digit.GetLength(0) * digit.GetLength(1))
                {
                    if (result > 0)
                        result *= 10;
                    result += 3;
                }
            });
            return result;
        }

- Teh Kok How September 01, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More