เรียกใช้การถอดรหัสความยาว


20

เขียนรหัสที่สั้นที่สุดในภาษาที่คุณเลือกเพื่อทำการถอดรหัสการรันความยาวของสตริงที่กำหนด

สตริงจะถูกป้อนเป็นอินพุตใน stdinในแบบฟอร์ม

CNCNCNCNCNCNCNCN

โดยที่แต่ละตัวCอาจเป็นอักขระ ASCII ที่พิมพ์ได้และแต่ละตัวNนั้นเป็นตัวเลข1ถึง9(รวม)

ตัวอย่างอินพุต:

:144,1'1

ผลลัพธ์ที่สอดคล้องกัน:

:4444,'

คำตอบ:


28

Brainfuck, 34 ตัวอักษร

,[>,>++++++[<-------->-]<[<.>-]<,]

5
ว้าว. โซลูชัน brainfuck ที่สามารถแข่งขันกับโซลูชันอื่นได้หรือไม่
Johannes Kuhn

13

ภาษาการเขียนโปรแกรมของเช็คสเปียร์ 406 ไบต์

.
Ajax,.
Ford,.
Act I:.
Scene I:.
[Enter Ajax and Ford]
Scene II:.
Ford:
Open your mind.Is sky nicer than you?If so, let us return to scene IV.
Ajax:
Open your mind.You is sum you and sum big big big big big big pig and big big big big cat!
Scene III:.
Ford:
Speak thy mind.
Ajax:
You is sum you and pig!Is you as big as zero?If so, let us return to scene II.Let us return to scene III.
Scene IV:.
[Exeunt]

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

The Decoding of the Lengths of Veronan Runs - A Drama of PPCG.

Romeo, quite a character.
Juliet, Romeo's lover and multiplicand.

Act I: In which the lengths of runs are decoded.

Scene I: A silent entrance.

[Enter Romeo and Juliet]

Scene II: In which neither Romeo nor Juliet believes the other open-minded.

Juliet:
  Open your mind. Is my mother jollier than thou? If so,
  we must proceed to scene IV.

Romeo:
  Open your mind. Thou art the sum of thyself and the sum of my good aunt and
  the difference between nothing and the quotient of the square of twice the sum
  of thy foul fat-kidneyed goat and thy death and thy evil variable!

Scene III: In which Romeo snaps and brutally insults Juliet.

Juliet:
  Speak thy mind.

Romeo:
  Thou art the sum of thyself and a hog! Art thou as rotten as nothing? If so,
  let us return to scene II. Let us return to scene III.

Scene IV: Finale.

[Exeunt]

ฉันใช้คอมไพเลอร์ Python SPL ของ drsam94ซึ่งมีข้อบกพร่องเล็กน้อย (ซึ่งเป็นสาเหตุที่ยกตัวอย่างเช่นฉันใช้Open your mindแทนOpen thy mindในเวอร์ชัน golfed)

เพื่อรันโปรแกรมนี้ใช้:

$ python splc.py rld.spl > rld.c
$ gcc rld.c -o rld.exe
$ echo -n ":144,1'1" | ./rld
:4444,'

มันทำงานอย่างไร

SPL เป็นภาษาโปรแกรมลับที่ออกแบบมาเพื่อให้โปรแกรมดูเหมือนกับ Shakespeare ทำได้โดยใช้ตัวอักษรเป็นตัวแปรและการประมวลผลทำได้โดยให้ตัวละครพูดสิ่งต่าง ๆ กัน

The Decoding of the Lengths of Veronan Runs - A Drama of PPCG.

นี่คือชื่อของการเล่น; มันถูกละเว้นโดยคอมไพเลอร์

Romeo, quite a character.
Juliet, Romeo's lover and multiplicand.

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

Act I: In which the lengths of runs are decoded.

ที่นี่เราประกาศการกระทำแรกและที่เดียวในโปรแกรม การกระทำและฉากเป็นเหมือนป้ายกำกับ พวกเขาสามารถกระโดดไปที่ใดก็ได้โดยใช้let us return to scene IIหรือตัวแปรบางอย่างของที่ เราใช้การกระทำเพียงอย่างเดียวเพราะมันเพียงพอสำหรับความต้องการของเรา คอมไพเลอร์จะละเว้นสิ่งใดระหว่าง:และ.ถูกละเว้น

Scene I: A silent entrance.

ที่นี่เราประกาศฉากแรก ฉากถูกกำหนดหมายเลขเป็นเลขโรมันฉากแรกคือScene Iฉากที่สองScene IIเป็นต้น

[Enter Romeo and Juliet]

นี่คือทิศทางของเวที ในนั้นเราบอกRomeoและJulietตัวแปรที่จะเข้าสู่ "เวที" มีเพียงสองตัวแปรเท่านั้นที่สามารถอยู่ใน "สเตจ" พร้อมกัน สเตจจะถูกใช้เพื่อให้คอมไพเลอร์สามารถคิดได้ว่าตัวแปรใดที่อยู่ซึ่งเมื่อพวกเขาพูด เนื่องจากเรามีเพียงสองตัวแปรโรมิโอและจูเลียตจะอยู่บนเวทีตลอดความยาวของโปรแกรม

Scene II: In which neither Romeo nor Juliet believes the other open-minded.

ประกาศอีกฉาก ฉากที่สองจะถูกข้ามไปเพื่อถอดรหัสการวิ่งอีกครั้ง

Juliet:

การประกาศในรูปแบบนี้หมายความว่าจูเลียตกำลังจะเริ่มพูด ทุกอย่างจนกว่าคำสั่งRomeo:ขั้นต่อไปหรือการประกาศฉาก / การกระทำจะเป็นบรรทัดที่จูเลียตพูดดังนั้น "ฉัน" จะหมายถึงจูเลียต "คุณ" / "เจ้า" ถึงโรมิโอ ฯลฯ

Open your mind.

คำสั่งนี้จะจัดเก็บค่าลำดับของตัวละครเดียวจาก STDIN Romeoใน

Is my mother jollier than thou?

ใน SPL คำนามแปลเป็น 1 หรือ -1 ขึ้นอยู่กับว่าเป็นบวกหรือลบ ในกรณีนี้my motherแปลเป็น 1 คำคุณศัพท์ (บวกหรือลบ) คูณคำนามของพวกเขาด้วย 2

นี่เป็นคำถาม ในนั้น Juliet ถามว่าmy mother(AKA 1) เป็น "jollier" มากกว่า Romeo หรือไม่ การเปรียบเทียบอาจแปลเป็นless than(หากพวกเขาเป็นลบเช่นworse) หรือgreater than(ถ้าพวกเขาเป็นบวกเช่นjollier) Is 1 greater than you?ดังนั้นคำถามนี้เดือดลงไป

เหตุผลที่เราถามคำถามนี้คือเพื่อตรวจหาจุดสิ้นสุดของอินพุต เนื่องจากค่าEOFแตกต่างกันไปตามแพลตฟอร์ม แต่มักจะน้อยกว่า 1 เราจึงใช้สิ่งนี้เพื่อตรวจจับ

If so, we must proceed to scene IV.

หากคำถามก่อนหน้านี้ได้รับการประเมินtrueเราจะข้ามไปที่ฉาก IV ซึ่งเป็นเพียงจุดสิ้นสุดของโปรแกรม กล่าวโดยย่อหากเราตรวจพบ EOF เราจะสิ้นสุดโปรแกรม

Romeo:

ตอนนี้มันเป็นแนวของโรมิโอ: "ฉัน" และ "คุณ" หมายถึงโรมิโอและจูเลียตตามลำดับ

Open your mind.

อีกครั้งคำพูดนี้ทำให้ค่าลำดับตัวอักษรตัวเดียวจาก STDIN Romeoเข้าไปจูเลียตซึ่งในกรณีนี้คือระยะความยาวของตัวอักษรที่เก็บไว้ใน

Thou art the sum of thyself and the sum of my good aunt and the difference 
between nothing and the quotient of the square of twice the sum of thy foul
fat-kidneyed goat and thy death and thy evil variable!

คนนี้ยาวเกินกว่าจะได้รายละเอียดมาก แต่เชื่อใจฉันเถอะว่ามันแปลJuliet -= 48ว่า เราทำเช่นนี้เพราะจูเลียตถือค่า ASCII ของตัวเลขและord('0') == 48; ในการลบ 48 เราแปลจากค่า ASCII ของตัวเลขเป็นตัวเลขเอง

Scene III: In which Romeo snaps and brutally insults Juliet.

ประกาศฉากอื่น หนึ่งนี้เป็นห่วงที่เราซ้ำแล้วซ้ำอีกพิมพ์ค่าของตัวละครRomeo, Julietครั้ง

Juliet:
  Speak thy mind.

คำสั่งนี้ทำให้โรมิโอพิมพ์ค่าของเขาเป็นตัวละคร นั่นคือสิ่งที่มูลค่าตัวละครใด ๆ ที่เก็บไว้ก่อนหน้านี้ใน Romeo ตอนนี้เอาท์พุท

Romeo:
  Thou art the sum of thyself and a hog!

หมูเป็นคำนามเชิงลบดังนั้นa hogแปลเป็น -1; Juliet -= 1ดังนั้นคำสั่งนี้ประเมิน

Art thou as rotten as nothing?

โรมิโอที่นี่ถามว่าจูเลียตเป็น "เน่าเหมือน" หรือเท่ากับ 0

If so, let us return to scene II.

หากค่าของจูเลียตเป็น 0 เราจะวนกลับไปยังฉากที่ 2 เพื่อถอดรหัสความยาวของตัวละครอื่น

Let us return to scene III.

ถ้าอย่างนั้นเราวนกลับไปยังฉาก III เพื่อเอาท์พุทตัวละครของโรมิโออีกครั้ง

Scene IV: Finale.

[Exeunt]

การประกาศฉากสุดท้ายนี้เป็นเพียงเครื่องหมายสำหรับการสิ้นสุดของโปรแกรม [Exeunt]ทิศทางขั้นตอนมีความจำเป็นต้องได้รับการรวบรวมเพื่อสร้างจริงฉากสุดท้าย



5

perl, 27 ตัวอักษร

print<>=~s/(.)(.)/$1x$2/ger

print<>=~s/(.)(.)/$1x$2/gerนี้ดูเหมือนว่าไม่จำเป็นละเอียด: ฉันค่อนข้างแน่ใจว่าคุณหมายถึง$1x$2และไม่ใช่วิธีอื่น ๆ
primo

@primo จริง - ฉันไม่รู้เกี่ยวกับธง r และฉันหามันไม่เจอ ขอบคุณ ส่วนอื่น ๆ - ขอโทษฉันอ่านสเป็คผิด ฉันจะแก้ไขเมื่อฉันสามารถ
John Dvorak

BTW /rมีการบันทึกไว้ในperlopและเพิ่มใน v5.14.0
psxls

ใช้-pธงช่วยให้คุณลดลงprintและ<>เพื่อให้คำตอบที่จะกลายเป็นเพียง: s/(.)(.)/$1x$2/ge-> 17chars +1 สำหรับ-p-> 18
F. Hauri

4

R 67

x=strsplit(readline(),"")[[1]];cat(rep(x[c(T,F)],x[c(F,T)]),sep="")

+1 ฉันไม่รู้ว่าrepจะบังคับให้timesอาร์กิวเมนต์จากตัวละครเป็นจำนวนเต็มโดยอัตโนมัติ สุกใส
plannapus

4

Python 3, 52

Python 3 ช่วยให้ฉันสามารถรวมวิธีการแก้ปัญหาของ python2 ของฉันทั้งสอง

s=input()
t=''
while s:a,b,*s=s;t+=a*int(b)
print(t)

งูหลาม 2 raw_inputตรงกับงูหลาม input3 ดังนั้นบรรทัดแรกต้องเป็นs=input()
AMK

1
49:s=input() while s:a,b,*s=s;print(a*int(b),end='')
Cees Timmerman


3

APL (22)

,/{⍺/⍨⍎⍵}/↑T⊂⍨~⎕D∊⍨T←⍞

คำอธิบาย:

  • T←⍞: เก็บอินพุตใน T
  • T⊂⍨~⎕D∊⍨T: แยกTตัวละครเหล่านั้นที่ไม่ใช่ตัวเลข
  • : เปลี่ยนเป็น2-by- N/2เมทริกซ์
  • {⍺/⍨⍎⍵}/: ในแต่ละแถวของเมทริกซ์ ( /) ให้ทำซ้ำ ( /) อักขระแรก ( ) โดย eval ( ) ของอักขระที่สอง ( )
  • ,/: เชื่อมต่อผลลัพธ์ของแต่ละแถว

3

Ruby ขนาด 30 ไบต์

gsub!(/(.)(.)/){$1*$2.to_i}

27 ไบต์รหัส + 3 ไบต์เพื่อเรียกใช้กับ-pธง:

$ ruby -p rld.rb <<< ":144,1'1"
:4444,'

2

8086 ชุด, 106 98 ตัวอักษร

l:
mov ah,8
int 21h
mov bl,al
int 21h
sub al,48
mov cl,al
xor ch,ch
mov al,bl
mov ah,14
p:
int 10h
loop p
jmp l

หากตัวเลขอยู่หน้าอักขระในสตรีมอินพุตสองบรรทัด (18 ตัวอักษร) อาจถูกตัดออกจากสิ่งนี้


เพิ่งลบ "mov ah, 8" ที่ซ้ำซ้อนออกไป
Mike C

2
คุณควรโพสต์การนับจำนวนไบต์ที่คอมไพล์แทนที่จะเป็นตัวนับถ่านของผู้รวบรวม กฎการละเมิด FTW
arrdem

ประมาณdq 21cdc38821cd08b4 d888ed30c188482c e8ebfce210cd14b453 ตัวอักษรล่ะ? ฉันไม่เห็นว่ามันจัดการกับตัวละครที่ไม่ใช่ตัวพิมพ์ใหญ่หรือ eof ...
Jason Goemaat

arrdem: ความคิดที่ดี ฉันสงสัยว่ามันผิดกฎหรือเปล่าถ้าฉันรวบรวมมันด้วยตัวแก้ไข hex ฉันยังคงเขียนโค้ดโดยตรงในระดับที่ต่ำกว่า asm source :) Jason: ฉันไม่เห็นอะไรเกี่ยวกับ EOF ในกฎ มันเป็น stdin เพียงกด ctrl-c เพื่อหยุด ทำไมถึงไม่จัดการกับตัวอักษรตัวเล็ก?
Mike C

โดยทั่วไปรหัสเครื่องจะถูกนับด้วยจำนวนไบต์เปรียบเทียบกับจำนวนซอร์สโค้ดสำหรับภาษาที่แปลหรือเรียบเรียงเนื่องจากไม่มีตัวเลือกอื่นที่สมเหตุสมผล
Joe Z.

2

GNU SED, 122 + 2 (-r)

#n
s/.*/\n&\a987654321\v\v\v\v\v\v\v\v\v/
:a
s/\n(.)(.)(.*\a.*\2.{9}(.*))/\1\n\4\3/
tb
bc
:b
s/(.)\n\v/\1\1\n/
tb
ba
:c
P

ความต้องการที่จะทำงานด้วยการ-rตั้งค่าสถานะ
อาจลดลงเป็น 110 + 2 โดยแทนที่\vด้วย unprintable 0x0Bและ\aด้วย0x07


+1 ( \2.{9}เป็นความคิดที่ดี) ยอดเยี่ยม!
F. Hauri

2

C, 65 ตัวอักษร

รับอินพุตเป็นพารามิเตอร์

main(p,v)char*p,**v;{
    for(p=v[1];*p;--p[1]<49?p+=2:0)putchar(*p);
}

ฉันไม่สามารถรับที่ผ่านมานี้กับ error: first parameter of 'main' (argument count) must be of type 'int'GCC: มีสวิตช์บรรทัดคำสั่งหรือไม่
Darren Stone

@DarrenStone รหัสนี้ไม่ได้มาตรฐาน 100% ฉันไม่ได้ใช้พารามิเตอร์ตัวแรกเป็นพารามิเตอร์ดังนั้นชนิดของมันจึงไม่สำคัญ คอมไพเลอร์ส่วนใหญ่ไม่สนใจอะไรมาก
ugoren

โอเคขอบคุณ. ฉันอิจฉาผู้รวบรวมนักเล่นกอล์ฟของคุณ! :)
Darren Stone

2

Perl, 19 18 ตัวอักษร

perl -pe 's/(.)(.)/$1x$2/ge'

กฎระเบียบสำหรับการนับสวิทช์ในบรรทัดคำสั่งที่มีที่นี่




2

Windows PowerShell, 55 ตัวอักษร

-join((read-host)-split'(..)'|%{(""+$_[0])*(""+$_[1])})

ฉันรู้สึกว่ามันสามารถเล่นกอล์ฟได้มากขึ้นโดยเฉพาะอย่างยิ่งกับบทละครจากตัวละครตัวละครถึงเรื่องสายอักขระ แต่ฉันไม่มีเวลาที่จะทำงานต่อไปในตอนนี้


2

C, 68 ตัวอักษร

คำตอบของ @ ugoren ใน C สั้นกว่าเล็กน้อย แต่คำตอบนี้สอดคล้องกับข้อกำหนดที่ว่า "สตริงจะถูกป้อนเป็นอินพุตในstdin "

n;main(c){for(;;){c=getchar(),n=getchar()-48;while(n--)putchar(c);}}

คุณสามารถโกนอักขระได้โดยปล่อย "int" และประกาศ c และ n เป็นพารามิเตอร์ของ main อีกตัวใช้ for (;;) แทนขณะที่ (1) และสุดท้ายอีกสองครั้งโดยวาง braces บนสุดในขณะที่วนรอบ
Stuntddude

ขอบคุณ @Stuntddude! ฉันใช้คำแนะนำลูปและรั้ง แต่ฉันดิ้นรนกับ "ประกาศ c และ n เป็นพารามิเตอร์ของหลัก" ถึงกระนั้นโกน 3 ตัวอักษรนี้ ไชโย
Darren Stone

เนื่องจาก main () เป็นฟังก์ชั่นคุณสามารถกำหนดพารามิเตอร์ได้เช่น: main(c,n){ ... }ซึ่งจะถูกส่ง 1 โดยค่าเริ่มต้นเมื่อโปรแกรมทำงาน
Stuntddude

ขอบคุณ @Stuntddude ฉันรู้ว่าและสามารถใช้ประโยชน์จาก 1 intหาเรื่อง แต่คอมไพเลอร์ (s) ฉันใช้บ่นerror: second parameter of 'main' (argument array) must be of type 'char **'ดังนั้นฉันไม่สามารถรับไปกับmain(c,n); main(int c,char **n)ฉันต้องใช้ อาจเป็นแพลตฟอร์มหรือสิ่ง gcc
Darren Stone

ผู้รวบรวมของฉันให้ฉันทำn;main(c)แต่ไม่main(n,c)- ดีพอ! :)
Darren Stone

2

Haskell, 58 56 ตัวอักษร

f[]=[]
f(x:y:s)=replicate(read[y])x++f s
main=interact$f

ความพยายามครั้งแรกของฉันในการเล่นกอล์ฟทุกอย่างดังนั้นอาจมีการปรับปรุงบ้างที่นี่


1
read[y]บันทึกอักขระสองตัว
MtnViewMark

@MtnViewMark ขอบคุณ ฉันใส่ไว้ใน
Silvio Mayolo

ฉันได้รับ 57 ไบต์สำหรับสิ่งนี้? คุณสามารถแทนที่ด้วยreplicate x y [1..x]>>[y]ดังนั้นบรรทัดที่สองของคุณสามารถถูกแทนที่ด้วยf(x:y:s)=(['1'..y]>>[x])++f sซึ่งจะลดลงเหลือ 53 ไบต์
Angs

2

Japtet -P , 8 ไบต์

อินพุตเป็นอาร์เรย์ของอักขระเอาต์พุตเป็นสตริง

ò crÈpY°

ลองมัน

ò crÈpYn     :Implicit input of character array
ò            :Groups of 2
   r         :Reduce each pair
    È        :By passing them through the following function as [X,Y]
     p       :  Repeat X
      Yn     :    Y, converted to an integer, times
             :Implicitly join and output

โอ้คอาร์อี epy!
Khuldraeseth na'Barya

@ Khuldraesethna'Barya มันอาจเป็นไปได้ò crϰîXถ้าคุณพบว่ามันน่าขนลุกเกินไป!
Shaggy

2

Malbolge Unshackled (ตัวแปรการหมุน 20 trit), 4,494e6 ไบต์

ขนาดของคำตอบนี้เกินขนาดโปรแกรมที่สามารถโหลดสูงสุด (เอ๊ะ) ดังนั้นรหัสจะตั้งอยู่ในพื้นที่เก็บข้อมูล GitHub ของฉัน

วิธีการใช้งานนี้

นี่อาจเป็นส่วนที่ยุ่งยากเนื่องจากล่ามที่ไร้เดียงสาของ Haskell จะใช้เวลานานในการรันสิ่งนี้ TIO มีล่าม Malbogle Unshackled ที่ดี แต่น่าเศร้าที่ฉันไม่สามารถใช้งานได้ (ข้อ จำกัด )

ที่ดีที่สุดที่ฉันสามารถหาเป็นคงที่ 20 trit หมุนกว้างตัวแปรที่มีประสิทธิภาพดีมาก, คลาย 360 ไบต์ต่อชั่วโมง

เพื่อให้ล่ามเร็วขึ้นฉันได้ลบเช็คทั้งหมดออกจากล่าม Malbolge Unshackled ของ Matthias Lutter

เวอร์ชันที่แก้ไขของฉันสามารถทำงานได้เร็วขึ้นประมาณ 6,3%

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const char* translation = "5z]&gqtyfr$(we4{WP)H-Zn,[%\\3dL+Q;>U!pJS72Fh"
        "OA1CB6v^=I_0/8|jsb9m<.TVac`uY*MK'X~xDl}REokN:#?G\"i@";

typedef struct Word {
    unsigned int area;
    unsigned int high;
    unsigned int low;
} Word;

void word2string(Word w, char* s, int min_length) {
    if (!s) return;
    if (min_length < 1) min_length = 1;
    if (min_length > 20) min_length = 20;
    s[0] = (w.area%3) + '0';
    s[1] = 't';
    char tmp[20];
    int i;
    for (i=0;i<10;i++) {
        tmp[19-i] = (w.low % 3) + '0';
        w.low /= 3;
    }
    for (i=0;i<10;i++) {
        tmp[9-i] = (w.high % 3) + '0';
        w.high /= 3;
    }
    i = 0;
    while (tmp[i] == s[0] && i < 20 - min_length) i++;
    int j = 2;
    while (i < 20) {
        s[j] = tmp[i];
        i++;
        j++;
    }
    s[j] = 0;
}

unsigned int crazy_low(unsigned int a, unsigned int d){
    unsigned int crz[] = {1,0,0,1,0,2,2,2,1};
    int position = 0;
    unsigned int output = 0;
    while (position < 10){
        unsigned int i = a%3;
        unsigned int j = d%3;
        unsigned int out = crz[i+3*j];
        unsigned int multiple = 1;
        int k;
        for (k=0;k<position;k++)
            multiple *= 3;
        output += multiple*out;
        a /= 3;
        d /= 3;
        position++;
    }
    return output;
}

Word zero() {
    Word result = {0, 0, 0};
    return result;
}

Word increment(Word d) {
    d.low++;
    if (d.low >= 59049) {
        d.low = 0;
        d.high++;
        if (d.high >= 59049) {
            fprintf(stderr,"error: overflow\n");
            exit(1);
        }
    }
    return d;
}

Word decrement(Word d) {
    if (d.low == 0) {
        d.low = 59048;
        d.high--;
    }else{
        d.low--;
    }
    return d;
}

Word crazy(Word a, Word d){
    Word output;
    unsigned int crz[] = {1,0,0,1,0,2,2,2,1};
    output.area = crz[a.area+3*d.area];
    output.high = crazy_low(a.high, d.high);
    output.low = crazy_low(a.low, d.low);
    return output;
}

Word rotate_r(Word d){
    unsigned int carry_h = d.high%3;
    unsigned int carry_l = d.low%3;
    d.high = 19683 * carry_l + d.high / 3;
    d.low = 19683 * carry_h + d.low / 3;
    return d;
}

// last_initialized: if set, use to fill newly generated memory with preinitial values...
Word* ptr_to(Word** mem[], Word d, unsigned int last_initialized) {
    if ((mem[d.area])[d.high]) {
        return &(((mem[d.area])[d.high])[d.low]);
    }
    (mem[d.area])[d.high] = (Word*)malloc(59049 * sizeof(Word));
    if (!(mem[d.area])[d.high]) {
        fprintf(stderr,"error: out of memory.\n");
        exit(1);
    }
    if (last_initialized) {
        Word repitition[6];
        repitition[(last_initialized-1) % 6] =
                ((mem[0])[(last_initialized-1) / 59049])
                    [(last_initialized-1) % 59049];
        repitition[(last_initialized) % 6] =
                ((mem[0])[last_initialized / 59049])
                    [last_initialized % 59049];
        unsigned int i;
        for (i=0;i<6;i++) {
            repitition[(last_initialized+1+i) % 6] =
                    crazy(repitition[(last_initialized+i) % 6],
                        repitition[(last_initialized-1+i) % 6]);
        }
        unsigned int offset = (59049*d.high) % 6;
        i = 0;
        while (1){
            ((mem[d.area])[d.high])[i] = repitition[(i+offset)%6];
            if (i == 59048) {
                break;
            }
            i++;
        }
    }
    return &(((mem[d.area])[d.high])[d.low]);
}

unsigned int get_instruction(Word** mem[], Word c,
        unsigned int last_initialized,
        int ignore_invalid) {
    Word* instr = ptr_to(mem, c, last_initialized);
    unsigned int instruction = instr->low;
    instruction = (instruction+c.low + 59049 * c.high
            + (c.area==1?52:(c.area==2?10:0)))%94;
    return instruction;
}

int main(int argc, char* argv[]) {
    Word** memory[3];
    int i,j;
    for (i=0; i<3; i++) {
        memory[i] = (Word**)malloc(59049 * sizeof(Word*));
        if (!memory) {
            fprintf(stderr,"not enough memory.\n");
            return 1;
        }
        for (j=0; j<59049; j++) {
            (memory[i])[j] = 0;
        }
    }
    Word a, c, d;
    unsigned int result;
    FILE* file;
    if (argc < 2) {
        // read program code from STDIN
        file = stdin;
    }else{
        file = fopen(argv[1],"rb");
    }
    if (file == NULL) {
        fprintf(stderr, "File not found: %s\n",argv[1]);
        return 1;
    }
    a = zero();
    c = zero();
    d = zero();
    result = 0;
    while (!feof(file)){
        unsigned int instr;
        Word* cell = ptr_to(memory, d, 0);
        (*cell) = zero();
        result = fread(&cell->low,1,1,file);
        if (result > 1)
            return 1;
        if (result == 0 || cell->low == 0x1a || cell->low == 0x04)
            break;
        instr = (cell->low + d.low + 59049*d.high)%94;
        if (cell->low == ' ' || cell->low == '\t' || cell->low == '\r'
                || cell->low == '\n');
        else if (cell->low >= 33 && cell->low < 127 &&
                (instr == 4 || instr == 5 || instr == 23 || instr == 39
                    || instr == 40 || instr == 62 || instr == 68
                    || instr == 81)) {
            d = increment(d);
        }
    }
    if (file != stdin) {
        fclose(file);
    }
    unsigned int last_initialized = 0;
    while (1){
        *ptr_to(memory, d, 0) = crazy(*ptr_to(memory, decrement(d), 0),
                *ptr_to(memory, decrement(decrement(d)), 0));
        last_initialized = d.low + 59049*d.high;
        if (d.low == 59048) {
            break;
        }
        d = increment(d);
    }
    d = zero();

    unsigned int step = 0;
    while (1) {
        unsigned int instruction = get_instruction(memory, c,
                last_initialized, 0);
        step++;
        switch (instruction){
            case 4:
                c = *ptr_to(memory,d,last_initialized);
                break;
            case 5:
                if (!a.area) {
                    printf("%c",(char)(a.low + 59049*a.high));
                }else if (a.area == 2 && a.low == 59047
                        && a.high == 59048) {
                    printf("\n");
                }
                break;
            case 23:
                a = zero();
                a.low = getchar();
                if (a.low == EOF) {
                    a.low = 59048;
                    a.high = 59048;
                    a.area = 2;
                }else if (a.low == '\n'){
                    a.low = 59047;
                    a.high = 59048;
                    a.area = 2;
                }
                break;
            case 39:
                a = (*ptr_to(memory,d,last_initialized)
                        = rotate_r(*ptr_to(memory,d,last_initialized)));
                break;
            case 40:
                d = *ptr_to(memory,d,last_initialized);
                break;
            case 62:
                a = (*ptr_to(memory,d,last_initialized)
                        = crazy(a, *ptr_to(memory,d,last_initialized)));
                break;
            case 81:
                return 0;
            case 68:
            default:
                break;
        }

        Word* mem_c = ptr_to(memory, c, last_initialized);
        mem_c->low = translation[mem_c->low - 33];

        c = increment(c);
        d = increment(d);
    }
    return 0;
}

มันใช้งานได้!

มันใช้งานได้ดี


2

05AB1E , 6 5 ไบต์

2ι`ÅΓ

-1 ขอบคุณไบต์@Grimy

เอาต์พุตเป็นรายการของอักขระ

ลองออนไลน์

คำตอบเก่า 6 ไบต์ที่ไม่มีตัวถอดรหัสความยาว run:

2ôε`×?

ลองออนไลน์

คำอธิบาย:

2ι      # Uninterleave the (implicit) input-string in two parts
        #  i.e. ":144,1'3" → [":4,'","1413"]
  `     # Push both separated to the stack
   ÅΓ   # Run-length decode
        #  i.e. ":4,'" and "1413" → [":","4","4","4","4",",","'","'","'"]
        # (after which the result is output implicitly)

2ô      # Split the (implicit) input-string into parts of size 2
        #  i.e. ":144,1'3" → [":1","44",",1","'3"]
  ε     # Loop over each of these pairs:
   `    #  Push both characters separated to the stack
    ×   #  Repeat the first character the digit amount of times as string
        #   i.e. "'" and "3" → "'''"
     ?  #  And print it without trailing newline

1
2ι`ÅΓคือ 5 ไบต์ คงจะเศร้าถ้า RLE ในตัวไม่ชนะการท้าทาย RLE
Grimmy

@Grimy Ah ดีกว่าจริง ๆ ขอบคุณ! :)
Kevin Cruijssen

1

Python, 78 72 66 ถ่าน

d = raw_input ()
พิมพ์ "". เข้าร่วม ([x * int (d [i + 1]) สำหรับ i, x เป็นการแจกแจง (d) ถ้า ~ i & 1])

s = raw_input ()
พิมพ์ "". เข้าร่วม (i * int (j) สำหรับ i, j ใน zip (s [:: 2], s [1 :: 2]))





1

Python 2, 58

นี่เป็นแรงบันดาลใจจากโซลูชันหลามของ Darren Stone - การทำซ้ำแบบวนซ้ำ

x=iter(raw_input())
print''.join(a*int(next(x))for a in x)

นี่คือโซลูชันดั้งเดิมของฉัน (60 ตัวอักษร)

s=raw_input()
t=''
while s:t+=s[0]*int(s[1]);s=s[2:]
print t

วิธีที่แตกต่างคือ 3 ตัวอักษรอีกต่อไป:

f=lambda a,b,*x:a*int(b)+(x and f(*x)or'')
print f(raw_input())

1

Java: 285 charas

import java.util.Scanner;public class A{public static void main(String args[]){Scanner s = new Scanner(System.in);while(s.hasNext()){String t=s.next();for(int i=0;i<t.length();i++) {for(int j=0; j<(Byte.valueOf(t.substring(i+1,i+2)));j++){System.out.print(t.substring(i,i+1));}i++;}}}}

ใช้บล็อกคงที่แทนที่จะเป็นหลักและรวบรวมด้วย Java6!
Fabinout


1

ช่องว่าง, 135

LSSSLSSSSLSLSTLTSTTTSLSSSSTSSSSLTSSTLTTTTLSSSSLSLSTLTSTTTSSSTTSSSSLTSSTLSSSSLSLSLTSTLSSSTLTSSTSTSSTLTLSSLSLSSLLSSTLSLLSLLLSLSLLSSTTLLLL

(แทนที่ S, T, L ด้วย Space, Tab, Linefeed อักขระ)

ลองมันออนไลน์[ที่นี่]

คำอธิบาย:

"assembly"      whitespace                                      stack
----------      ----------                                      -----
s:              LSS SL      ;input loop                         []
    push 0      SS SSL                                          [0]
    dup         SLS                                             [0,0]
    getc        TLTS        ;input & store char c               [0]
    rcl         TTT         ;recall c                           [c]
    dup         SLS                                             [c,c]
    push 16     SS STSSSSL                                      [c,c,16]
    sub         TSST                                            [c,c-16]
    jlt  tt     LTT TTL     ;exit if ord(c) < 16                [c]       
    push 0      SS SSL                                          [c,0]
    dup         SLS                                             [c,0,0]
    getc        TLTS        ;input & store char n               [c,0]
    rcl         TTT         ;recall n                           [c,n]
    push 48     SS STTSSSSL ;convert n to m = ord(n)-ord('0')   [c,n,48]
    sub         TSST                                            [c,m]

ss:             LSS SSL     ;inner loop outputs c, m times      [c,m]
    dup         SLS                                             [c,m,m]
    jeq  t      LTS TL      ;if m==0, stop outputting this c    [c,m]
    push 1      SS STL      ;otherwise decr m                   [c,m,1]
    sub         TSST                                            [c,m-1]
    copy 1      STS STL     ;copy c to tos                      [c,m-1,c]
    putc        TLSS        ;output this c                      [c,m-1]
    jmp  ss     LSL SSL     ;loop back to output this c again   [c,m-1]

t:              LSS TL                                          [c,m]
    pop         SLL                                             [c]
    pop         SLL                                             []
    jmp  s      LSL SL      ;loop back to get the next c,n      []

tt:             LSS TTL                                         [c]
    end         LLL         ;exit

1

Clojure (107)

(pr(apply str(map #(apply str(repeat(Integer/parseInt(str(second %)))(first %)))(partition 2(read-line)))))

สิ่งนี้ให้ความรู้สึกยาวเป็นพิเศษสำหรับการเป็น Clojure ถ้ามีคนสามารถทำได้ดีกว่าโปรดโพสต์


60 หรือ 73 ไบต์ที่codegolf.stackexchange.com/a/188823/59617 ;)
NikoNyrh
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.