March 3 - Building a Combination Lock Picker in Ruby
In this guide you'll learn how to build a method that returns the potential number of combinations associated with building a lock picking method, including both how to count the number of permutations and generating the full set of options.
Guide Tasks
- Read Tutorial
- Watch Guide Video
- Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license
Already a Bottega Student? Sign In
Summary
Build a method that helps give the full set of combinations associated with figuring out the numbers to a combination lock.
Exercise Description
Given an array of integers, build a method that returns either the count or the actual combinations of numbers it will take to pick a combination lock.
Example Input
To return the count by itself:
lockpick [14, 9, 29] # 6
And to return the combination values:
lockpick [14, 9, 29], combinations: true # [[14, 9, 29], [14, 29, 9], [9, 14, 29], [9, 29, 14], [29, 14, 9], [29, 9, 14]]
Real World Usage
This example will test your knowledge of Ruby arrays, additionally, it will help you discover the tools available to finding combinations of values. In addition to combination lock picking, this can also be helpful when it comes to building algorithms.