Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- mem_banks = [14, 0, 15, 12, 11, 11, 3, 5, 1, 6, 8, 4, 9, 1, 8, 4]
- def increaseblk(idx):
- global mem_banks
- mem_banks[idx] += 1
- def join_ints(a_list):
- return int(''.join(map(str, a_list)))
- previous_states = [join_ints(mem_banks)]
- cycles = 0
- while True:
- max_block = max(mem_banks)
- tgt = mem_banks.index(max_block)
- iter_ = list(range(tgt+1, 16)) + list(range(0, tgt))
- while mem_banks[tgt] > 0:
- idx = iter_.pop(0)
- increaseblk(idx)
- mem_banks[tgt] -= 1
- cycles += 1
- if join_ints(mem_banks) in previous_states:
- break
- else:
- previous_states.append(join_ints(mem_banks))
- # PART ONE
- print(cycles)
- # PART TWO
- print(cycles - previous_states.index(join_ints(mem_banks)))
Advertisement
Add Comment
Please, Sign In to add comment