fork download
  1. function n = f(a, b)
  2. if isempty(a) || isempty(b)
  3. n = numel(a);
  4. else
  5. n = f(a(find(a == b(1), 1):end), b(2:end));
  6. end
  7. end
  8. function tt = trick_or_treat(s)
  9. [trick treat] = deal(f(s, 'trick'), f(s, 'treat'));
  10. tt = {'trick' 'treat' 'none'}{[treat < trick trick < treat trick == treat]};
  11. end
  12. cellfun(@(s) disp(trick_or_treat(s)), {'trick or treat' '. tr ick' 'ttrriecatk' 'tri kc eat' 'my money'}');
Success #stdin #stdout 0.06s 44916KB
stdin
Standard input is empty
stdout
trick
trick
treat
treat
none