write a function is1234() that takes a numeric vector or matrix as an input and returns whether it contains the numbers 1,2,3,4 in any order in matlab using while loops in matlab

main.m
function result = is1234(input)
    if nargin < 1
        error('Input argument is required');
    end
    
    % Convert input to a single vector
    input = input(:);
    
    % Define target numbers
    target = [1, 2, 3, 4];
    
    i = 1;
    found_nums = zeros(1, 4);
    
    while i <= numel(input) && ~all(found_nums)
        current_num = input(i);
        idx = find(target == current_num);
        
        % If the number is one of the target numbers
        if ~isempty(idx)
            found_nums(idx) = 1;
        end
        
        i = i + 1;
    end
    
    result = all(found_nums);
end
610 chars
29 lines

related categories

gistlibby LogSnag