Find code that adds one 0 to each sequence of 0 in a string (composed with only 0 or 1).
'1010' -> '100100'
'0110' -> '001100'
'1000' -> '10000'
'1111' -> '1111'
Didn't really understand the problem right from reading the task itself, but from reading the test cases. Really fun problem though. First time I used regexprep function, so I learned a lot!
The problem asks to "add" a zero, no mention of append or prepend! Nice general solution though, and a new trick learned ($&0)
I feel I've overcomplicated my solution
regexprep(x, '(?(?=0[^0]|0$)0|)', '00')
I didn't know about $0! Nifty.
Neither did I! Matlab has great help.
The solution is not correct for the generalized case. 0$0 does a pre-pend of 0 not an append. The correct general solutions is either $00, or better to avoid operator ($0) confusion with the test set using 0s is operator ($%) $&0.
The solution is not correct for the generalized case. 0$0 does a pre-pend of 0 not an append. The correct general solutions is either $00, or better to avoid operator ($0) confusion with the test set using 0s is operator ($&) $&0. (Typo in prior comment)
DNA N-Gram Distribution
Count from 0 to N^M in base N.
Find the biggest empty box
Sum the entries of each column of a matrix which satisfy a logical condition.
Create a Multiplication table matrix...
Mysterious digits operation (easy)
Permute diagonal and antidiagonal
Pandigital number n°2 (Inspired by Project Euler 32)
Magic is simple (for beginners)
Longest Collatz Sequence
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office