Contenuto principale

Risultati per

Athi
Athi
Ultima attività il 17 Nov 2025 alle 15:33

Extracting the digits of a number will be useful to solve many Cody problems.
Instead of iteratively dividing by 10 and taking the remainder, the digits of a number can be easily extracted using String operations.
%Extract the digits of N
N = 1234;
d = num2str(N)-'0';
d =
1 2 3 4
Cephas
Cephas
Ultima attività il 13 Nov 2025 alle 2:40

Instead of growing arrays inside a loop, preallocate with zeros(), ones(), or nan(). It avoids memory fragmentation and speeds up Cody solutions.
A = zeros(1,1000);
Cephas
Cephas
Ultima attività il 12 Nov 2025 alle 7:08

isequal() is your best friend for Cody! It compares arrays perfectly without rounding errors — much safer than == for matrix outputs.
Cephas
Cephas
Ultima attività il 12 Nov 2025 alle 14:13

I realized that using vectorized logic instead of nested loops makes Cody problems run much faster and cleaner. Functions like any(), all(), and logical indexing can replace multiple for-loops easily !