C (gcc), 104 바이트
f(b,o,u,n,c,y){for(o=u=0;b;u+=y?0:o+0*--b,++o)for(n=o,y=3;n/10;)c=n%10,n/=10,y&=(c-=n%10)<0?:c?2:y;b=u;}
여기에서 온라인으로 사용해보십시오 .
언 골프 드 :
f(n, // function: return type and type of arguments defaults to int;
// abusing extra arguments to declare variables
i, // number currently being checked for bounciness
s, // sum of the bouncy numbers
j, // copy of i to be used for checking bounciness in a loop
p, // used for investigating the last digit of j
b) { // whether i is not bouncy; uses the two least significant bits to indicate increasing/decreasing
for(i = s = 0; // check numbers from zero up; initial sum is zero
n; // continue until we have n bouncy numbers
s += b ? 0 // not bouncy, no change to the sum
: i + 0* --n, // bouncy, add it to the sum and one less bouncy number to go
++i) // either way, move to the next number
for(j = i, b = 3; j/10; ) // make a copy of the current number, and truncate it from the right until there is just one digit left
// bounciness starts as 0b11, meaning both increasing and decreasing; a value of 0 means bouncy
p = j % 10, // get the last digit
j /= 10, // truncate one digit from the right
b &= // adjust bounciness:
(p -= j % 10) // compare current digit to the next
< 0 ? // not an increasing number, clear second to least significant bit
: p ? 2 // not a decreasing number, clear least significant bit
: b; // keep it the same
n = s; // gcc shortcut for return s
}
sort숫자와 그들이 원래의 수와 동일 있다면 확인? 그것은 내장 (sort)을 사용하고 있지만 그것이 증가하고 있는지 확인하기 위해 내장 된 것은 아닙니다. 확인 되지 않은 관찰 프로그램 요구 사항 및 Y없이 할 X를 우리의 "상황을 방지하기 위해"메타 게시물에.