set i read set f "" print map index i k v return label k set x _ set _ slice " " length index f e 1 1 set f concat f wrap x return label e set _ slice " " add _ multiply -1 x 1 1 return label v set _ unwrap slice i _ add 1 _ 1 return
- "골프 방지"언어 만들기 : 확인
- 어쨌든 골프 : 확인
STDIN에서 입력하고 STDOUT에서 출력하는 전체 프로그램입니다.
미적 가치를위한 포장 버전 :
set i read set f "" print map index i k v return label k set x _ set _ slice "
" length index f e 1 1 set f concat f wrap x return label e set _ slice " " add
_ multiply -1 x 1 1 return label v set _ unwrap slice i _ add 1 _ 1 return
그리고 심하게 "설명"되고 ungolfed 버전 (Macaroni에는 주석이 없으므로 베어 문자열 리터럴을 사용합니다) :
set input read "read line from STDIN, store in 'input' var"
set found "" "we need this for 'keep' below"
print map index input keep val "find indeces to 'keep', map to values, print"
return
label keep
"we're trying to determine which indeces in the string to keep. the special
'_' variable is the current element in question, and it's also the value
to be 'returned' (if the '_' variable is '0' or empty array after this
label returns, the index of the element is *not* included in the output
array; otherwise, it is"
set x _ set _ slice
" "
length index found exists
1
1
"now we're using 'index' again to determine whether our '_' value exists in
the 'found' array, which is the list of letters already found. then we
have to apply a boolean NOT, because we only want to keep values that do
NOT exist in the 'found' array. we can 'invert' a boolean stored as an
integer number 'b' (hence, 'length') with 'slice(' ', b, 1, 1)'--this is
equivalent to ' '[0:1], i.e. a single-character string which is truthy, if
'b' was falsy; otherwise, it results in an empty string if 'b' was truthy,
which is falsy"
set found concat found wrap x "add the letter to the 'found' array"
return
label exists
set _ slice
" "
add _ multiply -1 x
1
1
"commentary on how this works: since 0 is falsy and every other number is
truthy, we can simply subtract two values to determine whether they are
*un*equal. then we apply a boolean NOT with the method described above"
return
label val
set _ unwrap slice input _ add 1 _ 1 "basically 'input[_]'"
return
(이것은 최초의 실제 Macaroni 프로그램입니다 (실제로 수행하는 작업입니다)! \ o /)