Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //: Playground - noun: a place where people can play
- //: Roots of Unity Often Lie
- indirect enum BTree {
- case empty
- case branch(BTree, BTree)
- }
- func encode(_ t: (BTree, BTree, BTree, BTree, BTree, BTree, BTree)) -> BTree {
- switch t {
- case (.empty, .empty, .empty, .empty, .empty, .empty, .empty):
- return .branch(.empty, .empty)
- case let (.empty, .empty, .empty, .empty, .empty, .empty, .branch(b1, b2)):
- return .branch(.branch(.branch(.branch(.branch(.empty, .empty), .empty), b1), .empty), b2)
- case let (.empty, .empty, .empty, .empty, .empty, .branch(b1, b2), .empty):
- return .branch(.empty, .branch(b1, b2))
- case let (.empty, .empty, .empty, .empty, .empty, .branch(b1, b2), .branch(b3, b4)):
- return .branch(.branch(.branch(.branch(.branch(.empty, .empty), .branch(b1, b2)), b3), .empty), b4)
- case (.empty, .empty, .empty, .empty, .branch(.empty, .empty), .empty, .empty):
- return .empty
- case let (.empty, .empty, .empty, .empty, .branch(.empty, .empty), .branch(b1, b2), .empty):
- return .branch(.branch(.empty, b1), b2)
- case let (.empty, .empty, .empty, .empty, .branch(.empty, .branch(b1, b2)), b3, .empty):
- return .branch(.branch(.branch(.branch(.empty, b1), b2), .empty),b3)
- case let (.empty, .empty, .empty, .empty, .branch(.empty, .empty), b1, .branch(b2, b3)):
- return .branch(.branch(.branch(.empty, b1), b2), b3)
- case let (.empty, .empty, .empty, .empty, .branch(.empty, .branch(b1, b2)), b3, .branch(b4, b5)):
- return .branch(.branch(.branch(.branch(.empty, b1),b2), .branch(b3, b4)),b5)
- case let (.empty, .empty, .empty, .empty, .branch(.branch(b1, b2), b3), b4, b5):
- return .branch(.branch(.branch(.branch(.branch(.empty, .empty), b1), b2), .branch(b3, b4)),b5)
- case let (.empty, .empty, .empty, .branch(b1, b2), b3, b4, b5):
- return .branch(.branch(.branch(.branch(.branch(.empty, .branch(.empty, b1)), b2), b3), b4), b5)
- case let (.empty, .empty, .branch(b1, b2), b3, b4, b5, b6):
- return .branch(.branch(.branch(.branch(.branch(.empty,.branch(.branch(.empty, b1),b2)),b3),b4),b5),b6)
- case let (.empty, .branch(b1, b2), b3, b4, b5, b6, b7):
- return .branch(.branch(.branch(.branch(.branch(.empty,.branch(.branch(.branch(.empty, b1), b2), b3)), b4), b5), b6), b7)
- case let (.branch(.empty, b1), b2, b3, b4, b5, b6, b7):
- return .branch(.branch(.branch(.branch(.branch(.branch(b1, b2), b3), b4), b5), b6), b7)
- case let (.branch(.branch(b1, b2),b3), b4, b5, b6, b7, b8, b9):
- return .branch(.branch(.branch(.branch(.branch(.empty,.branch(.branch(.branch(.branch(b1, b2), b3), b4), b5)), b6), b7), b8), b9)
- }
- }
Add Comment
Please, Sign In to add comment