입력으로 다음이 있습니다.
N
그리고 다음을 출력해야합니다.
1 -> 0
2 -> 1
5 -> 1
10 -> 1
12 -> 2
20 -> 2
30 -> 3
54 -> 6
97 -> 10
100 -> 10
코드 골프이므로 바이트 단위로 가장 낮은 점수가 이깁니다!
lambda n:(n+8)/10
Ḋm⁵L
양의 정수, N
을 받아들이는 모나 딕 링크로, 음이 아닌 정수를 생성합니다.
Ḋm⁵L - Link: integer, N e.g. 15
Ḋ - dequeue (implicit range [1..N]) -> [2..N] [2,3,4,5,6,7,8,9,10,11,12,13,14,15]
⁵ - literal ten 10
m - modulo slice [2,12]
L - length 2
+8:⁵
8을 더하고 정수를 10으로 나눕니다 ( RGS의 Python 답변 에서 처음 사용 된 것처럼).
-pl
, @Grimmy는 올바른 출력으로 10 바이트로 줄였습니다.
$_+=1<chop
- 버블 러 덕분에 1 바이트
전체 프로그램
⌊.1×8+⎕
f x = div (x 8) 10
8+T/
또 다른 지루한 공식 : 8을 더하고 10으로 나눕니다. (두 피연산자가 정수이면 W는 정수 나눗셈을 수행합니다.)
d
, 5 바이트 [ⁿNy|
비 압축 :
Tm2=Wk
W % For every number in the range [1 .. N]:
% Keep all that satisfies:
Tm % After modulo by 10,
2= % The result is equal to 2
k% Find the length of that
8+T÷
다른 모든 사람과 동일한 접근 방식.
온라인으로 사용해보기 또는 모든 테스트 사례를 확인 합니다.
(약간) 더 흥미로운 5 바이트 대안 :
LT%2¢
L€θ2¢
L2Å¿O
FNθΘO
설명 :
8+ # Add 8 to the (implicit) input-integer
T÷ # Integer-divide it by 10
# (after which the result is output implicitly)
L # Push a list in the range [1, (implicit) input-integer]
T% # Take modulo-10 on each
# or
€θ # Leave the last digit of each
2¢ # Count the amount of 2s
# (after which the result is output implicitly)
L # Push a list in the range [1, (implicit) input-integer]
2Å¿ # Check for each whether it ends with a 2 (I'm actually surprised it vectorizes..)
O # Sum to get the amount of truthy values
F # Loop `N` in the range [0, (implicit) input-integer):
N # Push `N`
θ # Pop and leave only its last digit
Θ # 05AB1E trutify: check if it's exactly 1
O # Sum all values on the stack together
# (after the loop, the result is output implicitly)
.+
$*
.{2,10}
온라인으로 사용해보세요! 수정 : @Grimmy 덕분에 2 바이트가 절약되었습니다. 설명:
.+
$*
단항으로 변환하십시오.
.{2,10}
10의 배수의 수를 세고, 각각은 10에서 2로 끝나는 정수를 포함하고, 10에서 2로 끝나는 마지막 정수 하나에 충분하므로 최종 2-9에 대한 추가 일치를 계산합니다.
R%⁵ċ2
온라인으로 사용해보세요! Nick에게 감사드립니다. 케네디는 저에게 1 바이트를 저장했습니다.
작동 원리 :
R Range from 1 to n,
%⁵ modulo 10.
ċ2 Then count how many of those are 2.
1.."$args"-match"2$"
$ args는 숫자로 전달할 인수입니다.
정수 n에 대한 프롬프트 :
/ 2 = 10 | ⍳⎕
8+I/
이것은 dc "함수"입니다. 스택에서 입력을 가져온 다음 출력을 스택으로 푸시합니다. (dc는 스택 기반 언어입니다.)
호출하려면 먼저 원하는 입력을 입력하고 (스택에 푸시하려면) 위의 코드를 따른 다음 p
를 입력하여 출력을 print합니다.
dc<<<$1d8+I/p
입력이 인수로 전달되고 출력이 print됩니다.
(이것은 내부적으로 내 dc 답변을 사용합니다.)
f(n){n=(n+8)/10;}
f(n){n+=8;n/=10;}
대체 17 바이트 :
f(n){n=n/10.+.8;}
대체 17 바이트
f(n){n=(n+8)/10;}
온라인으로 시도해보십시오. / a>
(defn e[n](int(/(+ n 8)10)))
미 골프 :
(defn ends-in-two [n]
(int (/ (+ n 8) 10)))
테스트 하네스 :
(println (e 1))
(println (e 2))
(println (e 5))
(println (e 10))
(println (e 12))
(println (e 20))
(println (e 30))
(println (e 54))
(println (e 97))
(println (e 100))
x->(x+8)÷10
GolfScript는 소수점을 지원하지 않으므로 /
가 작동합니다.
~8+10/
{(1..it).count{it%10==2}}
(scan()+8)%/%10
8+A/
표준 더하기 8, 정수 나누기 10
8|+10|/
RGS의 방법 사용
8|+ # Add 8 (Parse string implcit)
10|/ # Divide by 10
riq[~GO2CN
ri # Read int
q[~ # Boxed tail (last digit)
GO # Generate from 1, N
2CN # Count number of 2's
$'main'
-0(!a!)-/-(a)ia(!a!)\
#od[01]a*8(a)-\ /e-----@
@-(!a!)/ >-
\m(a)[01]--/
0(!a!) Put 0 into variable "a"
(a)ia(!a!) Add "a" with input (one number at a time), put into variable "a"
e check if it's EOF, then go left or right at the next junction
if false:
[10](a)m(!a!) multiply "a" by 10, put into variable "a"
if true:
(a)8a[10]do# add a with 8, then divide by 10, print the output. Fin.
The rest of symbols are tracks
f(N)->(N+8)div 10.
f(N)-> % Function taking N as input
(N+8) % Add input by 8
div 10. % Floor division by 10
마침내 올바른 언어를 찾았습니다. Vim에서 이제 삭제 된 답변이 있었지만 1 입력에 대해 빈 문자열을 반환했습니다.
8+₀
설명:
8 In fact, I have no idea whether is this language stack-based, I guess it pushes 8
+ add that 8 to the seemingly-implicit input
₀ divide by 10. There are also instructions to divide by numbers from 2 to 11 :)
/+8QT
/+8QT
Q : Variable containing evaluated input
+8 : Add 8 to it
/ T : Divide result of add by 10
f=n=>n?(n%10==2)+f(n-1):0
! 를
f=n=>(n+8)/10|0
<?=$argn/10+.8|0;
@oxgeba 덕분에 -1 바이트
lambda n:(n+8)//10
정수 나누기를 사용하도록 제안한 @JoKing에게 감사드립니다.