-1
\$\begingroup\$

Task :

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.

\$\endgroup\$
13
  • 3
    \$\begingroup\$ How about skipping digits e.g. 135? \$\endgroup\$
    – Neil
    Nov 23 at 12:24
  • 3
    \$\begingroup\$ @DomHastings It's guaranteed to be a positive integer, so 0 can't be an input. \$\endgroup\$ Nov 23 at 12:37
  • 8
    \$\begingroup\$ 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? \$\endgroup\$
    – Grain Ghost
    Nov 23 at 13:15
  • 1
    \$\begingroup\$ @GrainGhost My wild guess is that they're all numbers that are more easy to guess. \$\endgroup\$ Nov 23 at 13:21
  • 2
    \$\begingroup\$ "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? \$\endgroup\$ Nov 23 at 18:31
4
\$\begingroup\$

JavaScript (Node.js), 103 88 82 bytes

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)
\$\endgroup\$
4
  • 3
    \$\begingroup\$ 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! \$\endgroup\$ Nov 23 at 14:06
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Nov 23 at 14:53
  • \$\begingroup\$ @DomHastings thanks, for that \$\endgroup\$ Nov 23 at 16:33
  • \$\begingroup\$ @KevinCruijssen : I forgot that, dam, thanks \$\endgroup\$ Nov 23 at 16:33
3
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

05AB1E, 19 18 16 15 bytes

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

Try it online or verify all test cases.

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)
\$\endgroup\$
4
1
\$\begingroup\$

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

Jelly, 20 19 12 bytes

DµIṠEoŒḂ*ḊẸ$

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Fails for 1234567890. \$\endgroup\$ Nov 23 at 12:50
  • \$\begingroup\$ @KevinCruijssen Oh, I didn't notice the “0 comes last” rule. Hold on… \$\endgroup\$
    – xigoi
    Nov 23 at 12:55
1
\$\begingroup\$

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
\$\endgroup\$
3
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – xigoi
    Nov 23 at 12:24
  • \$\begingroup\$ @xigoi that's fixed \$\endgroup\$
    – lyxal
    Nov 23 at 13:14
  • \$\begingroup\$ 13 bytes (shamelessly steals Kevin Cruijssen's test #2 for -3 bytes) \$\endgroup\$ Nov 23 at 17:49
0
\$\begingroup\$

Charcoal, 27 bytes

Nθ≔⁺⭆χι⁰η∨‹⮌θχ⊙⟦η⮌η⮌Iθ⟧№ιIθ

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:

Nθ

Input the number.

≔⁺⭆χι⁰η

Get the string 01234567890.

∨‹⮌θχ

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

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

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

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.