Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from os import listdir
- import sys
- def extractInt(ba, i, l):
- return int.from_bytes(ba[i:i+l], byteorder='little', signed=False)
- def extractString(ba, i):
- length = extractInt(ba, i, 1)
- i += 1
- return ba[i : i + length].decode('utf-8')
- def pruneFrontier(sols):
- sols = sols[:]
- #iterating all pairs i,j
- i = 0
- while i < len(sols):
- s1 = sols[i]
- j = i + 1
- while j < len(sols):
- s2 = sols[j]
- comp = [s1[k] <= s2[k] for k in range(4)]
- #if first is better on all scores, remove second
- if all(comp):
- sols.pop(j)
- else:
- j += 1
- i += 1
- return sols
- if __name__ == "__main__":
- names = {}
- names['P044'] = 'Lesson: Introduction'
- names['P001'] = 'Lesson: Arms'
- names['P004'] = 'Lesson: Pivots'
- names['P002'] = 'Lesson: Pistons'
- names['P003'] = 'Lesson: Tracks'
- names['P006'] = 'Lesson: Transmutation'
- names['P005'] = 'Lesson: Bonding'
- skip = set(names.keys())
- #chapter 1
- names['P007'] = 'Stabilized Water'
- names['P010'] = 'Refined Gold'
- names['P009'] = 'Face Powder'
- names['P011'] = 'Waterproof Sealant'
- names['P013'] = 'Hangover Cure'
- names['P008'] = 'Airship Fuel'
- names['P012'] = 'Precision Machine Oil'
- names['P014'] = 'Health Tonic'
- names['P015'] = 'Stamina Potion'
- #chapter 2
- names['P016'] = 'Hair Product'
- names['P019'] = 'Rocket Propellant'
- names['P018'] = 'Mist of Incapacitation'
- names['P017'] = 'Explosive Phial'
- names['P020'] = 'Armor Filament'
- names['P021'] = 'Courage Potion'
- names['P022'] = 'Surrender Flare'
- #chapter 3
- names['P024'] = 'Alcohol Separation'
- names['P025'] = 'Water Purifier'
- names['P026'] = 'Seal Solvent'
- names['P027'] = 'Climbing Rope Fiber'
- names['P028'] = 'Warming Tonic'
- names['P030b'] = 'Life Sensing Potion'
- names['P029'] = 'Very Dark Thread'
- #chapter 4
- names['P031b'] = 'Litharge Separation'
- names['P034'] = 'Stain Remover'
- names['P033'] = 'Sword Alloy'
- names['P032'] = 'Invisible Ink'
- names['P036'] = 'Purified Gold'
- names['P035'] = 'Alchemical Jewel'
- names['P037'] = 'Golden Thread'
- #chapter 5
- names['P038'] = 'Mist of Hallucination'
- names['P042'] = 'Timing Crystal'
- names['P039'] = 'Voltaic Coil'
- names['P040'] = 'Unstable Compound'
- names['P041'] = 'Curious Lipstick'
- names['P043'] = 'Universal Solvent'
- #journal 1
- names['P054'] = "Van Berlo's Wheel"
- names['P055'] = "Van Berlo's Chain"
- names['P056'] = 'Reactive Cinnabar'
- names['P057'] = 'Silver Caustic'
- names['P058'] = 'Lambent II/IX'
- #journal 2
- names['P059'] = "Explorer's Salve"
- names['P060'] = 'Preservative Salt'
- names['P061'] = 'Sailcloth Thread'
- names['P062'] = 'Buoyant Cable'
- names['P063'] = 'Spyglass Crystal'
- #journal 3
- names['P064'] = "Ravari's Wheel"
- names['P065'] = 'Lubricating Filament'
- names['P066'] = 'Resonant Crystal'
- names['P067'] = 'Refined Bronze'
- names['P068'] = 'Ablative Crystal'
- #journal 4
- names['P069'] = 'Proof of Completeness'
- names['P070'] = 'Wheel Representation'
- names['P071'] = 'Synthesis via Alcohol'
- names['P072'] = 'Universal Compound'
- #journal 5
- names['P086'] = 'General Anaesthetic'
- names['P088'] = 'Wakefulness Potion'
- names['P085'] = 'Suture Thread'
- names['P087'] = 'Blood-Stanching Powder'
- names['P089'] = 'Tonic of Hydration'
- #journal 6
- names['P096'] = "Van Berlo's Pivots"
- names['P095'] = 'Reactive Gold'
- names['P097'] = "Assassin's Filament"
- names['P098'] = 'Vaporous Solvent'
- names['P099'] = 'Alchemical Slag'
- #journal 7
- names['P100'] = 'Explosive Victrite'
- names['P101'] = 'Celestial Thread'
- names['P102'] = 'Visillary Anaesthetic'
- names['P104'] = 'Animismus Buffer'
- names['P103'] = 'Electrum Separation'
- #production 1
- names['P076'] = 'Silver Paint'
- names['P080'] = 'Viscous Sludge'
- names['P075'] = 'Fragrant Powders'
- names['P074'] = 'Rat Poison'
- names['P083'] = 'Special Amaro'
- names['P078'] = 'Vapor of Levity'
- names['P079'] = 'Abrasive Particles'
- names['P081'] = 'Eyedrops of Revelation'
- names['P082'] = 'Parade-Rocket Fuel'
- names['P077'] = 'Aether Detector'
- names['P084'] = 'Reconstructed Solvent'
- #production 2
- names['P091b'] = 'Hexstabilized Salt'
- names['P090'] = 'Lustre'
- names['P092'] = 'Lamplight Gas'
- names['P093'] = 'Conductive Enamel'
- names['P094'] = 'Welding Thermite'
- solutions = {}
- files = [f for f in listdir('.') if f.endswith('.solution')]
- for f in files:
- fh = open(f, 'rb')
- ba = bytearray(fh.read())
- fh.close()
- i = 4
- puzzleKey = extractString(ba, i)
- i += len(puzzleKey) + 1
- name = extractString(ba, i)
- i += len(name) + 1
- datastart = i
- #first number seems to be for validation.
- #Must be 4
- valid = extractInt(ba, i, 4)
- i += 8
- if valid!=4:
- continue
- cycles = extractInt(ba, i, 4)
- i += 8
- cost = extractInt(ba, i, 4)
- i += 8
- area = extractInt(ba, i, 4)
- i += 8
- instructions = extractInt(ba, i, 4)
- i += 8
- #only care about puzzles
- #ignore custom(c) and workshop(w) for now
- if puzzleKey.startswith('P'):# or True:
- s = (cost, cycles, area, instructions, f)
- if not puzzleKey in solutions:
- solutions[puzzleKey] = []
- solutions[puzzleKey].append(s)
- keys = list(solutions.keys())
- keys.sort()
- count = [0, 0]
- for k in keys:
- solsRaw = solutions[k]
- solsRaw.sort() #just for fun, not really needed
- sols = pruneFrontier(solsRaw)
- #skip the lessons
- if k in skip:
- continue
- if k not in names:
- print('Unknown name "{}" in file "{}"'.format(k, sols[0][-1]), file=sys.stderr)
- n = names.get(k, k)
- solstrs = ['/'.join(map(str,sol[:4])) for sol in sols]
- solstr = ', '.join(solstrs)
- print(n, ':', solstr, ' ')
- count[0] += len(sols)
- count[1] += len(solsRaw)
- print(count[0], '/', count[1], 'solutions on your frontier')
- input("Press Enter to quit")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement