64.1k views
3 votes
Write a program that find all possible combination of picking 3 letters or numbers

User Susopeiz
by
5.7k points

1 Answer

5 votes

Answer:

This is a MATLAB code.

clear all

clc

alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789';

for i = 1:combntns(length(alphabet),3) %takes the combination of (36,3)

pick(1) = ceil(rand()*length(alphabet)); %randomly chooses a letter or number

alphabet(find(alphabet == pick(1))) = ''; %removes the chosen character from the list

pick(2) = ceil(rand()*length(alphabet)); %randomly chooses second letter or number

alphabet(find(alphabet == pick(2))) = ''; %removes the chosen character

pick(3) = ceil(rand()*length(alphabet)); %randomly chooses the third letter or number

result(i,:) = alphabet(pick); %saves the 3-character pick into an array

alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'; %restores the original list of letters and numbers

end

disp(result) %displays all the combinations

Explanation: Please read the comments on each line.

User Jwosty
by
5.5k points