# Check for Wonky numbers [closed]

Wonky numbers are 3-or-more digit numbers that meet one or more of the following criteria:

• Any digit followed by all zeros: 100, 70000
• Same digit throughout the entirety of the number : 1111, 777777777
• The digits are in consecutive ascending order : 1234, 1234567890 (for 0 see below)
• The digits are in consecutive descending order : 4321, 9876543210
• The number is a palindromic number : 1221, 123321

Ascending and descending order mean no repeated digits in their so 122 is not ascending in this case, you may also not skip digits 1245 is not Wonky because 3 is missing. For both ascending and descending numbers 0 will come last so order is : 1234567890 and 9876543210 for ascending and descending respectively. Numbers can be given in any order, do not assume that it may be in some specific order : 1234, 987, 76842 are all valid numbers.

# I / O :

Your input will always be a number (positive) in the following range : $$99 < Z < 1,000,000,000$$

Check if the number is a Wonky number.

You may not take input as anything but a number unless your language is simply incapable of handling that, in which case take input in any reasonable format (per language)

You may output any truthy value (for wonky numbers) and any falsy value (for non wonky numbers).

# Examples :

Input : Output

100 : true
12344321 : true
77777777777 : true
132 : false
321 : true
122 : false
987789 : true
98765 : true
120000 : false
100001 : true
786 : false
890 : true


# Extra Credit :

Check if number is not a Wonky number, but one of next x numbers is a wonky number, where x is in range of 1 (inclusive) to 10 (exclusive).

This is code-golf, so shortest code in bytes wins.

• How about skipping digits e.g. 135?
– Neil
Commented Nov 23, 2021 at 12:24
• @DomHastings It's guaranteed to be a positive integer, so 0 can't be an input. Commented Nov 23, 2021 at 12:37
• To explain my downvote: Regardless of clarity issues, this challenge is just a random collection of disconnected tasks. There's no internal logic that makes it interesting. What's the connection between rep-digits and descending numbers? Commented Nov 23, 2021 at 13:15
• @GrainGhost My wild guess is that they're all numbers that are more easy to guess. Commented Nov 23, 2021 at 13:21
• "Numbers can be given in any order, do not assume that it may be in some specific order : 1234, 987, 76842 are all valid numbers." What does this mean? How is 76842 a "valid" number? Valid input? Also a number of all the same digits is inherently a palindromic number. What's the point of that stipulation? Commented Nov 23, 2021 at 18:31

n=>"1234567890|9876543210".match(n)|/^(.0+|(.?)(.?)(.?)(.?).?\5\4\3\2\1)$/.test(n)  Try it online! • -15 bytes thanks to Dom Hastings. • -6 bytes thanks to Kevin Cruikssen. # Original : # JavaScript (Node.js), 103 bytes n=>RegExp(n).test("1234567890|9876543210")|/^(\d0+|(\d)\1+|(\d?)(\d?)(\d?)(\d?)\d?\6\5\4\3\2)$/.test(n)


Try it online!

# Changes :

• changed all \d to . because input is guaranteed to be a number.
• instead of regex(n).test switch to match
• Removed the check for same digits (because palindromes check that)
• Using both strings as a regex is clever! You can save 15 bytes using .match instead of .test (although it does change the return to just truthy instead of boolean true) and you can drop (\d)+| from the regex as it's covered in the palindrome checker. Try it online! Commented Nov 23, 2021 at 14:06
• To build further on @DomHastings 88 byte version in the previous comment: you can save 6 more bytes by changing the \d to ., since the input is guaranteed to be an integer and every character will be a digit: Try it online. Commented Nov 23, 2021 at 14:53
• @DomHastings thanks, for that Commented Nov 23, 2021 at 16:33
• @KevinCruijssen : I forgot that, dam, thanks Commented Nov 23, 2021 at 16:33

# Retina, 43 bytes

$¶$^$¶10*#0 Y#d \b(.+)¶(.+¶)?.*\1|¶0*.¶  Try it online! Link includes test cases. Explanation: $
¶$^$¶10*#0
Y#d


Append the reverse of the input and build up the string 01234567890.

\b(.+)¶(.+¶)?.*\1|¶0*.¶


Check whether either the string or its reverse is a substring of each other (i.e. palindromic) or the created string, or whether the reverse is all zeros except the last digit.

# 05AB1E, 191816 15 bytes

RT‹žhĆIÂ‚åàIÂQM


Explanation:

RT‹      # Rule 1:
R        #  Reverse the (implicit) input
T‹      #  Check if it's smaller than 10
žhĆIÂ‚åà # Rules 3 & 4:
žh       #  Push builtin 0123456789
Ć      #  Enclose, append its own head: 01234567890
I     #  Push the input-integer again
Â    #  Bifurcate it (short for Duplicate & Reverse copy)
‚   #  Pair them together
å  #  Check for both whether it's a substring of 01234567890
à #  Pop and push the maximum to check if either was truthy
IÂQ      # Rules 2 & 5:
I        #  Push the input-integer yet again
Â       #  Bifurcate it (short for Duplicate & Reverse copy)
Q      #  Check if both are equal, thus it's a palindrome
#  (if all digits are the same it's also a palindrome, so no need to
#  check rule 2 separately)
M        # Push the largest number on the stack to check if any were truthy
# (which is output implicitly as result)

• 14 bytes? Commented Nov 23, 2021 at 12:52
• @lyxal Fails for 1234567890 (should be truthy), and 135, 159, 91, 19 (should all be falsey) I'm afraid. Commented Nov 23, 2021 at 12:54
• I think this is a valid 18 byter - took me a few tries to actually get the right built-ins lol Commented Nov 23, 2021 at 13:02
• @lyxal Almost, but it fails for 122 I'm afraid. Everything else seems correct, though. (PS: If you want to use my test suite to verify, simply paste your program in the code-block and replace all I with y.) Commented Nov 23, 2021 at 13:04

Broken because I didn't notice the “0 comes last” rule. I'll try to fix it.

# Jelly, 2019 12 bytes

DµIṠEoŒḂ*ḊẸ\$


Try it online!

• Fails for 1234567890. Commented Nov 23, 2021 at 12:50
• @KevinCruijssen Oh, I didn't notice the “0 comes last” rule. Hold on… Commented Nov 23, 2021 at 12:55

# Vyxal, 18 bytes

Ḣ0J≈?¯ȧ:19∩⊍¬?Ḃ⁼Wa


Try it Online!

0 can still go frick itself.

## Explained

Ḣ0J≈?¯ȧ:19∩⊍¬?Ḃ⁼Wa
Ḣ0J≈               # Test 1: Is the input[1:] all 0's? (not why I hate 0 btw)
?¯ȧ:19∩⊍¬      # Test 2: Is the differences between all numbers either 1 or 9? (this is why I hate 0)
?Ḃ⁼   # Test 3: Is the input a palindrome?
Wa # Did any of the tests pass? For some reason the -G flag doesn't work here to save 2 bytes. /shrug

• The second criterion is implied by the fifth one, so it's redundant. And if “descending” is not “strictly descending”, then the first criterion is also redundant; otherwise, this program is wrong. Commented Nov 23, 2021 at 12:24
• @xigoi that's fixed Commented Nov 23, 2021 at 13:14
• 13 bytes (shamelessly steals Kevin Cruijssen's test #2 for -3 bytes) Commented Nov 23, 2021 at 17:49

# Charcoal, 27 bytes

Ｎθ≔⁺⭆χι⁰η∨‹⮌θχ⊙⟦η⮌η⮌Ｉθ⟧№ιＩθ


Try it online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. - for wonky, nothing if not. Would have saved 4 bytes if it wasn't necessary to take input as a number. Explanation:

Ｎθ


Input the number.

≔⁺⭆χι⁰η


Get the string 01234567890.

∨‹⮌θχ


Output - if the reverse of the number is less than 10, or...

⊙⟦η⮌η⮌Ｉθ⟧№ιＩθ


... any of the strings 01234567890, 09876543210 or the reverse of the number as a string contain the number as a string.