珠玉のプログラミングのお題を python で書いてみた : 1
#!/bin/env python """ 1.4 The sketch of code(P6-7) That's a sort program using bitmap. """ import random def main(): # input data input_data = random.sample(xrange(0,99), 10) print "input : " + str(input_data) # initialize bitmap = [0 for i in xrange(100)] # set into bitmap for i in input_data: bitmap[i] = 1 # sort & output output_data = [i for i in xrange(100) if bitmap[i] == 1] print "bitmap sort" print "output : " + str(output_data) if __name__ == '__main__': main()
実行結果。
input : [82, 7, 44, 97, 42, 71, 58, 34, 33, 51] bitmap sort output : [7, 33, 34, 42, 44, 51, 58, 71, 82, 97]