I don't really know how to formulate this, but I have a bunch of IATA codes, and I want to generate all the possible combinations ex : JFK/LAX, BOS/JFK, ...etc, separated by a character such as "/" or "|".
use crunch to generate all the possible IATA codes comsbination
91 Views Asked by Ash At
1
Here we assume your IATA codes are stored in the file
file; one code per line.crunchhas the-qoption which generates permutations of lines from a file. However, in this modecrunchignores most of the other options like<max-len>, which would be important here to print only pairs of codes.Therefore, it would be easier and faster to …
Use something different than
crunchFor instance, try
If you really, really, really want, you can …
Translate the input into something
crunchcan work withWe translate each line from
fileto a unique single character, supply that list of characters tocrunch, and then translate the result back.crunchsupports Unicode characters, so files with more than 255 lines are totally fine. Here we enumerate the lines infileby characters in Unicode's Supplementary Private Use Area-A. Therefore,filemay have at most 65'534 lines.If you need more lines, you could combine multiple Unicode planes, but at some point you might run into
ARG_MAXissues. Also, with 65'534 lines you would already generate (a bit less than) 65'534^2 = 4'294'705'156 pairs, occupying more than 34 GB when translated into pairs of IATA codes.I suspect the back-translation to be a huge slowdown, so above alternative seems to be better in every aspect (efficiency, brevity, maintainability, …).