Skip to main content
added 439 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94

Assumes, as implied by the test cases, that number inputsthe input will always contain multiple digitsbe, or result in, a positive integer - i.e. not 0. 

Outputs false for invalid string inputs containing at least one valid letter, throws an overflow error for all others.

Explanation

We can avoid explicitly removing N & U before trying to convert a string to a number thanks to the way Japt's custom base conversion works. Unlike the native parseInt function which stops parsing when it encounters an invalid character and returns the result up to that point, when using a custom base invalid characters are ignored and parsing continues from the next valid character.

Assumes, as implied by the test cases, that number inputs will always contain multiple digits. Outputs false for invalid string inputs containing at least one valid letter, throws an overflow error for all others.

Assumes, as implied by the test cases, that the input will always be, or result in, a positive integer - i.e. not 0. 

Outputs false for invalid string inputs containing at least one valid letter, throws an overflow error for all others.

Explanation

We can avoid explicitly removing N & U before trying to convert a string to a number thanks to the way Japt's custom base conversion works. Unlike the native parseInt function which stops parsing when it encounters an invalid character and returns the result up to that point, when using a custom base invalid characters are ignored and parsing continues from the next valid character.

added 114 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94

Assumes, as implied by the test cases, that number inputs will always contain multiple digits. Outputs false for invalid string inputs containing at least one valid letter, throws an overflow error for all others.

Assumes number inputs will always contain multiple digits. Outputs false for invalid string inputs.

Assumes, as implied by the test cases, that number inputs will always contain multiple digits. Outputs false for invalid string inputs containing at least one valid letter, throws an overflow error for all others.

deleted 731 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94

Japt v1.4.5, 61 59 92 85 84 70 6868 52 bytes

Assumes number inputs will always contain multiple digits. Outputs 0false for invalid string inputs.


"OIREASGTBP"
"%v"²
Ñ?UsV eW,_ínuÃeWu _íuue"%v"²_ínuÃe"%V"²_íuu:UnV *!Uè["[^{V}NU]"WWu]q|U¶ßU=nV)©U

Try itTry it (Includes all test cases)

  • 2 4 bytes saved thank to obarakon, who also convinced me to take this up again after I abandoned it earlier. I wish he hadn't!
  • 33 26 25 23(!)23(!) 7 bytes sacrificed to check input validity.
\n"..."\n"%v"²\nÑ"\nÑ?UsV eW,_ínuÃeWu _íuue"%v"²_ínuÃe"%V"²_íuu:UnV *!Uè["[^{V}NU]"WWu]q|U¶ßU=nV)©U     :Implicit input of integer or string U
\n                                                                   :Prevent input value of U from being overridden
  "..."\n                                                            :Assign the string "OIREASGTBP" to variable V
         "%v"²             Ñ                                          :"%v" duplicated, givingMultiply the Japt RegEx classinput forby /[AEIOU][AEIOU]/g2
              \n            ?                                         :AssignIf totruthy variable(not WNaN)
                Ñ              UsV                                      :Multiply the input by 2
         Convert U to a string in custom base ?V
               e                                    :If truthy (not NaN)
              Recursively replace all occurrences UsVof
                "%v"                                :  Convert U to a string in custom baseLiteral V"%v"
                      eW              ²                               :  Recursively replace allDuplicate, occurrencesgiving ofthe W
Japt RegEx class for /[AEIUO][AEIOU]/g
                     _                                         :  :  ByPass passingeach themmatch through the following function
                          í                                       :   :    Interleave with
                           n                                       :  :      Literal "n"
                            u                                      :  :      Uppercase
                             Ã                                       :  End replace
                              eWu                e"%V"²                    :  Recursively replace all occurrences of W uppercased (RegEx /[^AEIOU][^AEIOU]/g)
                                  _                                  :  ByPass passingeach themmatch through the following function
                                   íuu                               :    Interleave with "u" uppercased
                                      :                              :Else
                                       UnV                           :  ConvertCheck U from a base-V string tofor anequality integerwith
                                           *!            ß            :  Multiply by theRecursive logicalcall NOTwith ofargument
                                             U=          :    Count the occurrencesReassign into U of
                                               [             nV        :      Construct an array containing
                                            Convert U from a "[^{base-V}NU]"           :        Literal string with V interpolated,
                                                          WWu        :        W &to uppercasean Winteger
                                                             ])       :      End array
                recursive call
                                             q|©U     :     Logical JoinAND with "|", giving "[^OIREASGTBPNU]|%v%v|%V%V"=/[^OIREASGTBPNU]|[AEIOU][AEIOU]|[^AEIOU][^AEIOU]/gU

Japt v1.4.5, 61 59 92 85 84 70 68 bytes

Assumes number inputs will always contain multiple digits. Outputs 0 for invalid string inputs.


"OIREASGTBP"
"%v"²
Ñ?UsV eW,_ínuÃeWu _íuu:UnV *!Uè["[^{V}NU]"WWu]q|

Try it (Includes all test cases)

  • 2 4 bytes saved thank to obarakon, who also convinced me to take this up again after I abandoned it earlier. I wish he hadn't!
  • 33 26 25 23(!) bytes sacrificed to check input validity.
\n"..."\n"%v"²\nÑ?UsV eW,_ínuÃeWu _íuu:UnV *!Uè["[^{V}NU]"WWu]q|     :Implicit input of integer or string U
\n                                                                   :Prevent input value of U from being overridden
  "..."\n                                                            :Assign the string "OIREASGTBP" to variable V
         "%v"²                                                       :"%v" duplicated, giving the Japt RegEx class for /[AEIOU][AEIOU]/g
              \n                                                     :Assign to variable W
                Ñ                                                    :Multiply the input by 2
                 ?                                                   :If truthy (not NaN)
                  UsV                                                :  Convert U to a string in custom base V
                      eW                                             :  Recursively replace all occurrences of W
                         _                                           :  By passing them through the following function
                          í                                          :    Interleave with
                           n                                         :      Literal "n"
                            u                                        :      Uppercase
                             Ã                                       :  End replace
                              eWu                                    :  Recursively replace all occurrences of W uppercased (RegEx /[^AEIOU][^AEIOU]/g)
                                  _                                  :  By passing them through the following function
                                   íuu                               :    Interleave with "u" uppercased
                                      :                              :Else
                                       UnV                           :  Convert U from a base-V string to an integer
                                           *!                        :  Multiply by the logical NOT of
                                                       :    Count the occurrences in U of
                                               [                     :      Construct an array containing
                                                "[^{V}NU]"           :        Literal string with V interpolated,
                                                          WWu        :        W & uppercase W
                                                             ]       :      End array
                                                              q|     :      Join with "|", giving "[^OIREASGTBPNU]|%v%v|%V%V"=/[^OIREASGTBPNU]|[AEIOU][AEIOU]|[^AEIOU][^AEIOU]/g

Japt v1.4.5, 61 59 92 85 84 70 68 52 bytes

Assumes number inputs will always contain multiple digits. Outputs false for invalid string inputs.


"OIREASGTBP"
Ñ?UsV e"%v"²_ínuÃe"%V"²_íuu:U¶ßU=nV)©U

Try it (Includes all test cases)

  • 2 4 bytes saved thank to obarakon, who also convinced me to take this up again after I abandoned it earlier. I wish he hadn't!
  • 33 26 25 23(!) 7 bytes sacrificed to check input validity.
\n"..."\nÑ?UsV e"%v"²_ínuÃe"%V"²_íuu:U¶ßU=nV)©U     :Implicit input of integer or string U
\n                                                  :Prevent input value of U from being overridden
  "..."\n                                           :Assign the string "OIREASGTBP" to variable V
         Ñ                                          :Multiply the input by 2
          ?                                         :If truthy (not NaN)
           UsV                                      :  Convert U to a string in custom base V
               e                                    :  Recursively replace all occurrences of
                "%v"                                :    Literal "%v"
                    ²                               :    Duplicate, giving the Japt RegEx class for /[AEIUO][AEIOU]/g
                     _                              :    Pass each match through the following function
                      í                             :      Interleave with
                       n                            :        Literal "n"
                        u                           :        Uppercase
                         Ã                          :  End replace
                          e"%V"²                    :  Recursively replace all occurrences of /[^AEIOU][^AEIOU]/g
                                _                   :  Pass each match through the following function
                                 íuu                :    Interleave with "u" uppercased
                                    :               :Else
                                                  :  Check U for equality with
                                       ß            :    Recursive call with argument
                                        U=          :      Reassign to U
                                          nV        :      Convert U from a base-V string to an integer
                                            )       :    End recursive call
                                             ©U     :  Logical AND with U
added 1 character in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
added 2931 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
added 5 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
deleted 2598 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
Commonmark migration
Source Link
Loading
Rollback to Revision 6
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
deleted 102 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
added 185 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
added 889 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
added 45 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
added 266 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
added 1363 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading