Problem 42323. With apologies to William Blake
Coder Coder, typing fast Sitting at your desk, aghast. What immortal MATLAB script will solve this problem, nice and quick?
You are given a number. Your task is to write a MATLAB script that will calculate the smallest positive number you need to add to your original number so that each digit in your sum will have horizontal symmetry. For this problem, those numbers are [0 1 3 8]
For example:
- If you are given 27, your script should output 3, as 27+3=30. Both 3 and 0 have horizontal symmetry.
- If you are given 801, your script should output 0, as 801+0=801. 8, 0 and 1 are all horizontally symmetric.
- If you are given 900, your answer should be 100, as 900+100=1000, which is the next highest number that is horizontally symmetric.
Good luck. May you become a poet, and not even know it.
Solution Stats
Problem Comments
-
4 Comments
James is the master of deceptively difficult Cody problems.
Deceptively difficult indeed. Took me two wrong rabbit holes to even figure out what I was actually trying to do.
Of course, it would have helped a lot more if the test cases were better. 5 & 6 are the only useful ones till you realize 7 & 8 are practically giving you the answer.
Rather difficult.¡, but figured out
however, I would like to see some test case with a number starting with lots of 8s: 88888888882123, for example.
Solution Comments
Show commentsGroup

Operations
- 32 Problems
- 14 Finishers
- modular arithmetic
- Sum the 'edge' values of a matrix
- Subtract integers and add doubles
- Multiplication
- Let's get back to school, and create multiplication tables
- Make an N-dimensional Multiplication Table
- Mmm! Multi-dimensional Matrix Multiplication
- Accurate Division
- Number of even divisors of a given number
- Raise a polynomial to a power
- Array ex-OR
- Airline Ticket Mod7 Checksum
- Determinant without using det()
- Calculate the hypotenuse of a right triangle without using ^ and sqrt ()
- Calculate sin(x) without sin(x)
- Calculate cosine without cos(x)
- Negative without '-'
- calculate PI without using pi function
- Church Encoding
- Concatenated roots
- Product of Each Column
- Perl 1: push
- Vector push
- Vector pop
- Shuffle
- Please check the last row
- Converting Decimal to Binary
- Temperature Conversion Utility
- Temperature Conversion Utility (Strings)
- Calculate the sum of two polynomials
- Moving average (variable kernel length)
- Weighted average
Problem Recent Solvers70
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!