Skip to content

Instantly share code, notes, and snippets.

@orisano
Created October 30, 2017 17:12
Show Gist options
  • Save orisano/7f545e0da49beab62973cf47f9aad6b0 to your computer and use it in GitHub Desktop.
Save orisano/7f545e0da49beab62973cf47f9aad6b0 to your computer and use it in GitHub Desktop.
import argparse
import itertools as it
def pipe(x, fn):
for f in fn:
x = f(x)
return x
def main():
parser = argparse.ArgumentParser()
parser.add_argument("n", type=int)
args = parser.parse_args()
pipe(it.count(1), [
lambda x: map(lambda y: str(y).count("1"), x),
it.accumulate,
lambda x: enumerate(x, 1),
lambda x: filter(lambda y: y[0] == y[1], x),
lambda x: it.islice(x, args.n),
list,
reversed,
next,
iter,
next,
print,
])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment