เสียงก้องเวลา


38

พื้นหลัง

echoโปรแกรมเป็นระเบียบเพื่อให้ คุณสามารถพูดอะไรกับมันได้และมันจะซ้ำคำพูดของคุณอย่างสมบูรณ์แบบทุกครั้ง! ช่างยอดเยี่ยมจริงๆ! ที่น่าผิดหวังก็จะป้อนข้อมูลซ้ำทั้งหมดในครั้งเดียวโดยไม่คำนึงถึงความเร็วการพิมพ์ของคุณซึ่งไม่สมจริงมาก เราจะต้องแก้ไขเรื่องนั้น

งาน

โปรแกรมของคุณจะรับข้อมูลจาก STDIN หรือเทียบเท่าที่ใกล้เคียงที่สุด มันจะอ่านบรรทัดจากผู้ใช้ทีละคนอาจแสดงพรอมต์บางอย่างจนกว่าพวกเขาจะป้อนบรรทัดว่าง หลังจากนั้นมันจะพิมพ์บรรทัดไปยัง STDOUT หรือใกล้เคียงที่สุดในลำดับเดียวกันกับที่พวกเขาได้รับ บรรทัดสุดท้าย (ว่าง) ไม่ถูกพิมพ์และบรรทัดที่พิมพ์ล่าสุดไม่จำเป็นต้องขึ้นบรรทัดใหม่

นอกจากนี้โปรแกรมจะรักษาช่วงเวลาระหว่างแต่ละบรรทัด: ถ้าใช้xเวลาวินาทีของผู้ใช้เพื่อเข้าสู่บรรทัดมันจะใช้เวลาไม่xกี่วินาทีในการพิมพ์โปรแกรม สิ่งนี้ใช้ได้กับบรรทัดแรกและบรรทัดสุดท้ายเช่นกัน บรรทัดว่างจะไม่ถูกพิมพ์ แต่โปรแกรมจะรออยู่ก่อนที่จะยกเลิก

ตัวอย่าง

นี่คือตัวอย่างเซสชันกับโปรแกรม การกระทำทั้งหมดที่ไม่ได้ผลิตข้อความอธิบายไว้ในวงเล็บและ (ถ้ามี) >พร้อมท์จะแสดงเป็น

[begin program]
> fhtagn[enter; 1.48s passed since starting program]
> yum yum[enter; 3.33s passed since previous enter]
> so cool![enter; 2.24s passed since previous enter]
> [enter; 0.23s passed since previous enter]
[wait 1.48s]fhtagn
[wait 3.33s]yum yum
[wait 2.24s]so cool!
[wait 0.23s, then end program]

หากไม่มีการดำเนินการเซสชันจะมีลักษณะดังนี้:

> fhtagn
> yum yum
> so cool!
> 
fhtagn
yum yum
so cool!

กฎและเกณฑ์การให้คะแนน

เวลาที่รอควรแม่นยำภายใน 0.01 วินาที (ในทางปฏิบัติหากคนทั่วไปไม่สามารถบอกความแตกต่างได้คุณก็โอเค) จำนวนไบต์ต่ำสุดที่ชนะและช่องโหว่มาตรฐานไม่ได้รับอนุญาต หากภาษาของคุณมีฟังก์ชันในตัวสำหรับงานนี้อย่างแม่นยำคุณไม่สามารถใช้งานได้


9
ก้าวต่อไป: เล่นกอล์ฟโปรแกรมที่เล่นเกมจังหวะพื้นฐาน: P
Sp3000

เราสามารถมองข้ามเวลาที่โปรแกรมใช้ในการแสดงอักขระได้หรือไม่? ฉันหมายถึงถ้าฉันสามารถวัดได้ว่าภาษาของฉันใช้เวลา 0.1 วินาทีในการส่งออกถ่านฉันควรนำมาพิจารณาด้วยหรือไม่ การเปิดเผยอย่างเต็มรูปแบบฉันวางแผนที่จะใช้> <> เวลาติ๊กของล่ามเพื่อดำเนินการล่าช้า ในกรณีนี้ฉันสามารถวนรอบเวลาป้อนข้อมูลจากนั้นไม่สนใจเวลาที่ผ่านไปโดยวนรอบการแสดงผลของฉันได้หรือไม่
แอรอน

1
@AaronGOUZIT ฉันจะอนุญาตให้ตราบใดที่คุณมีความสอดคล้อง: ช่วงเวลาระหว่างช่วงเวลาที่โปรแกรมของคุณเริ่มพิมพ์บรรทัดถูกนำมาจากผู้ใช้หรือเวลารอระหว่างการพิมพ์จนเสร็จและเริ่มพิมพ์ ถัดไปทั้งหมดนำมาจากผู้ใช้
Zgarb

1
@TessellatingHeckler หลัง; ดูเซสชันตัวอย่าง
Zgarb

1
@KritixiLithos ฉันใช้มือขวาyum yumเท่านั้นซึ่งค่อนข้างยุ่งยาก
Zgarb

คำตอบ:


15

CJam, 45 41 39 36 34 ไบต์

{eslN1$}g;es](es-fm3/{){_es>}g;o}/

แน่นอนว่ามันไม่สมเหตุสมผลในล่ามออนไลน์ แต่มันใช้งานได้กับล่าม Java

มันไม่แสดงพรอมต์

คำอธิบาย

{        e# Do while... (popping the condition from the stack)
  es     e#   Get the current timestamp.
  l      e#   Wait for a line to be entered and read it.
  N      e#   Push a linefeed.
  1$     e#   Copy the line we read - this terminates if the line is empty, because
         e#   empty strings/arrays are falsy.
}g
;        e# Discard the last linefeed (the one after the empty input).
es       e# Push the current timestamp (corresponding to the last, empty, input).
]        e# Wrap everything in an array. This is now a flat array containing:
         e#   - The initial timestamp.
         e#   - Three elements for each line: the line, a linefeed, the timestamp.
         e#   - Two elements for the last line: the empty string and the timestamp.
(        e# Pull off the initial time.
es-      e# Subtract the current time, which gives (minus) the difference between
         e# when a line was entered and when it should be printed back.
fm       e# This maps "minus that value" onto each element in the array. Now the lines
         e# and linefeeds are strings (arrays) - so minus is set difference, but they
         e# only contain characters, not any integers (like the difference value), so
         e# none of the strings will be affected.
         e# The timestamps on the other hand will be incremented by the time difference
         e# between reading and printing, giving the time at which each line should be
         e# printed back.
3/       e# Split the array into chunks of 3 (where the remaining two elements are
         e# just grouped as a pair).
{        e# For each of those chunks...
  )      e#   Pull off the timestamp.
  {      e#   Do while... (popping the condition from the stack)
    _    e#     Duplicate the target time.
    es>  e#     Check if it's still greater than the current time.
  }g
  ;o     e# Discard the target time and print the rest of the current chunk, which will
         e# automatically be flattened/concatenated into a single string.
}/

9

จาวาสคริปต์, 119 112 ไบต์

k=(d=Date.now)(i=j=[]);do{i[++j]=[prompt(),d()-k]}while(i[j][0]);i.map(a=>setTimeout(b=>console.log(a[0]),a[1]))

หวังว่าจะได้พบกับอีกสองสามไบต์เพื่อตัดออก


1
คุณสามารถบันทึกสองสามไบต์ด้วยj=i=[]( ++จะยังคงใช้งานได้!), คุณwhileไม่จำเป็นต้องใช้!=''เพราะมันเป็นเท็จ! ผิดหวังมากฉันพลาดmap! +1
Dom Hastings

1
!=''ทราบดีใน มีความกังวลหากอินพุตนั้น0แต่ดูเหมือนว่าจะจัดการได้ดี ฉันสังเกตเห็น[]ความเป็นไปได้ที่เพิ่มขึ้นก่อนหน้านี้ แต่ฉันโง่และพยายามทำสิ่งj++นั้น ทำ++jผลงานตั้งแต่[]++เห็นได้ชัดคือ 0 XD ขอบคุณ!
Mwr247

1
ทำเครื่องหมายวันนี้ที่ฉันได้เรียนรู้ว่ามีdo...whileวงวนใน JS
Conor O'Brien

6

JavaScript ขนาด 120 ไบต์

ไม่มีโอกาสได้เข้าใกล้ CJam ด้วยวิธีนี้ แต่เป็นสคริปต์ที่ตรงไปตรงมา

a=[];t=+new Date;while(s=prompt()){a.push({s:s,t:+new Date})}while(v=a.pop()){setTimeout(`console.log('${v.s}')`,v.t-t)}

1
ดูเหมือนว่าเราทั้งสองไปหา JS ในเวลาเดียวกันฮ่าฮ่าถึงแม้ว่าคุณจะได้รับของคุณก่อนที่ฉัน ยังคงวิธีการที่แตกต่างกัน
Mwr247

@ Mwr247 แน่นอนว่าคุณมีความสง่างามกว่านี้!
Dom Hastings

6

Pyth, 68 ไบต์

M&p+Gb$__import__('time').sleep(H)$J].dZWeaYwaJ.dZ)aJ.dZp&gVPY-VtJJk

เสียจำนวนมากในการเรียกไปsleepเนื่องจาก Pyth ไม่มีsleepฟังก์ชั่น


3
บางทีคุณควรแนะนำว่าเป็นส่วนเสริมของ Pyth
mbomb007

ฉันเชื่อว่าคุณมีข้อผิดพลาดในการรอคอย ลองเริ่มโปรแกรมรอรอบแล้วพิมพ์บางอย่างแล้วกด Enter สองครั้งอย่างรวดเร็ว มันจะพิมพ์บรรทัดแรกทันทีจากนั้นรอสักครู่ก่อนที่จะยุติ
FryAmTheEggman

6

ทับทิม, 74

t,*a=Time.now
a<<[$_,t-t=Time.now]while$/<gets
a.map{|l,i|sleep -i;puts l}

Tricks: *aบนบรรทัดแรกจะสร้างอาร์เรย์ว่าง ฉันสามารถใช้$*แทนได้ แต่มันเป็นภาพร่างที่นุ่มนวลเนื่องจากมีการร้องขอบางอย่างและช่วยให้ฉันไบต์เท่านั้น $/เป็นบรรทัดใหม่และเป็นบรรทัดสุดท้ายดึงข้อมูลโดย$_gets

แก้ไข: การนอนหลับตอนท้ายนั้นมีค่าใช้จ่ายเพิ่มขึ้นอีก 20 ไบต์ซึ่งอาจเป็นหนทางหนึ่งที่จะทำให้มันสงบลงได้

t,*a=Time.now
a<<[$_,t-t=Time.now]while$/<gets
t-=Time.now
a.map{|l,i|sleep -i;puts l}
sleep -t

ฉันคิดว่าคุณต้องนอนในบรรทัดสุดท้ายขึ้นอยู่กับระยะเวลาที่ผู้ใช้ต้องเตรียมบรรทัดว่าง
Konrad Borowski

สำหรับการนอนหลับตอนท้าย (โซลูชันที่ 2) คุณโทรได้Time.nowเวลาเพียงพอที่จะdef n;Time.now;endประหยัดทั้ง 2 ไบต์
Value Ink

6

Python 3, 124

ใช้ได้กับแพลตฟอร์ม Windows เท่านั้น

from time import*
s=[(1,clock())]
while s[-1][0]:s+=[(input(),clock()-s[-1][1])]
[sleep(y)or x and print(x)for x,y in s[1:]]

การเก็บรักษาการป้อนข้อมูลและเวลาในรายการแยกต่างหากค่าใช้จ่ายฉัน3 ไบต์ อาจไม่ใช่วิธีที่ดีที่สุด

เวอร์ชั่นที่เป็นมิตรกับ 129 ไบต์ Unix โดยให้เครดิตกับMego :

from time import*
t=time
s=[(1,t())]
while s[-1][0]:s+=[(input(),t(),t()-s[-1][1])]
[sleep(y)or x and print(x)for x,z,y in s[1:]]

คุณไม่สามารถใช้time()แทนที่จะclock()บันทึก 2 ไบต์ได้หรือไม่
kirbyfan64sos

4

SWI-Prolog ขนาด 185 ไบต์

a:-b([],S),reverse(S,T),c(T),!.
b(R,S):-get_time(X),read_string(user_input,"\n","",_,A),get_time(Y),Z is Y-X,(A="",S=[A:Z|R];b([A:Z|R],S)).
c([A:Z|T]):-sleep(Z),T=[];(write(A),nl,c(T)).

อาจจะมีสนามกอล์ฟเยอะ แต่ตอนนี้จะทำ ...


4

PowerShell, 261 190 121 95 ไบต์

$(do{Measure-Command{$l=read-host};$l}while($l))|%{($_,(sleep -m($_.Ticks/1e4)))[($b=!$b+!$_)]}

อุปกรณ์ประกอบฉากเพื่อTessellatngHecklerและTomkandyสำหรับความช่วยเหลือและแรงบันดาลใจในการเล่นกอล์ฟ

นี่คือความคล้ายกันในแนวคิดรุ่น 121 $aไบต์ด้านล่างเราเพียงแค่การสร้างแบบไดนามิกและการสร้างรายชื่อของวัตถุแทนการที่จะผ่านในขณะที่วงในการจัดเก็บไว้ในอาร์เรย์อย่างชัดเจน |%{...}ในทั้งสองกรณีรายการของวัตถุที่ได้รับไปป์ไลน์เข้าไปในห่วง 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)
}

144$a=1,1;while($a[-1]-ne""){$a+=Measure-Command{$b=read-host};$a+=$b};$i=2;while($i-lt$a.length){sleep -m $a[($i++)].totalmilliseconds;$a[($i++)]}
tomkandy

@tomkandy ขอบคุณ! อัปเดตด้วยการปรับปรุง
AdmBorkBork

@TessellatingHeckler ยอดเยี่ยม! ฉันกำลังดิ้นรนกับวิธีการควบคุมการสลับอย่างมีประสิทธิภาพและการจัดทำดัชนีในอาร์เรย์เช่นนั้นเป็นตัวเลือกที่ชัดเจนในขณะนี้ที่ฉันเห็น บังเอิญผมแข็งแรงเล่นกอล์ฟไบต์อื่นโดยการเอา@จากแถวที่เป็นมันไม่จำเป็นต้องใช้ในบริบทนี้จึงลงไปที่121
AdmBorkBork

@ TimmyD สิ่งที่ฉันพยายามเมื่อวานนี้คือการใส่คู่ ($ t, $ l) ลงใน a $ a เพื่อสร้างอาร์เรย์ที่ซ้อนกัน ฉันไม่สามารถทำงานได้ แต่วันนี้ฉันสามารถทำได้และมันช่วยได้เล็กน้อยเพราะไม่จำเป็นต้องสลับอ่านทุกคู่และใช้มัน จากนั้นฉันก็รู้ว่า - เรามีระบบที่ดีอย่างสมบูรณ์แบบที่สามารถจัดคิวสิ่งต่างๆ $($l=1;while($l){Measure-Command{$l=read-host};$l})|%{($_,(sleep -m($_.Ticks/1e4)))[($b=!$b+!$_)]}- และด้วยการเปลี่ยน toggle ดังนั้นเมื่อสตริงว่างเปล่ามันจะไม่สลับและ sleep แทน - 98
TessellatingHeckler

(ทำให้เป็นdo{...}while($l)วงแล้วปล่อย$l=1;เพื่อให้ได้95 )
TessellatingHeckler

3

Perl 6, 70 ตัวอักษร

repeat {$/=now;.push($!=get,now -$/)}while $!;.map:{sleep $^b;say $^a}

ล่าม Perl 6 กำหนดตัวแปรสัญลักษณ์สามตัวเท่านั้น (ซึ่งแตกต่างจากความบ้าคลั่งของ Perl 5) เป็นที่แน่นอน$/, และ$! โปรแกรมนี้ใช้พวกเขาทั้งหมดเพื่อหลีกเลี่ยงค่าใช้จ่ายของตัวแปรที่ประกาศใช้$_my

getอ่านบรรทัดจาก STDIN ไม่มีบรรทัดใหม่ซึ่งแตกต่างจาก Perl 5

nowbuiltin ส่งคืนเวลาปัจจุบัน เมื่อลบมันจะให้ช่วงเวลาที่สามารถส่งผ่านไปยังสตริง

วิธีการที่มีอะไรทางด้านซ้ายของมัน (ชอบ.pushและ.mapในรหัสนี้) $_ทำงานบน

การใช้repeat whileloop (รู้จักกันdo whileในภาษาการเขียนโปรแกรมอื่น ๆ ), Perl 6 กำลังเขียนการประทับเวลาปัจจุบันไปที่$/และผลักดันบรรทัดที่ได้รับ (ซึ่งมันยังเก็บไป$!) และความแตกต่างระหว่างเวลาปัจจุบันและการประทับเวลา$/มา เนื่องจากการสั่งซื้อพารามิเตอร์nowจะไม่ถูกคำนวณจนกว่าจะได้รับสาย

whileเงื่อนไขการตรวจสอบหากสายไม่ว่าง (ใน Perl 6 "0"เป็นมูลค่าที่แท้จริงแตกต่างจาก Perl 5)

หลังจากที่ฉันได้รับการประทับเวลาและเส้นทั้งหมดฉันเพียงแค่ให้พวกเขาmapโทรกลับซึ่งนอนน้อยและพูดสิ่งที่พูด


2

Groovy ขนาด 202 ไบต์

def b={System.currentTimeMillis()};def h=[];for(;;){def t=b();def s=System.console().readLine();h.add(s+" "+(b()-t));if(s=="")break};for(def s:h){Thread.sleep((s=s.split(" "))[1].toLong());println s[0]}

รุนแรง

เวอร์ชันที่ไม่ถูกปรับแต่ง:

def b = {System.currentTimeMillis()}; // Creates a closure (short function) b that returns the current time since the epoch in milliseconds.
def h = []; // Makes an empty list
for(;;) { // Infinite loop
  def t = b(); // Get the time
  def s = System.console().readLine(); // Read a line
  h.add(s + " " + b()-t); // Add the string plus the amount of time elapsed to the list
  if(s=="") // If the string is blank
    break; // Exit loop
}
for(def s : h) { // Iterate through array
  Thread.sleep((s=s.split(" "))[1].toLong()); // Splits s into an array and puts the value in s, then takes the second element (the time), converts into a long and sleeps for that time.
  println s[0] // Print the first element (text)
}

2

JavaScript (ES6) 102

รวบรวมความพยายามของ Mwr247 และ Dom Hastings (CW)

/* for TEST */ console.log=x=>O.innerHTML+=x+'\n'

for(k=new Date,i=[];p=prompt();i.push([p,new Date]));i.map(a=>setTimeout(b=>console.log(a[0]),a[1]-k))
<pre id=O></pre>


2

MATLAB, 107 99

tic;a={};i=1;while nnz(i);i=input('','s');a=[a;{i,toc}];tic;end;for b=a';pause(b{2});disp(b{1});end

และไม่ดี

tic; %Start timer
a={};
i=1; %Make us enter the while loop
while nnz(i); %While i has some non-zero elements (this is used to detect a zero length input where we end)
    i=input('','s'); %Get an input string
    a=[a;{i,toc}]; %Append the string and current time as a new cell in a
    tic; %Restart timer
end
for b=a' %For each input
    pause(b{2}); %Wait for the required time
    disp(b{1}); %Then print the string
end

สิ่งนี้จะไม่ถูกต้อง 100% ในเวลาเนื่องจากมันไม่ได้คำนึงถึงเวลาที่ใช้ในการแสดงแต่ละสตริง แต่มันควรจะค่อนข้างเร็วดังนั้นเวลาที่ฉลาดควรใกล้เคียงกัน


หลังจากกลับมาอีกครั้งอย่างรวดเร็วฉันได้บันทึกสองสามไบต์โดยการลบอาเรย์เซลล์สองชั้น ปรากฎทั้งหมดที่ฉันต้องการคือการ;ได้รับมันเพื่อแยกอย่างถูกต้องเมื่อบรรจุ


1
บางทีคุณอาจสร้างเวอร์ชันที่เล่นกอล์ฟใน MATL
ckjbgames

1

Java ใช้เวอร์ชัน 1.04 ของไลบรารีนี้ 385 ไบต์

import sj224.lib.util.*;import java.util.*;class E{static long t(){return System.currentTimeMillis();}public static void main(String[]a) throws Exception{List<Pair<?,Long>>l=new ArrayList();Scanner i=new Scanner(System.in);while(true){long t=t();String s=i.nextLine();if(s.isEmpty())break;l.add(new Pair(s,t()-t));}for(Pair<?,Long>p:l){Thread.sleep(p.two);System.out.println(p.one);}}}

1

Caché ObjectScript ขนาด 123 ไบต์

w() q $P($ZTS,",",2)
r f  s i=i+1,t=$$w() r x,! q:x=""  s g(i,x)=$$w()-t
    f i=1:1 s s=$O(g(i,"")) q:s=""  w s,! h g(i,s)
    q

d rตามปกตินี้ถือว่าตารางสัญลักษณ์สะอาดก่อนที่จะใช้

ปัญหานี้ไม่สามารถแก้ไขได้ใน ANSI MUMPS เนื่องจากมาตรฐาน ANSI ต้องการการแก้ปัญหาระดับที่สองสำหรับเวลาที่แท้จริง$H[OROLOG]เท่านั้น โชคดีที่ Intersystems Cachéซึ่งปัจจุบันเป็นแพลตฟอร์มชั้นนำของอุตสาหกรรมสำหรับ MUMPS ให้การใช้งาน$ZT[IME]S[TAMP]ภายในที่กำหนดไว้ซึ่งให้ความละเอียดระดับไมโครวินาที

(คะแนนเดิมคือ 105 ไบต์ แต่มีข้อผิดพลาด)


1

C ++ 11, 343 338 ไบต์

ต้องการดูจำนวนไบต์ของโค้ดใน c ++ ที่ต้องการ มากกว่าที่ฉันคาดไว้มาก บางทีฉันอาจจะซับซ้อนเกินโซลูชัน

#include<iostream>
#include<vector>
#include<chrono>
int i;using namespace std;int main(){auto n=chrono::system_clock::now;auto t=n();string s{1};vector<string>r;vector<decltype(t-t)>w;while(s.size())getline(cin,s),r.push_back(s),w.push_back(n()-t),t=n();while(i<r.size()){while((n()-t)<w[i]);t=n();cout<<r[i++]<<(i<r.size()-1?"\n":0);}}  

ให้ดูว่าฉันสามารถลดสิ่งนี้ได้ไหม


คุณสามารถลบช่องว่างใน#includes mainและการประกาศชนิดสำหรับ นั่นคือ 7 ไบต์ - ไม่มากนัก แต่เป็นการเริ่มต้น นอกจากนี้คุณยังอาจจะสามารถที่จะใช้autoมากกว่าสำหรับstring s
Alex A.

ขอบคุณสำหรับความคิดเห็น. ฉันจะให้ผลตอบแทนประเภทหลัก ถ้าฉันจำได้อย่างถูกต้องเฉพาะcที่เราไม่ต้องระบุ ฉันพยายามครั้งแรกที่จะใช้auto s... แต่ดูเหมือนว่ามันจะถูกแปลงเป็นและไม่ได้const char * std::stringฉันสงสัยว่าฉันสามารถสร้างชื่อแทนwhileได้หรือไม่
wendelbsilva

การลบประเภทส่งคืนสามารถใช้ได้กับ C ++ แม้ว่าจะเป็น "ไม่ควร" ตามมาตรฐาน คุณสามารถลองสร้างชื่อแทนเพื่อwhileใช้งาน#defineได้
Alex A.

1

Bash, 91 90 ไบต์

while r=`\time -fsleep\ %e head -1`
[[ $r ]]
do printf{,\ %%b\ %q\;} "$r
"
done>t 2>&1
. t

tซึ่งสร้างแฟ้มชั่วคราว มันจะเขียนทับไฟล์ที่มีอยู่ด้วยชื่อเดียวกัน

แนวคิดนี้ค่อนข้างสั้น แต่การจัดการกับอักขระพิเศษในอินพุตเพิ่มประมาณ 15 ไบต์ ...


1

VBA, 233 228bytes

ฉันแน่ใจว่านี่สามารถเล่นกอล์ฟได้มาก Redim preserveพวกเขาไม่ได้ระบุว่าหลายปัจจัยดังนั้นฉันเขียนยากความยาวอาร์เรย์ของฉันเพราะมันสั้นแล้ว

การป้อนข้อมูลผ่านป๊อปอัปการส่งออกเป็นdebug.printเพราะmsgboxสร้าง MODAL และรหัสหยุด

ฉันไม่รู้วิธีทดสอบว่านี่ถูกต้องกับ 0.01s หรือไม่ บางทีใครบางคนสามารถทดสอบได้ แต่ฉันกำลังให้หมายเลขคำสั่ง wait ในแบบที่มันควรใช้มิลลิวินาที แต่ VBA ไม่ทราบว่าทำสิ่งที่ควรทำ

อาจจะสามารถใช้แทนโดยแข็งแรงเล่นกอล์ฟได้ดีIf gotoDo Loop While

Sub a()
Dim k(99) As String
Dim h(99) As Date
b:
t=Now()
i=i+1
k(i)=InputBox("")
h(i)=Now()-t
If k(i)<>"" Then GoTo b
For u=1 To i
Application.Wait (Now()+(Format(h(u),"s")&Format(h(u),"ms"))/10^8)
Debug.Print k(u)
Next
End Sub

จะไม่ทำงานใน Access VBA เนื่องจากการเข้าถึงไม่มีคำสั่ง wait เนื่องจาก Microsoft เกลียดความสอดคล้อง


0

SmileBASIC ขนาด 122 ไบต์

DIM A$[0],T[0]@L
C=MAINCNT
LINPUT S$PUSH A$,S$PUSH T,MAINCNT-C
IF""<S$GOTO@L@P
WAIT SHIFT(T)IF""<A$[0]THEN?SHIFT(A$)GOTO@P

ฉันคิดว่านี่อาจทำให้สั้นลงเล็กน้อย


0

C UNIX, 272 ไบต์

#include <stdio.h>
#include <unistd.h>
#define P printf
i;r;c;main(){char*L[99]={0};size_t s;long T[99]={0};while(1){P(">  ");T[c]=time(0);r=getline(&L[c],&s,stdin);T[c]=time(0)-T[c];if(r==-1|!(*L[c]-10))break;c++;}while(i<c){P("> ");usleep(T[i]*1000);P("%s", L[i]);i++;}}

รายละเอียด

#include <stdio.h>
#include <unistd.h>

int main(void)
{
    int i = 0, c = 0, r;
    char * L[99] = {0};
    size_t size;
    long T[99] = {0L};

    while(1)
    {
        printf("> ");
        T[c] = time(0);
        r = getline(&L[c], &size, stdin);
        T[c] = time(0) - T[c];
        if(r == (-1)) break;
        if(*L[c]=='\0' || *L[c]=='\n') break;
        c = c + 1;
    }

    while(i < c)
    {
        printf(" %ld > ",T[i]);
        usleep(T[i]*1000);
        printf("%s", L[i]);
        i = i + 1;
    }

    return 0;
}
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.