PowerShell을 261 190 121 95 바이트
$(do{Measure-Command{$l=read-host};$l}while($l))|%{($_,(sleep -m($_.Ticks/1e4)))[($b=!$b+!$_)]}
골프 지원 및 영감을 위해 TessellatngHeckler 및 tomkandy 에 소품
이것은 아래의 121 바이트 버전과 개념 상 매우 유사합니다 $a
. 명시적인 배열에 객체를 저장하기 위해 while 루프를 거치지 않고 객체 목록을 동적으로 생성하고 작성하는 것 입니다. 두 경우 모두 해당 객체 목록이 동일한 foreach 루프로 파이프 라인됩니다 |%{...}
. 결과 배열 선택기에 대한 색인 작성 ($b=!$b+!$_)
은 이번에 if($_){$_}
아래 반복 을 제거하도록 작성되어 몇 바이트를 더 절약합니다.
이전, 121 바이트
$l,$a=1,@();while($l){$t=Measure-Command{$l=read-host};$a+=$t,$l}$a|%{($(if($_){$_}),(sleep -m($_.Ticks/1e4)))[($b=!$b)]}
확장 및 설명 :
$l,$a=1,@() # Set variable $l and create array $a
while($l){ # So long as we don't have a blank line
$t=Measure-Command{$l=read-host} # Read the input and measure time to input
$a+=$t,$l # Add those values into the array
}
$a|%{ # For each item in $a, do
($(if($_){$_}),(sleep -m($_.Ticks/1e4)))[($b=!$b)]
# Magic happens here ... first, we set $b to the NOT of it's uninitialized
# value, so $b is initially set to truthy
# This value in [...] selects which of the two elements ( , ) get selected
# Truthy to start means the second command, sleep, gets chosen first, and
# then it alternates every next item, so it sleeps, then prints, then
# sleeps, then prints, etc., until we run out of $a
}
이전, 190 바이트
function f {param($m)sleep -m $a[$m].totalmilliseconds}$a=1,1;while($a[-1]-ne""){$a+=Measure-Command{$b=read-host};$a+=$b}if(!($a[3])){f 2;exit}$i=2;while($i-lt$a.length){f($i++);$a[($i++)]}
function f { # Define a new function
param($m) # with $m as input
sleep -m $a[$m].totalmilliseconds # sleep for $a[$m] milliseconds
}
$a=1,1 # Create new array with two elements
while($a[-1]-ne""){ # While the last element isn't empty
$a+=Measure-Command{$b=read-host} # Read into $b and measure how long that took,
# and add the time into $a
$a+=$b # Then add the input into $a
}
if(!($a[3])){ # If the third element is empty, the user entered
# a blank as the only input, so...
f 2 # sleep for $a[2] ms (how long it took them to hit enter)...
exit # and exit the script
} # Else ...
$i=2 # Set a counter variable
while($i-lt$a.length){ # While we haven't reached the end of $a
f($i++) # Sleep
$a[($i++)] # Write the output
}
이전, 261 바이트
$a=$d=@();$d+=,@(date);$x=Read-Host
while($x){$a+=,@($x);$d+=,@(date);$x=Read-Host}
if($x){0..($a.Length-1)|%{sleep -m((($d[$_+1]).ticks-($d[$_]).ticks)/1e4);$a[$_]};sleep -m((($d[-1]).ticks-($d[-2]).ticks)/1e4)}
else{sleep -m(((date).Ticks-($d[0]).Ticks)/1e4)}
배트맨! 그것을 분해하자 :
$a=$d=@() # Create two empty arrays
$d+=,@(date) # Add the current time into $d
$x=Read-Host # Read the first line
while($x){ # So long as it's not empty
$a+=,@($x) # Add it into our output array
$d+=,@(date) # Add the current time into $d
$x=Read-Host # Get the next line
}
if($a){ # So long as $a exists (i.e., the first input wasn't blank)
0..($a.Length-1)|%{ # For-loop over the length
# Sleep for how long it took to do input
sleep -m((($d[$_+1]).ticks-($d[$_]).ticks)/1e4)
$a[$_] # Print out the input
}
# Sleep the length it took for the final blank
sleep -m((($d[-1]).ticks-($d[-2]).ticks)/1e4)
}
else{
# If we're here, the initial input was blank, so just sleep
sleep -m(((date).Ticks-($d[0]).Ticks)/1e4)
}