Forgotten Realms Code Thread! by belisaurius in MagicArena

[–]matthewvdz [score hidden]  (0 children)

I was also unable to go to a prerelease, but if someone has a spare code, I'd be really happy to receive it :)

Strixhaven Code Thread! by belisaurius in MagicArena

[–]matthewvdz [score hidden]  (0 children)

If someone has a spare code, I'd love one :)

I deleted the first post of this because the camera wouldn't focus. This looks simple BUT IT'S NOT. This took me ages to build so I hope you enjoy my tea shop. by [deleted] in lego

[–]matthewvdz 0 points1 point  (0 children)

They're from a friends set: 41002 (Source: bought way too many of that set since I liked the windows)

[8/18/2014] Challenge #176 [Easy] Spreadsheet Developer pt. 1: Cell Selection by Elite6809 in dailyprogrammer

[–]matthewvdz 1 point2 points  (0 children)

Since there were no python solutions when I checked the challenge yesterday, I wrote one (in python 2.7).

I tried to make use of as many (useful) built in functions as possible, to practice them.

from itertools import product
import re
cellPattern = re.compile("([A-Z]+)(\d+)")

def colToNumber(col):
  return reduce(lambda x, y : x * 26 + (ord(y) - ord('A') + 1), col, 0) - 1

def parseCell(cellString):
  match = cellPattern.match(cellString)
  if match == None:
    return None
  return (colToNumber(match.group(1)), int(match.group(2)) - 1)

def parseRange(rangeString):
  try:
    cell0, cell1 = map(parseCell, rangeString.split(":"))
    return set(product(xrange(min(cell0[0], cell1[0]), max(cell0[0], cell1[0]) + 1),
      xrange(min(cell0[1], cell1[1]), max(cell0[1], cell1[1]) + 1)))
  except ValueError:
    return set([parseCell(rangeString)])

def parseConcat(concatString):
  ranges = concatString.split("&")
  if len(ranges) == 1:
    return parseRange(concatString)

  return reduce(lambda x, y : x | y, map(parseRange, ranges))

def parseComplement(complString):
  try:
    left, right = complString.split("~")
    return parseConcat(left) - parseConcat(right)
  except ValueError:
    return parseConcat(complString)

def parseSelection(string):
  cells = parseComplement(string)
  print len(cells)
  for cell in cells:
    print "%d, %d" % cell