Building a Combination Lock Picker in Ruby

0
280

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.

Summary

Build a method that helps give the full set of combinations associated with figuring out the numbers to a combination lock.

Exercise File

Code File

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.

Solution

Can be found on the solutions branch on github.

LEAVE A REPLY

Please enter your comment!
Please enter your name here