4/13/2011

Macbook Pro 1,1 Battery Woes

I still get 45 minutes or so out of my 4+ year old battery. However, the one I bought to replace it, about 18 mo ago, it's now a brick. The worst value I've ever gotten out of a battery (33 cycles), and it started failing just around 13 mo, (right outside warranty). I just didn't realize it, and the mac didn't warn me, yet it's been telling me for 2 years to service my original battery. I dare Apple to give their batteries an 18 mo warranty.

Any tips on rebuilding it myself or a 3rd party that makes something reliable? I'd only get 2+ hours out of a new one anyway, since my mbp is the first gen.


Original Battery from late 2006:

Model Information:
Manufacturer: Sony
Device name: ASMB012
Pack Lot Code: 0003
PCB Lot Code: 0000
Firmware Version: 102a
Hardware Revision: 0400
Cell Revision: 0303
Charge Information:
Charge remaining (mAh): 2934
Fully charged: Yes
Charging: No
Full charge capacity (mAh): 3043
Health Information:
Cycle count: 99
Condition: Check Battery
Battery Installed: Yes
Amperage (mA): 0
Voltage (mV): 12331

Replacement battery from mid-2009:

Model Information:
Manufacturer: Sony
Device name: ASMB012
Pack Lot Code: 0001
PCB Lot Code: 0000
Firmware Version: 0110
Hardware Revision: 0500
Cell Revision: 0303
Charge Information:
Charge remaining (mAh): 0
Fully charged: No
Charging: No
Full charge capacity (mAh): 0
Health Information:
Cycle count: 33
Condition: Replace Now
Battery Installed: Yes
Amperage (mA): 0
Voltage (mV): 6505

4/10/2011

Learning Ruby with Ruby Koans

I've gotten through more than half of the Ruby Koans in the past few weeks. Around the 174th test, the developer is asked to implement a method that solves a trivial problem. I would have liked to make the solution more simple, but this is what I could come up with, based on my current Ruby skill level.

# Greed is a dice game where you roll up to five dice to accumulate
# points.  The following "score" function will be used calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
#
# * A set of three numbers (other than ones) is worth 100 times the
#   number. (e.g. three fives is 500 points).
#
# * A one (that is not part of a set of three) is worth 100 points.
#
# * A five (that is not part of a set of three) is worth 50 points.
#
# * Everything else is worth 0 points.
#
#
# Examples:
#
# score([1,1,1,5,1]) => 1150 points
# score([2,3,4,6,2]) => 0 points
# score([3,4,5,3,3]) => 350 points
# score([1,5,1,2,4]) => 250 points
#
# More scoring examples are given in the tests below:
#
# Your goal is to write the score method.

def get_score_for_matching_roll(potential_roll, dice)
single_scores = {1=>100, 5=>50}
  triple_score_multipliers = {1=>1000}
  single_scores.default = 0
  triple_score_multipliers.default = 100
  triples_singles = dice.find_all { |roll| roll == potential_roll }.size.divmod(3)
  triples_singles[0]*triple_score_multipliers[potential_roll]*potential_roll +
          triples_singles[1]*single_scores[potential_roll]
end

def score(dice)
  # You need to write this method
  score = dice.uniq.inject(0) { |score, potential_roll|
    score + get_score_for_matching_roll(potential_roll, dice)
  }
end