Skip to content

Instantly share code, notes, and snippets.

@jcalvert
Created September 20, 2011 00:56
Show Gist options
  • Save jcalvert/1228041 to your computer and use it in GitHub Desktop.
Save jcalvert/1228041 to your computer and use it in GitHub Desktop.
Vetstreet is looking for developers

Vetstreet is looking for developers

Vetstreet is looking for solid software developers in the DC Metro area to work in our downtown Silver Spring office. We have a diverse, interesting, collaborative work environment, delivering software services to veterinarians and their clients.

The interesting bits:

  • We're a polyglot shop. Java and Ruby are our greatest needs right now. If you can do both, awesome. We have Perl and .NET hanging around too. SQL all around.
  • Experience is preferred, but junior candidates OK.
  • You should feel relatively comfortable jumping into different things; some back end, some front end.
  • Most important is that you're smart and enthusiastic.

Leave comments, messages, etc to this Gist to get in touch with us.

You should of course feel free to send along a resume, but most important is perhaps linking to a solution to one of the programming puzzles below. This is the best way to prove you're not a paper tiger.

Cheers!

BEGIN PUZZLE TEST Z1. "Queue-Tip"

Imagine a queue that looks like the following: ABCDEFGH

A is in slot 0 of the queue, and H is in slot 7. The alphabet gods have now told you to defy the order of this queue on-demand. Your task is to write a program that accepts pairs of values, one being a slot number, and the other being a letter. The program should be able to accept any even combination of unique slot numbers and letters, which pairs in the order of letters and numbers received, and should throw an error if an odd number of arguments are passed or if a slot number and letter are used more than once in the argument list. Based on the input, the queue will change, and you will output the new queue. Any letters that are not defined in the arguments passed should move into the open slots in alphabetical order (much like a queue, ironically). If no arguments are passed, the original queue should output. It is also safe to throw an error if a letter that doesn’t exist in the queue is passed, and also if a slot number is passed that is larger than the size of the queue.

Example input: Myprog 3 A B 5 Expected output: CDEAFBGH

Example input: Myprog A H 1 6 7 E Expected output: BACDFGHE

Bad inputs: Myprog A 1 A 2 Myprog A 1 B 3 C

Z2. "Sort-sort-sort-it-out"

You're receiving a delimited text file, and it's very large (greater than 1GB). Some fields contain alpha numeric characters, and fields may be duplicated. You should process the file and output strings that occur multiple times in the same field and the number of occurrences. You should also sort as you go, meaning that the most frequently occurring words are at the top. Consider the following concerns:

Simple, elegant code. Memory efficiency. Computational run time.

EXAMPLE:
1,2,3,4,5
foo,bar,foodbar,foobar,faboor
fSU_)d89fs-,sjdoknfpoi,doof,foobar,oiufs
&^T(^#(*&$,1233880,FOODBARz,%%YES%%,NV
apoif,bar,pf9,FOOBAR,null

The output would be bar - column 2 - occurrences: 2 foobar - column 4 - occurrences: 2 foo - column 1 - occurrences: 1 fSU_)d89fs- - column 1 - occurrences: 1 etc...

Z3. "Tran-slay-tor"

You need to write a program that follows a simple interface. This interface has one method/function/routine that accepts a single argument of a filepath and returns a filepath to a new file it has written out. The method should be called translate. It must be able to read an arbitrary set of chained instructions and perform the translation described on the file. In cases of ambiguity, simply document your decisions.

Entities your program should understand CHARACTER CONSONANT VOWEL NUMBER WORD LINE

Operators: +-/*><=

Actions you should support: REPLACE WITH REVERSE var PREPEND APPEND Modifiers: CONSECUTIVE UNIQUE

So a given instruction set might look like: consecutive vowels replace with 'x' consecutive consonants append 'bar' numbers > 10 reverse line

And they would respective produce outputs: My name is foobar => My name is fxbar I am happy to buy all 5 => I am happbary to buy all 5 There are 100s of foos! => !sxf fo s001 era erehT

END PUZZLE TEST

@mkuklis
Copy link

mkuklis commented Nov 6, 2011

first take on Z1

    def queue_tip(*args)

      queue = ["A","B","C","D","E","F","G","H"]

      return queue if args.size == 0
      raise "odd number of arguments" unless args.size.even?

      slots = {}
      letters = {}

      args.each do |a|
        # process slot
        if a =~ /^[0-9]+$/
          a = a.to_i
          raise "slot '#{a}' does not exist" if a >= queue.length
          raise "slot '#{a}' is not unique" if slots.key?(a)
          slots[a] = 1

        # process letter
        elsif a =~ /^[a-zA-Z]{1}$/
          a = a.capitalize
          raise "letter '#{a}' doesn't exist in the queue" unless queue.include?(a)
          raise "letter '#{a}' is not unique" if letters.key?(a)
          letters[a] = 1
        end
      end

      raise "number of letters is not equal to number of slots" unless letters.size == slots.size

      q = []
      offset = 0

      # TODO improve this

      # prefill new queue with given letters in specific slots
      slots.each_with_index { |slot, index| q[slot[0]] = letters.keys[index] }

      # fill the rest
      queue.each_with_index do |l, i|
        next if letters.key?(l)
        (offset..q.size).each do |j|
          if q[j].nil?
            q[j] = l
            offset+=1
            break
          end
        end
      end
      q
    end

and specs

  describe "#queue_tip" do
      it "should output original queue for no arguments" do
        queue_tip().should == ["A","B","C","D","E","F","G","H"]
      end

      it "should raise odd number of arguments error" do
        expect{ queue_tip("1", "C", "2") }.to raise_error RuntimeError, "odd number of arguments"
      end

      it "should raise error about missing slot" do
        expect{ queue_tip("9", "C") }.to raise_error RuntimeError, "slot '9' does not exist"
      end

      it "should raise error about slot uniqueness" do
        expect{ queue_tip("1", "C", "1", "D") }.to raise_error RuntimeError, "slot '1' is not unique"
      end

      it "should raise error about letter missing from the queue" do
        expect{ queue_tip("1", "Z", "2", "D") }.to raise_error RuntimeError, "letter 'Z' doesn't exist in the queue"
      end

      it "should raise error about letter uniqueness" do
        expect{ queue_tip("1", "D", "2", "D") }.to raise_error RuntimeError, "letter 'D' is not unique"
      end

      it "should raise error when number of slots != number of letters" do
        expect{ queue_tip("1", "D", "2", "H", "E", "F") }.to raise_error RuntimeError, "number of letters is not equal to number of slots"
      end

      it "should output CDEAFBGH" do
        queue_tip("3", "A", "B", "5").should == ["C", "D", "E", "A", "F", "B", "G", "H"]
      end

      it "should output BACDFGHE" do
        queue_tip("A", "H", "1", "6", "7", "E").should == ["B", "A","C","D","F","G","H","E"]
      end
    end

@mkuklis
Copy link

mkuklis commented Nov 6, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment