diff --git a/icpc/2018 ICPC East Central North America Regional Contest/D/input b/icpc/2018 ICPC East Central North America Regional Contest/C/input similarity index 100% rename from icpc/2018 ICPC East Central North America Regional Contest/D/input rename to icpc/2018 ICPC East Central North America Regional Contest/C/input diff --git a/icpc/2018 ICPC East Central North America Regional Contest/C/main.py b/icpc/2018 ICPC East Central North America Regional Contest/C/main.py new file mode 100644 index 0000000..daa9643 --- /dev/null +++ b/icpc/2018 ICPC East Central North America Regional Contest/C/main.py @@ -0,0 +1,65 @@ +import os, sys + +mappings = { + '@' : ['at'], + '&' : ['and'], + '1' : ['one', 'won'], + '2' : ['to', 'too', 'two'], + '4' : ['for', 'four'], + 'b' : ['bea', 'be', 'bee'], + 'c' : ['sea', 'see'], + 'i' : ['eye'], + 'o' : ['oh', 'owe'], + 'r' : ['are'], + 'u' : ['you'], + 'y' : ['why'] +} + +# gets the largest and smallest possible subs +minSub = min([min(list(map(len, vals))) for vals in mappings.values()]) +maxSub = max([max(list(map(len, vals))) for vals in mappings.values()]) + +# Gets the token ('are' -> 'r') for a sub, case sensitive +def getToken(sub): + for key in mappings.keys(): + if sub in mappings[key]: + return key + +def processWord(word): + processed = [False] * len(word) + # For every character in the word + index = 0 + while index < len(word): + possible = [] + for length in range(minSub, maxSub + 1): + if index + length > len(word): + continue + sub = word[index:index + length] + token = getToken(sub.lower()) + if token: + # Sometimes mulitple tokens can appear for the same one, we just select the one that is longest + possible.append((token, len(sub), sub)) + # A token replacement has been found at this index + if possible: + # Find the best one, based on the sub + select = max(possible, key=lambda item : item[1]) + # print(index, select, word[index:index + select[1]]) + word = word[:index] + (select[0].title() if select[2].istitle() else select[0]) + word[index + select[1]:] + # word[index:index + select[1]] = select[0] + index += len(select[0]) + else: + index += 1 + return word + +# Process a single line +def processLine(line): + return ' '.join([processWord(word) for word in line.split(' ')]) + +# Drive Code +def main(): + path = os.path.join(sys.path[0], 'input') + data = open(path, 'r').read().split('\n')[1:] + print('\n'.join(map(processLine, data))) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/icpc/2018 ICPC East Central North America Regional Contest/D/inputs/1 b/icpc/2018 ICPC East Central North America Regional Contest/D/inputs/1 new file mode 100644 index 0000000..fa7280a --- /dev/null +++ b/icpc/2018 ICPC East Central North America Regional Contest/D/inputs/1 @@ -0,0 +1,6 @@ +5 +H 2 0:13 +A 2 0:19 +H 1 0:52 +H 1 0:52 +A 3 1:08 \ No newline at end of file diff --git a/icpc/2018 ICPC East Central North America Regional Contest/D/inputs/2 b/icpc/2018 ICPC East Central North America Regional Contest/D/inputs/2 new file mode 100644 index 0000000..165a430 --- /dev/null +++ b/icpc/2018 ICPC East Central North America Regional Contest/D/inputs/2 @@ -0,0 +1,2 @@ +1 +H 1 16:00 \ No newline at end of file diff --git a/icpc/2018 ICPC East Central North America Regional Contest/D/main.py b/icpc/2018 ICPC East Central North America Regional Contest/D/main.py index daa9643..34beb36 100644 --- a/icpc/2018 ICPC East Central North America Regional Contest/D/main.py +++ b/icpc/2018 ICPC East Central North America Regional Contest/D/main.py @@ -1,65 +1,41 @@ -import os, sys +import datetime, re, os, sys -mappings = { - '@' : ['at'], - '&' : ['and'], - '1' : ['one', 'won'], - '2' : ['to', 'too', 'two'], - '4' : ['for', 'four'], - 'b' : ['bea', 'be', 'bee'], - 'c' : ['sea', 'see'], - 'i' : ['eye'], - 'o' : ['oh', 'owe'], - 'r' : ['are'], - 'u' : ['you'], - 'y' : ['why'] -} +pattern = r'([HA]) (\d) (\d+):(\d+)' +mmsspattern = '%M:%S' -# gets the largest and smallest possible subs -minSub = min([min(list(map(len, vals))) for vals in mappings.values()]) -maxSub = max([max(list(map(len, vals))) for vals in mappings.values()]) +# Process the input for a single niput +def process(rawinput): + def getBest(): + return max(score.items(), key=lambda x:x[1])[0] + score = {'H' : 0, 'A' : 0} + leads = {'H' : 0, 'A' : 0} + rawinput = '\n'.join(rawinput.split('\n')[1:]) + events = re.finditer(pattern, rawinput) + curLead = '' + lastTime = datetime.datetime(1990, 1, 1, 0, 0, 0) + gameEnd = datetime.datetime(1990, 1, 1, 1, 30) + for event in events: + # Create the formatted timecode, add the score + timecode = '{}:{}'.format(event.group(3).zfill(2), event.group(4).zfill(2)) + curtime = datetime.datetime.strptime(timecode, mmsspattern) + score[event.group(1)] += int(event.group(2)) + # Get the team in the lead and if it's different + best = getBest() + leads[best] += int((curtime - lastTime).seconds) + lastTime = curtime +# if gameEnd > lastTime: + # leads[best] += (gameEnd - lastTime).seconds + return '{} {} {}'.format(getBest(), leads['H'], leads['A']) -# Gets the token ('are' -> 'r') for a sub, case sensitive -def getToken(sub): - for key in mappings.keys(): - if sub in mappings[key]: - return key - -def processWord(word): - processed = [False] * len(word) - # For every character in the word - index = 0 - while index < len(word): - possible = [] - for length in range(minSub, maxSub + 1): - if index + length > len(word): - continue - sub = word[index:index + length] - token = getToken(sub.lower()) - if token: - # Sometimes mulitple tokens can appear for the same one, we just select the one that is longest - possible.append((token, len(sub), sub)) - # A token replacement has been found at this index - if possible: - # Find the best one, based on the sub - select = max(possible, key=lambda item : item[1]) - # print(index, select, word[index:index + select[1]]) - word = word[:index] + (select[0].title() if select[2].istitle() else select[0]) + word[index + select[1]:] - # word[index:index + select[1]] = select[0] - index += len(select[0]) - else: - index += 1 - return word - -# Process a single line -def processLine(line): - return ' '.join([processWord(word) for word in line.split(' ')]) - -# Drive Code +# Driver code def main(): - path = os.path.join(sys.path[0], 'input') - data = open(path, 'r').read().split('\n')[1:] - print('\n'.join(map(processLine, data))) + # Read inputs + inputs = [os.path.join(sys.path[0], 'inputs', x) for x in + os.listdir(os.path.join(sys.path[0], 'inputs'))] + inputs = [open(path).read() for path in inputs] + for rawinput in inputs: + print(process(rawinput)) + print('-'*19) if __name__ == "__main__": main() \ No newline at end of file diff --git a/icpc/2018 ICPC East Central North America Regional Contest/F/main.py b/icpc/2018 ICPC East Central North America Regional Contest/F/main.py index 2e244fd..4321eb9 100644 --- a/icpc/2018 ICPC East Central North America Regional Contest/F/main.py +++ b/icpc/2018 ICPC East Central North America Regional Contest/F/main.py @@ -4,25 +4,41 @@ def process(item): # Constants and initial values stocks, (n, m) = item[1], item[0] peaks, valleys = [], [] - possiblePeaks, possibleValleys = range(n, len(stocks) - n), range(m, len(stocks) - m) # Check all possible peaks - for index in possiblePeaks: - isPeak = True + for index in range(len(stocks)): + isPeak, isValley = True, True + # Peak Checking for i in range(1, n + 1): - if not stocks[index - i] < stocks[index] or not stocks[index] > stocks[index + i]: - isPeak = False - if isPeak: - peaks.append(index) - print(peaks) - # Check all possible valleys - for index in possibleValleys: - isValley = True + # If we're no the first index + if index - i >= 0: + # If position behind us is lower + if not stocks[index] > stocks[index - i]: + isPeak = False + break + # If we're not the final index + if index + i < len(stocks): + # and position in front of us is lower + if not stocks[index] > stocks[index + i]: + isPeak = False + break + # Valley checking for i in range(1, m + 1): - if not stocks[index - i] > stocks[index] or not stocks[index] < stocks[index + i]: - isValley = False - if isValley: - valleys.append(index) - print(valleys) + # If we're not the first index + if index - i >= 0: + # if position behind us is higher + if not stocks[index] < stocks[index - i]: + isValley = False + break + # If we're not the final index + if index + i < len(stocks): + # and position in front of us is higher + if not stocks[index] < stocks[index + i]: + isValley = False + break + if isPeak: peaks.append(index) + if isValley: valleys.append(index) + print(f'n{n}, m{m}') + print('{0}{1}\n{0}{2}'.format('-> ', peaks, valleys)) return len(peaks), len(valleys) # Driver code for all inputs in folder diff --git a/icpc/2018 ICPC East Central North America Regional Contest/README.MD b/icpc/2018 ICPC East Central North America Regional Contest/README.MD index e9c5add..2fc034a 100644 --- a/icpc/2018 ICPC East Central North America Regional Contest/README.MD +++ b/icpc/2018 ICPC East Central North America Regional Contest/README.MD @@ -8,6 +8,14 @@ Most of these problems seem modestly easy, if I'm being honest. ## Progress -#1 : Unsovled +#A : **Solved** -#2 : **Solved** \ No newline at end of file +#B : **Solved** + +#C : Unsolved + +#D : **Solved** + +#E : **Solved** + +#F : **Solved** \ No newline at end of file diff --git a/uil/October 2013 Set/1/java/.idea/misc.xml b/uil/October 2013 Set/1/java/.idea/misc.xml new file mode 100644 index 0000000..4c1c37a --- /dev/null +++ b/uil/October 2013 Set/1/java/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/uil/October 2013 Set/1/java/.idea/modules.xml b/uil/October 2013 Set/1/java/.idea/modules.xml new file mode 100644 index 0000000..7a3904f --- /dev/null +++ b/uil/October 2013 Set/1/java/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/uil/October 2013 Set/1/java/.idea/workspace.xml b/uil/October 2013 Set/1/java/.idea/workspace.xml new file mode 100644 index 0000000..9fb398a --- /dev/null +++ b/uil/October 2013 Set/1/java/.idea/workspace.xml @@ -0,0 +1,311 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1568523104137 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 11 + + + + + + + + \ No newline at end of file diff --git a/uil/October 2013 Set/2/java/2.iml b/uil/October 2013 Set/2/java/2.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/uil/October 2013 Set/2/java/2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/uil/October 2013 Set/2/java/input1.dat b/uil/October 2013 Set/2/java/input1.dat new file mode 100644 index 0000000..fd7e24c --- /dev/null +++ b/uil/October 2013 Set/2/java/input1.dat @@ -0,0 +1,4 @@ +3 +@coolstuff This tweet will have exactly 81 characters so it is definitely a tweet +@funnyman This message is really, really, really, long so it will not be a tweet. No one wants a long tweet cuz ain't nobody got time for that! +@sweetbrown I am so awesome that Beyonce quotes me! \ No newline at end of file diff --git a/uil/October 2013 Set/2/java/out/production/2/problem2.class b/uil/October 2013 Set/2/java/out/production/2/problem2.class new file mode 100644 index 0000000..a08d7f1 Binary files /dev/null and b/uil/October 2013 Set/2/java/out/production/2/problem2.class differ diff --git a/uil/October 2013 Set/2/java/src/problem2.java b/uil/October 2013 Set/2/java/src/problem2.java new file mode 100644 index 0000000..2a24bd0 --- /dev/null +++ b/uil/October 2013 Set/2/java/src/problem2.java @@ -0,0 +1,18 @@ +import static java.lang.System.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class problem2 { + public static void main(String[] args ) throws FileNotFoundException { + // Constants + File input = new File("input1.dat"); + Scanner read = new Scanner(input); + int lines = read.nextInt(); + read.nextLine(); + // Driver Code + for (int i = 0; i < lines; i++) + out.println(read.nextLine().length() <= 140 ? "tweet" : "not a tweet"); + } + +} \ No newline at end of file diff --git a/uil/October 2013 Set/3/input-generator/main.py b/uil/October 2013 Set/3/input-generator/main.py new file mode 100644 index 0000000..3092b18 --- /dev/null +++ b/uil/October 2013 Set/3/input-generator/main.py @@ -0,0 +1,205 @@ +import math, time, random + +class Node(object): + def __init__(self, parent=None, position=None): + self.parent, self.position = parent, position + + self.g, self.h, self.f = 0, 0, 0 + + def __eq__(self, other): + assert type(other) == Node, "Can only compare equality against other Node objects" + return self.position == other.position + + def __repr__(self): + return f'' + +# Generate a grid and return it to the user +class SnakeGrid(object): + def __init__(self, x, y, length=3): + self.x, self.y, self.length, self.sleepTime = x, y, length, 0.0 + self.offsets = [[0, 1], [1, 0], [-1, 0], [0, -1]] + self.generate() + + def sleep(self, seconds): + self.sleepTime += (seconds, time.sleep(seconds))[0] + + def generate(self): + assert self.x > 2 + self.length and self.y > 3, "Dimensions must be able to at least fit the snake" + + # Grid is a matrix of single space strings + self.matrix = [[' ' for xx in range(self.x + 1)] for yy in range(self.y + 1)] + + # Choose a initial position + self.positions = [self.getPos(-1, -1)] + self.mark(self.positions[0]) + curlength = self.length - 1 + + # Start drawing up the snake + while curlength > 0: + left, right = [self.positions[0][0], self.positions[0][1] - 1], [self.positions[-1][0], self.positions[-1][1] + 1] + canLeft, canRight = self.available(left), self.available(right) + curlength -= 1 + + # If both options are available, just choose one and act like the other is unavailable + if canLeft and canRight: + if random.choice([True, False]): canLeft = False + else: canRight = False + + if canLeft != canRight: + if canLeft: + self.mark(left) + self.positions.insert(0, left) + if canRight: + self.mark(right) + self.positions.append(right) + elif not (canLeft or canRight): + print(positions, left, right) + print("Could not resolve any position to use...?") + + # Populate with 3-7 pellets + for _ in range(random.randint(2, 5)): + while True: + pos = self.getPos() + if self.available(pos): + self.mark(pos, 'F') + break + + # Pythagorean distance calculation + def distance(self, pos1, pos2): + return math.sqrt(((pos1[0] - pos2[0]) ** 2) + ((pos1[1] - pos2[1]) ** 2)) + + # Returns all positions with the specified character (by default, 'F', for pellets) + def pellets(self, char='F'): + pelletss = [] + for yy in range(self.y): + for xx in range(self.x): + if self.available([xx, yy], look=char): + pelletss.append([xx, yy]) + return pelletss + + # Returns the best pellet to path to based on distance and a specified blacklist of positions + def bestPellet(self, curpos, blacklist=[]): + potential = self.pellets() + if blacklist: + potential = list(filter(lambda item : item not in blacklist, potential)) + # Returns None if no potential pellets are in due to blacklist + if not potential: + return None + return min(potential, key=lambda pos : self.distance(curpos, pos)) + + # Quick code for calcul + def merge(self, pos1, pos2): + return [pos1[0] + pos2[0], pos1[1] + pos2[1]] + + # Generater a solution for the maz + def solution(self, length=20): + def build_path(current_node): + path = [] + current = current_node + while current is not None: + path.append(current.position) + current = current.parent + return str(path[::-1]) + + # Pathfinding initial constants + start_node = Node(None, self.positions[-1]) + end_node = Node(None, self.bestPellet(start_node.position)) + open_list, closed_list = [start_node], [] + finished_end_nodes = [] + pathdist = 0 + output = "" + + while len(open_list) > 0: + self.sleep(0.125) + pathdist += 1 + # Choose the best node to work on + current_index, current_node = min(enumerate(open_list), key=lambda item : item[1].f) + open_list.pop(current_index) + closed_list.append(current_node) + + + # Check if we've hit the maximum distance + if pathdist >= length: + return build_path(current_node) + + # If we've hit the "end node", but still distance to travel, setup a new one + if current_node == end_node: + finished_end_nodes.append(end_node) + end_node = self.bestPellet(blacklist=finished_end_nodes) + # if we've acquired all pellets by chance + if end_node is None: + return build_path(current_node) + + # Basically iterates upon all positions next to the current node dependent on the cardinal directions + for offset in self.offsets: + child = self.merge(current_node.position, offset) + # Ensure in bounds + if self.inBounds(child): + child = Node(parent=current_node, position=child) + + # Ensure not already a closed position + if not child in closed_list: + child.g = current_node.g + 1 + child.h = self.distance(child.position, end_node.position) + child.f = child.g + child.h + + # Ensure that child node is + for open_node in open_list: + if child == open_node: + if child.g > open_node.g: + continue + + open_list.append(child) + + return output + + # Quick method for getting a position with the offsets provided + def getPos(self, xoffset=0, yoffset=0): + return [random.randint(1, self.x + xoffset), random.randint(1, self.y + yoffset)] + + # Quick method for marking a postiion + def mark(self, pos, marker='X'): + self.matrix[pos[0]][pos[1]] = marker + + # Mechansim for determining whether a position is in the boundaries of the matrix + def inBounds(self, pos): + return all([pos[0] >= 0, pos[1] >= 0, pos[1] < self.y, pos[0] < self.x]) + + # Determine whether a position is available for use + def available(self, pos, look=' '): + return (self.matrix[pos[0]][pos[1]] == look) if self.inBounds(pos) else False + + def __repr__(self): + return '\n'.join(' - '.join(_) for _ in self.matrix) + +# Driver Code +if __name__ == "__main__": + # User Adjustable Constants + timing = 0.050 + iterations = 1 + size = (15, 15) + + # Build Constants + roundTime = lambda seconds : str(round((seconds) * 1000, 2)) + 'ms' + centerSize = (2 + len(str(iterations))) + dividerTotal = (4 * size[0]) - centerSize + dividerCustom = ('-' * (dividerTotal // 2)) + ' {} ' + ('-' * (dividerTotal // 2)) + dividerTotal = '-' * (dividerTotal + 4) + t1 = time.time() + + # Build and prints matrixes + for x in range(iterations): + snakegrid = SnakeGrid(size[0], size[1], 3) + print(dividerCustom.format(str(x+1).zfill(len(str(iterations))))) + print(snakegrid) + print(dividerTotal) + print(snakegrid.solution()) + time.sleep(timing) + print(dividerTotal) + + # Finish and print timing statistics + t2 = time.time() + print(f'Processing Time : {roundTime(t2 - t1 - (timing * iterations) - snakegrid.sleepTime)}') + print(f'Artificial Time : {roundTime((timing * iterations) + snakegrid.sleepTime)}') + print(f'Total Time : {roundTime(t2 - t1)}') + print(dividerTotal) \ No newline at end of file diff --git a/uil/October 2013 Set/3/java/.idea/misc.xml b/uil/October 2013 Set/3/java/.idea/misc.xml new file mode 100644 index 0000000..4c1c37a --- /dev/null +++ b/uil/October 2013 Set/3/java/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/uil/October 2013 Set/3/java/.idea/modules.xml b/uil/October 2013 Set/3/java/.idea/modules.xml new file mode 100644 index 0000000..16b2576 --- /dev/null +++ b/uil/October 2013 Set/3/java/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/uil/October 2013 Set/3/java/.idea/workspace.xml b/uil/October 2013 Set/3/java/.idea/workspace.xml new file mode 100644 index 0000000..7318077 --- /dev/null +++ b/uil/October 2013 Set/3/java/.idea/workspace.xml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +