Problem 242. Make a function that returns its own character count
Write a function that returns a 128 element vector with an accurate inventory of the ASCII characters in its own function file. The test suite uses textscan to verify that your function returns the exact same census.
file = textscan(fid,'%c','CommentStyle','%','Whitespace','')
filetext = file{1};
texthist = histc(filetext,1:128);
Newlines are suppressed by this approach, so you may assume the counts for ASCII 10 and 13 are zero.
Special Note: The characters associated with ASCII values 33-41 are not allowed in your function. For clarity, these are
33 !
34 "
35 #
36 $
37 %
38 &
39 '
40 (
41 )
Solution Stats
Problem Comments
-
1 Comment
minnolina
on 16 Jun 2024
I'm not sure if I've understood the test correctly.
ha = histc(file{1},1:128);
hp = omphaloskeptic;
assert(~any(ismember(33:41,find(ha))),'Used an illegal character');
This assertion checks if forbidden characters are used in ha, which is the histogram of the file content. However, our output is hp, which is the histogram produced by the function omphaloskeptic. Shouldn't the assertion check for forbidden characters in hp, not ha, or am I missing something?
Solution Comments
Show commentsGroup

Tough Stuff
- 19 Problems
- 7 Finishers
- Make a function that returns its own character count
- love is an n-letter word
- Reverse Boggle
- Cumulative maximum of an array
- Pattern Recognition 3 - Variable Unit and Array Length (including cell arrays)
- Cumulative minimum of an array
- Find the Final State of an Abelian Sandpile
- Decimation - Optimized for speed
- Construct a "diagAdiag" matrix
- Find vampire numbers
- Math with Roman Numerals
- Find similar sequences
- Given two arrays, find the maximum overlap
- Some Assembly Required
- N-Dimensional Array Slice
- Find the stride of the longest skip sequence
- Create initial basic feasible solution for transportation problems -Minimum Cost Method
- Numbers spiral diagonals (Part 2)
- Find the biggest empty box
Problem Recent Solvers30
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!