अडिग संख्या


16

एक लहरदार संख्या एक नंबर है, जहां अपने अंकों के बीच वैकल्पिक ऊपर और नीचे निम्नलिखित संख्या की तरह: 461,902 या 708,143, या यहाँ तक 1,010,101, लेकिन नहीं 123, क्योंकि 2 <3।

एक कार्यक्रम या समारोह जो एक truthy मान देता है, तो एक नंबर है लिखें लहरदार , और एक falsy मूल्य अन्यथा। सबसे छोटा कोड जीतता है।

नोट : एकल अंक संख्या एक वैध इनपुट है, लेकिन इसे udulant नहीं माना जाता है , इस प्रकार isUndulantn <10 के लिए गलत है।


स्ट्रिंग, पूर्णांक, फ्लोट के रूप में संख्या इनपुट ...?
19-21 को काउंटरक्ल्विस

1
यहाँ क्या उद्देश्य है? कोड-गोल्फ (सबसे छोटा फ़ंक्शन)?
अलेक्जेंड्रू

1
@ जर्नार्डो: मुझे लगता है कि यह सच या अपरिभाषित व्यवहार होगा, क्योंकि यह पुनरावृत्ति के लिए एक बेहतर आधार मामला होगा।
जॉय एडम्स

4
अचूक संख्या की आपकी परिभाषा मानक परिभाषा के अनुरूप नहीं है: mathworld.wolfram.com/UndulatingNumber.html । क्या यह जानबूझकर है?
मेलमोकब

9
मेरा मामला 16% छोटा हो सकता है अगर आधार मामला सही हो (जैसा कि आईएमएचओ समझेगा)।
शाश्वत

जवाबों:


6

जे, ४५

*./(n>9),(}:(=-)}.)(}:*@-}.)n#:~10$~>.10^.n=.

नमूना उपयोग:

   *./(n>9),(}:(=-)}.)(}:*@-}.)n#:~10$~>.10^.n=. 461902
1
   *./(n>9),(}:(=-)}.)(}:*@-}.)n#:~10$~>.10^.n=. 708143
1
   *./(n>9),(}:(=-)}.)(}:*@-}.)n#:~10$~>.10^.n=. 1010101
1
   *./(n>9),(}:(=-)}.)(}:*@-}.)n#:~10$~>.10^.n=. 123
0
   *./(n>9),(}:(=-)}.)(}:*@-}.)n#:~10$~>.10^.n=. 5
0

मुझे पूरा यकीन है कि एक बार में /अधिक काम करने के लिए सम्मिलित सम्मिलित करने का एक बेहतर तरीका है , लेकिन मैं महीनों तक जे-कम रहा हूं, मुझे इसे वापस लाने की आवश्यकता है।


इस समस्या में J को हरा पाना कठिन होगा। अच्छा समाधान!
लियोनार्डो

@ एलोनार्डो धन्यवाद!
जेबी

6

रूबी, 72२ characters० अक्षर

Q=10;k=->n,v{(n%Q-n/Q%Q)*v<0?k[n/Q,-v]:n<Q};u=->n{n>9&&k[n,-1]|k[n,1]}

उपयोग और टेस्टकेस:

p u[10101]   # <= true
p u[708143]  # <= true
p u[2421]    # <= false
p u[1231]    # <= false
p u[873]     # <= false

एकल अंक गलत :

p u[5]       # <= false

लगातार समान अंक भी झूठे होते हैं :

p u[66]      # <= false
p u[1221]    # <= false

6

जे, 30 बाइट्स

*/0<(#,]*{.*1 _1$~#)2-/\a.i.":

अन्य J उत्तरों की तुलना में एक अलग दृष्टिकोण।

   * / 0 <(#,] * {। * 1 _1 $ ~ #) 2 - / \ ai ": 461902
1
   * / 0 <(#,] * {। * 1 _1 $ ~ #) 2 - / \ ai ": 708143
1
   * / 0 <(#,] * {। * 1 _1 $ ~ #) 2 - / \ ai ": 1010101
1
   * / 0 <(#,] * {। * 1 _1 $ ~ #) 2 - / \ ai ": 123
0
   * / 0 <(#,] * {। * 1 _1 $ ~ #) (} .-}} :) ai ": 5
0

यदि 5 को अयोग्य माना जाता है, तो 3 अक्षर कम होंगे।


ठीक है, कम से कम मैं खुद को इस सोच के साथ सांत्वना दे सकता हूं कि मेरे पास एक घंटे के लिए नेतृत्व था। :-)
गारेथ

5

(pdf) eTeX, 129 वर्ण

\def\a#1#2{\if#2?\ifx\r\s\def\s{1}\else
True\end\fi\fi\edef\t{\pdfstrcmp{#2}{#1}}\ifx\s\t
False\end\fi\let\s\t\a#2}\expandafter\a

के साथ संकलन pdfetex filename.tex 1324?एक पीडीएफ आउटपुट देता है। TeX मुख्य रूप से एक टाइप करने वाली भाषा है, और स्टडआउट के बजाय आउटपुटिंग लगभग 20 अधिक वर्ण लेगा। इसके अलावा एक-अंकों की संख्या (सच के बजाय झूठे) के लिए अजीब आवश्यकता मुझे 26 वर्ण लेती है।


5

हास्केल, 88 77 73 65 वर्ण

z=tail>>=zipWith compare
q[]=0>1
q s=all(/=EQ)$s++z s
u=q.z.show

इसके लिए आमतौर पर इस्तेमाल की जाने वाली भाषा प्राग्मा (या -Xध्वज) की आवश्यकता होती है NoMonomorphismRestriction:। यदि आप यह स्वीकार नहीं करते हैं, तो हमें 4 वर्ण जोड़ने होंगे और zइस प्रकार परिभाषित करना होगा :

z s=zipWith compare s$tail s

मैं इतना उग्र हूं कि आपने मेरे 104 चार समाधानों को हरा दिया। u n=length s>1&&(a[GT,LT]||a[LT,GT])where s=show n;z=q compare s$tail s;w=q(==)z;q=zipWith;a=and.w.cycleयह थोड़े सुरुचिपूर्ण है। zipWithके साथ एक बार compareकी तरह तुमने किया था, उसके बाद zipWithफिर से साथ (==)और cycle[GT,LT]या cycle[LT,GT]दूसरा आर्ग के रूप में।
शाश्वत

आप इनलाइन w को tail>>=zipWith compareकम कर सकते हैं जो कुछ बाइट्स को छोटा कर देगा।
गौरवशाली हैकेलर

इसके अलावा, मैंने इसका एक छोटा संस्करण गॉर्लेट किया q:q[]=0<1;q(a:b:s)|a/=b,a/=EQ=q$b:s;q _=0>1
गर्वित हैकेलर

वास्तव में, यहां एक और भी छोटा संस्करण है: q s=and$all(/=EQ)s:zipWith(/=)s(tail s)
गर्वित हैकेलर

@proudhaskeller - न तो संस्करण सभी परीक्षण पास करता है। वे दोनों 3 पर विफल (गलत होना चाहिए), और पहला कई अन्य लोगों की तरह विफल रहता है, जैसे 32 और 101010101।
माउंटनवार्क

4

ऋषि, 83 76 बाइट्स

f=lambda x:uniq(cmp(*`x`[i-2:i][::(-1)^i])for i in[2..len(`x`)])in[[1],[-1]]

JBernardo से cmp (* [..]) का उपयोग करने का विचार आया। सेज में, के uniq(...)लिए एक उपनाम है list(set(...))

संपादित करें: अभी देखा कि x <10 के लिए uniq(cmp(...)) == [], जो चालू नहीं है [[1],[-1]]। यदि x एक स्ट्रिंग के रूप में इनपुट होता है, तो एक पूर्णांक के बजाय, मुझे एक और 4 वर्ण मिल सकते हैं!


मुझे एक विचार का उपयोग करना था sum(uniq(...))^2, क्योंकि sum([1,-1]) = 0, और एकल के योग [1] और [-1] वर्ग 1 से। दुर्भाग्य से, यह तीन बार दोहराया अंक पर विफल रहता है; 1011101.
बूथ

अच्छा लगा। मुझे ऋषि सीखना चाहिए। BTW, मुझे बस एहसास हुआ कि Lपायथन में संख्या 2 ** 32 से बड़ी होने पर बैकेंड्स अपेंड करेगा और परिणाम को प्रभावित करेगा। क्या ऋषि पर ऐसा होता है?
जेर्नार्डो

हाँ, सेज गोल्फिंग के लिए कुछ चीजों को अच्छा बनाता है ... उदाहरण के लिए, इसका हास्यास्पद स्टार्टअप समय मॉड्यूल के एक विशाल पेड़ के आयात पर खर्च किया जाता है। सेज Lइंटेगर वर्ग परेशान नहीं करता है क्योंकि ऋषि पहले से तैयार अजगर है; 1234 -> इंटेगर ('1234')। आप यहाँ ऋषि का उपयोग करके सही तरीके से कूद सकते हैं: sagenb.org
बूथबेल

4

अजगर: 101 100 characters

न्यूनतम करने से पहले:

undulate = (lambda n: n > 9
            and all(cmp(*digits) == (i % 2) * 2 - 1
                    for i, digits
                    in enumerate(zip(min(`n`,`n`[1:]), 
                                     max(`n`,`n`[1:])))))

न्यूनतम करने के बाद:

a=lambda b:b>9and all(cmp(*c)==d%2*2-1 for d,c in enumerate(zip(min(`b`,`b`[1:]),max(`b`,`b`[1:]))))

3

पायथन, 134 129 चर

def f(x):d=[cmp(*i)for i in zip(`x`,`x`[1:])]if x>9 else[0];n=d[0]>0;return all(i<0 for i in d[n::2])&all(i>0 for i in d[n<1::2])

Ungolfed:

def f(x):
    if x>9:
        d = [cmp(*i)for i in zip(`x`,`x`[1:])] #difference of x[i] and x[i+1]
    else:
        d = [0]       #trick to return False if x<10 using less chars
    n = d[0]>0        #First digit is -1 or 1?
    neg = d[n::2]     #negative numbers if x is Undulant
    pos = d[not n::2] #positive numbers if x is Undulant

    #check if all negs are -1 and all pos are 1 and return value
    return all(i<0 for i in neg) and all(i>0 for i in pos)

3

JavaScript, 88 chars

function _(i){i+='';c=i[0];f=i[a=x=1];for(g=f<c;d=i[x++];c=d)g^=a&=g?d<c:d>c;return!f^a}

In essence, turn the number into a string and compare adjacent characters, flipping the expectation for each.


2
In JavaScript, a function doesn't need a name and the question asks explicitly for a function, so you can save two characters.
Ry-

3

K, 41 bytes

{(x>9)&~max(=). 1_'-':'1_'(<':;>':)@\:$x}

E.g.

{(x>9)&~max(=). 1_'-':'1_'(<':;>':)@\:$x}1212130659
1b

3

CoffeeScript, 98 67 53 bytes

(n)->0!in((n[i]>=c^(n[0]<n[1])+i)%2for c,i in n[1..])

Tests:

[
    '01010101' # true
    '12345'    # false
    '1010101'  # true
    '887685'   # false
    '9120734'  # true
    '090909'   # true
]

Uncompressed:

undulant = (n) ->
    direction = n[0] < n[1]
    return n.split('').every (cur, i) ->
        prev = arr[i-1] or 10 * direction
        +(prev >= cur) is (direction+i)%2

3

J, 44 39 36 31 bytes

*/2(0<#@],0>*/\)*2-/\".;' ',.":

Usage as before.

I hadn't noticed that my last edit made the inequality with 0 check completely unnecessary. :-)

Previous answer (+ explanation):

(0=+/2=/\u)*(1<#u)**/2~:/\2<:/\u=.".;' ',.":

Usage:

    (0=+/2=/\u)*(1<#u)**/2~:/\2<:/\u=.".;' ',.":461902
1

The answer has four parts:

  1. u=.".;' ',.": This reads in the number as a string ":, splits it into a list of characters preceded by spaces ' ',., stitches it back together ;, converts it back to numbers ". and then stores the result u=. This basically turns 461902 into 4 6 1 9 0 2 which I find easier to process in J.

  2. */2~:/\2<:/\ This operates on the value stored in u. It takes each pair of characters and checks if the left one is less than or equal to the right one 2<:/\ so 4 6 1 9 0 2 becomes 1 0 1 0 1. It then takes the result of this and checks each pair of numbers for inequality 2~:/\ so 1 0 1 0 1 becomes 1 1 1 1. Finally it multiplies them all together to get either a 0 or a 1 */ At this point we could return the answer if it weren't for 2 things: a single digit returns 1 when the question requires a 0; and equal numbers are treated the same as 'less than' so 461900 returns 1 instead of 0. Bummer. On we go...

  3. (1<#u) This checks if the number of items stored in u #u is greater than 1 and returns false if it's just a single digit number.

  4. (0=+/2=/\u) This takes each pair of numbers stored in u and checks for equality 2=/\u. It then sums the answers and checks if it has 0.

The results of parts 2, 3 and 4 are then multiplied together to (hopefully) produce a 1 when the number meets the requirements specified in the question.


Nice job re-taking the lead, but I just borrowed a trick from yours!
ephemient

(That being said, I think you could take my a.i.": to shave a few more characters off.)
ephemient

Unfortunately, I'm probably going to have to put that inequality check back in - my answer fails now for 11, 22, 33, 44 etc.
Gareth

3

Haskell, 82 bytes

c=cycle[(<),(>)]
l!n=n>9&&and(zipWith3($)l(show n)$tail$show n)
u n=c!n||((>):c)!n

Try it online!


I count only 83 characters in this solution. (Are you on Windows, perhaps? Write the file with unix line endings, which is legal Haskell.)
MtnViewMark

Thanks, I was using 'wc' to count my characters on Cygwin. I count 82 characters. I used the following code, as wc seems to be outputting an extra character. (Vim doesn't show a trailing newline, but notepad does...) readFile "Undulant.hs" >>= print . length . dropWhile (== '\n') . reverse . filter (/= '\r')
Thomas Eding

c=cycle[(<),(>)] can be shortened to c=(<):(>):c.
Laikoni

1
zipWith3($)l(show n)$tail$show n can be zipWith3($)l=<<tail$show n and ((>):c) can be tail c. All together 70 bytes: Try it online!
Laikoni

3

Python, 119 108 bytes

def u(x):l=[cmp(i,j)for i,j in zip(`x`,`x`[1:])];print x>9and all([i*j<0 for i,j in zip(l,l[1:])])and l!=[0]

2
Nice use of xor. You can cut quite a few characters out with ... for a,b in zip(t,t[1:]) rather than using ranges. Also, you don't need the brackets in all([...]) -- Python makes a generator when it finds (... for ...), even if the parentheses are for a function call.
boothby

Thank you very much for your advice! They have been very valuable! -20 chars
Kirill

Very nice solution. Few more characters x>9 and all(i^j for i,j in zip(l,l[1:])) and remove if l else False.
Ante

1
It is not working in all cases. Two cases are problematic: only 2 digits (e.g. 11), and last 2 digits are same and larger than one before (e.g. 12155). First problem is since there is no testing if x<100. Second is because 'one way comparison'. It can be fix with cmp(i,j) and instead i^j set i*j<0, and testing and l[0]!=0. Few more characters :-/
Ante

1
Hmmm... print saves one character over return, but is it legitimate? The spec does ask for a function that "returns".

2

Python, 155 chars

g=lambda a,b:all(x>y for x,y in zip(a,b))
u=lambda D:g(D[::2],D[1::2])&g(D[2::2],D[1::2])
def U(n):D=map(int,str(n));return(n>9)&(u(D)|u([-d for d in D]))

2

C++, 94 chars

bool u(int N){int K,P,Q,U=1,D=1;while(N>9)P=N%10,Q=(N/=10)%10,K=D,D=U&Q<P,U=K&Q>P;return U^D;}

same method as my Erlang awnser with a for loop rather than recursion.


2

Python 105 101 100 chars

c=lambda r,t:len(r)<2 or(cmp(*r[:2])==t and c(r[1:],-t))
u=lambda x:x>9and c(`x`,cmp(*`x`[:2])or 1)

Recursive solution. c(r,t) checks if first char of r is less (t==-1) or greater (t==1) of second char, and call opposite check on shortened string.


Nice. You can save a character in the first line by removing 0, and you can save three characters on the second line by writing u=lambda x:x>9 and c(`x`,cmp(*`x`[:2])or 1)

Tnx. I didn't like any() from the beginning :-)
Ante

You can save one more by writing x>9and.

2

Perl/re, 139 bytes

Doing everything in regex is kind of a bad idea.

/^(?:(.)(?{local$a=$1}))?(?:(?>((.)(?(?{$a lt$3})(?{local$a=$3})|(?!)))((.)(?(?{$a gt$5})(?{local$a=$5})|(?!))))*(?2)?)(?(?{pos>1})|(?!))$/

I'm using Perl 5.12 but I think this will work on Perl 5.10. Pretty sure 5.8 is out though.

for (qw(461902 708143 1010101 123 5)) {
    print "$_ is " . (/crazy regex goes here/ ? '' : 'not ') . "undulant\n";
}

461902 is undulant
708143 is undulant
1010101 is undulant
123 is not undulant
5 is not undulant

2

GolfScript, 48 bytes

[`..,(<\1>]zip{..$=\-1%.$=-}%(\{.@*0<*}/abs

Hoping to beat J, my first time using GolfScript. Didn't quite succeed.


2

JavaScript, 66 65 62 60 bytes

Takes input as a string, returns true for undulant numbers, an empty string (falsey) for single digit numbers and false otherwise.

([s,...a])=>a+a&&a.every(x=>eval(s+"<>"[++y%2]+x,s=x),y=s<a)

Try it

Run the Snippet below to test 0-9 and 25 random numbers <10,000,000.

f=
([s,...a])=>a+a&&a.every(x=>eval(s+"<>"[++y%2]+x,s=x),y=s<a)
tests=new Set([...Array(10).keys()])
while(tests.add(Math.random()*1e7|0).size<35);
o.innerText=[...tests].map(x=>(x=x+``).padStart(7)+` = `+JSON.stringify(f(x))).join`\n`
<pre id=o></pre>


Explanation

A few fun little tricks in this one so I think it warrants a rare explanation to a JS solution from me.

()=>

We start, simply, with an anonymous function which takes the integer string as an argument when called.

[s,...a]

That argument is immediately destructured into 2 parameters: s being the first character in the string and a being an array containing the remaining characters (e.g. "461902" becomes s="4" and a=["6","1","9","0","2"]).

a+a&&

First, we concatenate a with itself, which casts both occurrences to strings. If the input is a single digit number then a will be empty and, therefore, become and empty string; an empty string plus an empty string is still an empty string and, because that's falsey in JS, we stop processing at the logical AND and output our empty string. In all other cases a+a will be truthy and so we continue on to the next part of the function.

a.every(x=>)

We'll be checking if every element x in a returns true when passed through a function.

y=s<a

This determines what our first comparison will be (< or >) and then we'll alternate from there. We check if the string s is less than the array a, which gets cast to a string in the process so, if s is less than the first character in a, y will be true or false if it's not.

s+"<>"[++y%2]+x

We build a string with the current value of s at the beginning and x at the end. In between, we index into the string "<>" by incrementing y, casting its initial boolean value to an integer, and modulo by 2, giving us 0 or 1.

eval()

Eval that string.

s=x

Finally, we pass a second argument to eval, which it ignores, and use it to set the value of s to the current value of x for the next iteration.


1

PowerShell, 88

Naïve and trivial. I will golf later.

filter u{-join([char[]]"$_"|%{if($n){[Math]::Sign($n-$_)+1}$n=$_})-notmatch'1|22|00|^$'}

My test cases.


1

JavaScript, 112

function(n,d,l,c,f){while(l=n%10,n=n/10|0)d=n%10,c?c>0?d>=l?(f=0):(c=-c):d<=l?(f=0):(c=-c):(c=d-l,f=1);return f}

You only need to pass it one argument. I could probably golf this further with a for loop.


(d>=l -> d>0) and (d<=l -> d<2) perhaps? I'm not looking closely, as perhaps d might contain fractional parts that might skew it.
Thomas Eding

@trinithis: That's a lowercase L, not a 1. Thanks though!
Ry-

Where's DejaVu Sans Mono or Bitstream Vera Sans Mono when you need it? Perhaps I need to customize stackoverflow with some custom css or a user script...
Thomas Eding

@trinithis: I agree, the font choice isn't that great. Bolding doesn't stand out enough...
Ry-

1

Erlang, 137 123 118 chars

u(N)->Q=N div 10,u(Q,N rem 10,Q>0,Q>0). u(0,_,D,U)->D or U;u(N,P,D,U)->Q=N rem 10,u(N div 10,Q,U and(Q<P),D and(Q>P)).

Won't this return True so long as there has been at least one up and one down transition anywhere? Won't it return True for, say 1234321?
MtnViewMark

@ MtnViewMark, yeah it did thanks, I misunderstood the question fixed now hopefully.
Scott Logan

1

CJam, 30 bytes

CJam is newer than this challenge, so this does not compete for the green checkmark, but it's not a winner anyway (although I'm sure this can actually be golfed quite a bit).

l"_1=\+{_@-\}*;]"_8'*t+~{W>},!

Test it here.

How it works

Firstly, I'm doing some string manipulation (followed by eval) to save 5 bytes on duplicate code:

"..."_8'*t+~
"..."        "Push this string.":
     _       "Duplicate.";
      8'*t   "Replace the 8th character (the -) with *.";
          +~ "Concatenate the strings and evaluate.";

So in effect my code is

l_1=\+{_@-\}*;]_1=\+{_@*\}*;]{W>},!

First, here is how I deal with the weird special case of a single digit. I copy the digit at index 1 and prepend it to the number. We need to distinguish 3 cases:

  • The first two digits are different, like 12..., then we get 212..., so the start is undulant, and won't affect whether the entire number is undulant.
  • The first two digits are the same, like 11..., then we get 111.... Now the start is not undulant, but the number wasn't undulant anyway, so this won't affect the result either.
  • If the number only has one digit, the digit at index 1 will be the first digit (because CJam's array indexing loops around the end), so this results in two identical digits, and the number is not undulant.

Now looking at the code in detail:

l_1=\+{_@-\}*;]_1=\+{_@*\}*;]{W>},!
l                                   "Read input.";
 _1=\+                              "Prepend second digit.";
      {_@-\}*                       "This fold gets the differences of consecutive elments.";
             ;]                     "Drop the final element and collect in an aray.";
               _1=\+                "Prepend second element.";
                    {_@*\}*         "This fold gets the products of consecutive elments.";
                           ;]       "Drop the final element and collect in an aray.";
                             {W>},  "Filter out non-negative numbers.";
                                  ! "Logical not.";

I'm sure there is a shorter way to actually check digits (of length greater 1) for whether they are undulant (in particular, without using two folds), but I couldn't find it yet.


1

Prolog 87 bytes

u(X) :- number_codes(X,C),f(C).
f([_,_]).
f([A,B,C|L]) :- (A<B,B>C;A>B,B<C),f([B,C|L]).

To run it, just save it as golf.pl, open a prolog interpreter (e.g. gprolog) in the same directory then do:

consult(golf).
u(101010).

It will give true if the number is undulant, otherwise just no.


1

Mathematica, 46 bytes

#!=Sort@#&&#!=Reverse@Sort@#&[IntegerDigits@n]

Examples (spaces are not required):

# != Sort@# && # != Reverse@Sort@# &[IntegerDigits@5]
# != Sort@# && # != Reverse@Sort@# &[IntegerDigits@123]
# != Sort@# && # != Reverse@Sort@# &[IntegerDigits@132]
# != Sort@# && # != Reverse@Sort@# &[IntegerDigits@321]

(*  out *)
False  False  True  False

1

Scala, 141 133 129 97 bytes

def u(n:Int):Boolean=n>9&&{
val a=n%10
val b=(n/10)%10
a!=b&&n<99||(a-b*b-(n/100)%10)<0&&u(n/10)}

With a = n % 10, b = (n/10) % 10, c = (n/100) % 10

if a > b and b < c or 
   a < b and b > c

Then a-b * b-c is either x*-y or -x*y with x and y as positive numbers, and the product is in both cases negative, but for -x*-y or x*y (a < b < c or a > b > c) the product is always positive.

The rest of the code is handling special cases: one digit, two digits, two identical digits.


1

Perl, 78 bytes

sub u{@_=split//,$_=shift;s/.(?=.)/($&cmp$_[$+[0]])+1/ge;chop;$#_&&!/00|1|22/}

1

Q, 71 bytes

{$[x>9;any all a=#[;(1 -1;-1 1)](#)a:1_signum(-':){"I"$x}each -3!x;0b]}

Sample usage:

q){$[x>9;any all a=#[;(1 -1;-1 1)](#)a:1_signum(-':){"I"$x}each -3!x;0b]} 5
0b
q){$[x>9;any all a=#[;(1 -1;-1 1)](#)a:1_signum(-':){"I"$x}each -3!x;0b]} 10101
1b
q){$[x>9;any all a=#[;(1 -1;-1 1)](#)a:1_signum(-':){"I"$x}each -3!x;0b]} 01010
1b
q){$[x>9;any all a=#[;(1 -1;-1 1)](#)a:1_signum(-':){"I"$x}each -3!x;0b]} 134679
0b
q){$[x>9;any all a=#[;(1 -1;-1 1)](#)a:1_signum(-':){"I"$x}each -3!x;0b]} 123456
0b
q){$[x>9;any all a=#[;(1 -1;-1 1)](#)a:1_signum(-':){"I"$x}each -3!x;0b]} 132436
1b

You can logic away the if {(x>9)&any all a=#[;(1 -1;-1 1)](#)a:1_signum(-':)("I"$')($)x} gives 62
skeevey

Never seen ($) syntax for string before and the logic is a nice touch.
tmartin

1

Julia 0.6, 62 bytes

f(x,a=sign.(diff(digits(x))))=x>9&&-a*a[1]==(-1).^(1:endof(a))

Takes in a number, returns true for Undulant, and false for not. Eg f(163) returns true.

f(x,a=sign.(diff(digits(x))))=x>9&&-a*a[1]==(-1).^(1:endof(a))
f(x,                        )                                   # function definition
    a=sign.(diff(digits(x)))                                    # default 2nd argument is array of differences of signs of digits
                              x>9&&                             # short circuiting and to catch cases under 10
                                   -a*a[1]                      # make the first element of a always -1
                                          ==(-1).^(1:endof(a))  # check that a is an array of alternating -1 and 1 of correct length

Try it online!

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.