1+ import argparse
2+ import sys
3+
4+ def hmdin (count , stack_size = 64 , container_size = 27 ):
5+ i = count % stack_size
6+ s_raw = count // stack_size
7+ s = s_raw % container_size
8+ c = s_raw // container_size
9+ return c , s , i
10+
11+ def pretty_print_kind (count , name ):
12+ return f"{ count } { name } { '' if count == 1 else 's' } "
13+
14+ def pretty_print (chests , stacks , items ):
15+ components = []
16+ if chests > 0 :
17+ components .append (pretty_print_kind (chests , "chest" ))
18+ if stacks > 0 :
19+ components .append (pretty_print_kind (stacks , "stack" ))
20+ if items > 0 or len (components ) == 0 :
21+ components .append (pretty_print_kind (items , "item" ))
22+ if len (components ) == 1 :
23+ return components [0 ]
24+ return ", " .join (components [:- 1 ]) + " and " + components [- 1 ]
25+
26+ def csv_print (chests , stacks , items , separator = "," ):
27+ return separator .join (chests , stacks , items )
28+
29+ if __name__ == '__main__' :
30+ parser = argparse .ArgumentParser ()
31+ parser .add_argument ("count" , help = "Number of items to evaluate" , type = int )
32+ parser .add_argument ("--stack_size" , help = "Stack size of the respective item" , type = int , default = 64 )
33+ parser .add_argument ("--as_csv" , action = "store_true" )
34+ args = parser .parse_args ()
35+ printer = csv_print if args .as_csv else pretty_print
36+ if args .count < 0 :
37+ print (f"-{ pretty_print_kind (- args .count , 'item' )} { 'are' if args .count != 1 else 'is' } imaginary." )
38+ sys .exit (1 )
39+ print (f"{ pretty_print_kind (args .count , 'item' )} { 'are' if args .count != 1 else 'is' } { printer (* hmdin (args .count , args .stack_size ))} ." )
40+
0 commit comments