Wednesday, October 29, 2014

Changes 10/29/14

UMD Programming:

  • Worked on 2012 UMD programming contest question 1 (page 3 of the link), which involves error detection for 16 bit integers
  • My implementation is here
  • It actually ended up being an easy problem, the hard part was getting used to the environment.  They had a TryTest file which loaded preset integers and their check bits, but it took a while to figure out that this is how I was meant to test my file
  • Since Integer.toBinaryString(int i) doesn't allow you to specify the expected bits, I figured that I should append the missing zeros to the front, so an integer like 42 would return "0000000000101101" and not "101101".  In Python or Ruby, you could just do "0" * (16 - binary_string.length) + binary_string, but there is no way to do a string operation like this in Java as far as I could tell.  
  • I ended up writing a whole separate method to prepend the missing zeroes.  
  • In hindsight, I actually wasted a lot of time doing this, because only the ones are counted anyway.  Using the method I painstakingly created ends up being functionally equivalent to just calling Integer.toBinaryString(int i).
  • Line 11 can be replaced with Integer.toBinaryString() for an identical result.
  • I think my performance on this problem would have really benefited from a plan, rather than just jumping right in.  If I had thought about it more, I would have realized that Integer.toBinaryString() is sufficient for finding the number of '1's present in a binary integer.

1 comment:

  1. Excellent reflections! You'll get better at developing an approach to solving these problems the more you practice. It will also be important to learn to work well with your team mates, since the challenge is for the four of you to solve eight problems together in as little time as you can.

    Let's stick with 2012 as the first set. I'll suggest the same thing to Sam. Next week see if you can complete problems 2 and 3, the Pythogorean Triples and Vigenere Cipher problems. Try this approach:

    1. You and Sam each look over the problem on your own, then develop an approach you plan to use to solve it. Don't implement anything at this stage.

    2. Discuss it with Sam, comparing your plans for a solution.

    3. Only after the two of you have agreed on the best approach, you should begin writing an implementation.

    Try this with problems 2 and 3 and let me know how it works.

    ReplyDelete