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

User Susopeiz
by
7.9k 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
7.6k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.