หน้าต่าง Hello World


22

สร้างหน้าต่างที่กล่าวสวัสดีโลกภายในและไม่มีอะไรอื่น คุณไม่สามารถมีปุ่มตกลงหรือยกเลิกภายใน มันจะต้องเป็นเพียงหน้าต่างธรรมดาที่บอกว่าสวัสดีโลก ฉันไม่สนใจเกี่ยวกับเนื้อหาของกรอบหน้าต่างหรือลักษณะของหน้าต่าง แต่ภายในนั้นต้องบอกว่าสวัสดีโลกเท่านั้น

ตัวอย่าง:
enter image description here

รหัสที่สั้นที่สุดชนะ

แก้ไข: ฉันขอโทษ Johannes Kuhn หน้าต่างต้องอยู่ที่นั่นจริง ๆ มันอาจไม่ได้ปิดทันที ฉันไม่ได้นึกถึงสถานการณ์นี้และไม่ได้คำนึงถึงสิ่งนี้

แก้ไข 2: ขณะนี้เรามี 3 คำตอบผูก (20 ตัวอักษร) ข้อเสนอแนะของผู้ที่ควรจะเป็นผู้ชนะก็ยินดีต้อนรับ


1
หน้าต่างต้องมีขนาดใหญ่พอที่จะแสดงข้อความหรือไม่เมื่อมันปรากฏขึ้นหรือไม่เป็นไรที่ผู้ใช้ต้องปรับขนาดหน้าต่างหรือไม่
— Iszi

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

ฉันสามารถทำให้มันสั้นเท่ากับของ Sven แต่ด้วยปุ่ม OK และ Cancel :(
— Teresa e Junior

ดูเหมือนว่าจะมีคำตอบ Bash ตอนอายุ 19 แล้ว
— Iszi

2
ฉันสามารถทำโซลูชัน VB 6 ที่มีป้ายกำกับด้วย "Hello World" ได้หรือไม่ โซลูชั่นรหัส 0?
— Cruncher

คำตอบ:


13

ทุบ20ตัวอักษร20

ขอบคุณ @ manatwork สำหรับพื้นที่ที่ไร้ประโยชน์หลังจากนั้น-p!

read -pHello\ World

ในการดำเนินการ:

echo 'read -pHello\ World' >/tmp/helloworld.sh
chmod +x /tmp/helloworld.sh

กว่าดับเบิ้ลคลิกจากตัวจัดการไฟล์:

enter image description here

และดู:

enter image description here

มีเป็นเปลือกเริ่มต้น

19 16

เป็นขาตั้งคำถามสำหรับเพียง Hello Worldและไม่มีอะไรอื่น , หน้าต่างต้องอยู่แต่ไม่มีอะไรเช่นพิมพ์ข้อความเพียงครั้งเดียวหรืออื่น ๆ ผมคิดว่าการแข่งขันครั้งนี้ต้องการมากเกินไป!

yes Hello\ World

มีเพียง 16 ตัวอักษร

echo >/tmp/helloworld.sh 'yes Hello\ World'

ด้วยวิธีการเดียวกันนี้ให้:

enter image description here


1
ดูเหมือนว่า GNOME กับฉัน
— Pierre Arlaud

2
ฉันคิดว่าส่วน "เลือกรันในเทอร์มินัล" ควรนับเป็นอย่างน้อยที่สุด 1 ไบต์ คล้ายกับกฎเกี่ยวกับตัวเลือกที่ส่งไปยังล่ามเมื่อใช้สารละลาย codegolf
— Bakuriu

1
@Bakuriu ทั้งนี้ขึ้นอยู่กับการใช้งานส่วนบุคคลของคุณสามารถกำหนดค่าให้คุณจัดการหน้าต่างที่จะไม่ถามและเรียกใช้เสมอภายใต้เปลือกบางส่วนหรือขั้วของทางเลือกของคุณ ... (ฉันคิดว่ามันเริ่มต้นภายใต้ MS-Window)
— เอฟ HAURI

2
@Bakuriu เช่นการติดตั้งHQ9+ล่ามเพิ่ม.hq9+เป็นกำลังการผลิตละครใบ้ : ทำงานHQ9+ในสถานีหน้าต่าง ดังนั้นความท้าทายอาจลดลงถึง 1 ไบต์ คำตอบนี้ขึ้นอยู่กับคำตอบก่อนหน้านี้โดยใช้แบทช์หรือPowerShellและใช้ระบบปฏิบัติการที่ใช้เคล็ดลับประเภทนี้เป็นค่าเริ่มต้น
— F. Hauri

3
@JohannesKuhn คุณบ้าไปแล้ว! ด้านนอกไม่เกิน 2 ° C! หนาวเกินไป !!
— F. Hauri

23

พรอมต์คำสั่งของ Windows, 26

echo Hello World>.hta&.hta

enter image description here


นี่มันเจ๋งมาก. คะแนนโบนัสสำหรับการวางไข่สองหน้าต่างหรือไม่
— Gusdor

@Gusdor คุณหมายถึงอะไร ฉันเห็นเพียงหน้าต่างเดียวที่ปรากฏที่นี่
— Iszi

@Iszi ฉันได้ทำการสันนิษฐานว่าไฟล์แบตช์นั้นรันจากเดสก์ท็อปไม่ได้พิมพ์ อ๊ะ!
— Gusdor

@Gusdor ฉันคิดว่านั่นเป็นสาเหตุที่เขาเรียกมันว่า "Windows Command Prompt" แทนที่จะเป็น "แบทช์" มิเช่นนั้นคำตอบของโยฮันเนสก็จะหายไป
— Iszi

1
@Iszi: นี่เป็นการเปิดหน้าต่างใหม่ดังนั้นจึงไม่สำคัญว่าคำสั่งจะถูกสะท้อนในหน้าต่างอื่นหรือไม่ ...
— Ry-

15

R, 23

plot(1,m="Hello World")

สิ่งนี้จะเปิดหน้าต่างการลงจุด


+1 คุณสามารถย่อsub=ให้เล็กลงs=ด้วยการจับคู่บางส่วนอย่างไรก็ตาม
— plannapus

@plannapus ขอบคุณความคิดที่ดี! ฉันแก้ไขรหัสของฉัน
— Sven Hohenstein

สเวนนี่ไม่ได้พิมพ์"สวัสดีโลกข้างในและไม่มีอะไร" :) ฉันได้เข้าร่วมในความท้าทายที่คล้ายกันและมันจะต้องทำแตกต่างกันดูcodegolf.stackexchange.com/a/19807/2800
— Tomas

1
@Tomas ความท้าทายนี้ต่างออกไป จากคำถาม: " ฉันไม่สนใจเนื้อหาของกรอบหน้าต่าง "
— Sven Hohenstein

แต่นี่ไม่เกี่ยวกับเฟรม แต่รวมถึงข้อความ - ป้ายกำกับแกน "ดัชนี" ตัวเลขและอื่น ๆ
— Tomas


11

พาวเวอร์เซลล์, 23

'Hello World'>.hta;.hta

enter image description here


ดี! เอาชนะโซลูชัน "ของจริง" ของฉันและยาวกว่าวิธีทางลัดเพียง 3 ตัวอักษร แม้ว่าจะพิสูจน์ได้ว่าสิ่งนี้ไม่ได้ดีไปกว่าการใช้Hello Worldเพียงอย่างเดียวและเรียกมันว่า HTML เนื่องจากเป็นสิ่งที่คุณได้ทำไปแล้ว คุณเพิ่งใช้ PowerShell เพื่อสร้างและดำเนินการ
— Iszi

11

HTML (kinda) อายุ 17 ปี

data:,Hello World

วางสิ่งนั้นลงในแถบที่อยู่ของเบราว์เซอร์ของคุณ

Javascript, 25

open("data:,Hello World")

สิ่งนี้ใช้เบราว์เซอร์ของคุณwindow.openและ data uri

ประเภท Mime ของ Data URIs และชุดอักขระเริ่มต้นเป็นtext/plain;charset=US-ASCIIเมื่อละเว้น

Javascript, 19

eval($("s").text())

อันนี้ใช้ได้เฉพาะเมื่อคำตอบนี้เป็นคำตอบด้านบน (หรือยอมรับ) และจะทำงานในหน้า stackoverflow นี้ (ผ่านคอนโซล JavaScript ของคุณ) :-)

เปิด ("data:, Hello World");


เคล็ดลับตลก แต่น่าเสียดายที่มันขึ้นอยู่กับการเรียงลำดับของโพสต์ซึ่งอาจแตกต่างกันไป
— จัดการ

1
มันจะทำงานได้ตราบใดที่มันเป็นคำตอบที่ยอมรับ (และคำถามไม่มี "<s>")
— David Murdoch

ฮ่า ๆ. ฉันต้องโหวตให้กับการมองโลกในแง่ดีของคุณ
— จัดการ

คุณอธิบายได้ไหมว่ามันจะใช้งานได้อย่างไร ฉันใช้โครเมี่ยมและได้พยายามทำงานบนคอนโซล Unexpected token ILLEGALแต่ฉันได้รับ คุณต้องเป็นคำตอบที่ดีที่สุดในการทำงานหรือไม่
— Quillion

ใช่มันต้องเป็นคำตอบอันดับต้น ๆ สำหรับการทำงาน หรือฉันสามารถแก้ไขคำถามเองเพื่อรวม<s>open("data:,Hello World");</s>HTML ที่ต้องการแต่นั่นอาจเป็นการโกงมากเกินไป :-p
— David Murdoch

9

Matlab, 30 27 20

title('Hello World')

พล็อต windows อนุญาตหรือไม่ ไม่มีปุ่มใด ๆ อยู่ข้างใน


ใช่หน้าต่างพล็อตเป็นเรื่องดี :) ตราบใดที่มันเป็นหน้าต่างฉันไม่สนใจ
— Quillion

รูป ('ชื่อ', 'Hello World') สั้นกว่า
— magu_

@magu_ ความคิดที่ดี แต่ฉันคิดว่ามันผิดกฎ "หน้าต่างที่ระบุว่าสวัสดีโลกภายใน "
— Sven Hohenstein

1
@SvenHohenstein อืมบางที อย่างน้อยสิ่งที่เป็นประโยชน์ในการพูด: คุณไม่จำเป็นต้อง (1) จำเป็น ทำให้รหัส 3 ตัวเล็กลง
— magu_

1
คุณไม่ต้องการจริงๆfigure;
— Torbjørn T.

9

Java, 117 ตัวอักษร

import java.awt.*;class C{public static void main(String[]a){new Frame(){{add(new Label("Hello World"));show();}};}}

ด้วยการจัดรูปแบบ:

import java.awt.*;

class C {
    public static void main(String[] a) {
        new Frame() {
            {
                add(new Label("Hello World"));
                show();
            }
        };
    }
}

เราสามารถหลีกเลี่ยงการประกาศตัวแปรอย่างชัดเจนโดยใช้บล็อก initializerภายในคลาสย่อยที่ไม่ระบุชื่อของ Frame ที่น่าสนใจคือการใช้ awt เป็นเพียงตัวละครหลายตัวเพื่อimport java.awt.*;ให้มีคุณสมบัติครบถ้วนทั้งชื่อคลาส


8
คุณสามารถเรียกargsสิ่งที่คุณต้องการ; aเพียงพอแล้ว
— daniero

@daniero ขอบคุณสำหรับข้อเสนอแนะสวยโง่ของผมที่จะพลาดที่ :)
— swilliams

1
s/class/enum/
— โทมัส Eding

like @ThomasEding คำแนะนำการแทนที่คลาสโดย enum โกนหนวดออกหนึ่งไบต์
— masterX244

@ masterX244 ที่จะไม่ถูกต้อง syntactically เว้นแต่อัฒภาคถูกเพิ่มก่อนpublic static...ที่จะจบรายการของค่าคงที่ enum และ ... ดูstackoverflow.com/questions/7318011/... ไม่ว่าในกรณีใดคุณจะจบลงด้วยจำนวนอักขระที่เท่ากัน
— swilliams

7

Mathematica 29 27 25

ด้วย 1 ไบต์ที่บันทึกไว้ต้องขอบคุณ CatsAreFluffy

DialogInput@"hello world"

hello world


CreateDialogสั้นกว่า
— alephalpha

ขอบคุณ ฉันคิดว่า CreateDialog จะใส่ปุ่มตกลง
— DavidC

DialogInputสั้นลง 1 ไบต์
— CalculatorFeline

ใช่ขอบคุณและการจัดฟันแบบหยิกก็ไม่จำเป็นเช่นกัน
— DavidC

5

เชลล์, 32

xmessage -buttons '' Hello World

1
มีวิธีที่ 1 xterm -e 'read -p Hello\ World'ตัวละครสั้นคือ:
— จัดการ

ฉันคงจะสั้นกว่านี้ถ้าฉันไม่ต้อง-buttons '':(
— Hasturkun

@Hasturkun ฉันเห็นด้วย แต่ฉันต้องเพิ่มความต้องการปุ่มกำจัดเพราะจาวาสคริปต์จะชนะด้วยการแจ้งเตือนของพวกเขาหรือทางลัดอื่น ๆ เช่นนั้นและฉันรู้สึกว่ามันไม่ยุติธรรมและธรรมดาเกินไปโดยเฉพาะกับภาษาอื่น ๆ
— ล้านล้าน

@Hasturkun โดยไม่มีข้อ จำกัด ปุ่มxmessage Hello Worldวิธีแก้ปัญหาของคุณมีเพียง 20 ตัวอักษรเท่านั้น แต่จากนั้น Windows cmdจะเอาชนะคุณได้ด้วยmsg * Hello Worldอักขระเพียง 17 ตัว ดังนั้นขอขอบคุณสำหรับข้อ จำกัด :)
— จัดการ


5

Python 2/3, 54 ตัวอักษร

ใช้ประโยชน์จาก t ใน tkinter เพื่อให้ทำงานบน Python 2

__import__("tkinter").Label(text="Hello World").pack()

เมื่อฉันลองแล้วฉันจะได้รับ: AttributeError: Label instance has no attribute 'show'. อย่างไรก็ตาม__import__("Tkinter").Label(text="Hello World").pack()ให้ผลตามที่ต้องการ
— plannapus

@plannapus ที่จริงแล้วฉันได้คัดลอกเวอร์ชันก่อนหน้านี้ที่มีข้อผิดพลาดไม่ใช่อันที่ถูกต้อง ขอบคุณ
— Ramchandra Apte

4

Windows รุ่นที่ 23

@pause|echo Hello World
  • เปิดหน้าต่างสีดำที่แสดงHello Worldไม่มีอะไรอื่น
  • ตอนนี้หน้าต่างยังคงเปิดอยู่
  • There are no buttons in the window.

2
Requirement is: create a window not force window manager to create a window
— F. Hauri

4
@F.Hauri Ok, I'll look how to write a window manager. Until someone post that, consider all posts as violation of your requirement.
— Johannes Kuhn

1
As the op states, it doesn't matter how the window looks. If it is a plot window or a shell window, who cares?
— Johannes Kuhn

5
I absolutely agree :) now this is absolutely acceptable because it is a window and it does say hello world :) well done I love it
— Quillion

1
@JohannesKuhn PowerShell can still beat it. Edit coming up.
— Iszi


4

ExtJS (Javascript) 44

new Ext.Window({html:'Hello world',}).show()




3

AutoIt v3, 32

ToolTip("Hello World")
Sleep(9^9)

Wouldn't MsgBox(0,"","Hello World") be shorter? It's 26 characters.
— Mr. Llama

The requirements are to have no Ok or Cancel buttons within the window. The code you suggest has an OK button. :(
— Chris

Ah balls, I missed that requirement.
— Mr. Llama

3

HTML, 11

Hello World

Screenshot:

HTML Hello World

I guess this shouldn't count, but I think it would be interesting to see such an answer here.


3
I agree it shouldn't count. The same can be accomplished by loading a simple TXT file in the browser.
— Iszi

Your count is off, that's 20 characters.
— jmoreno

2
@Iszi without HTML tags, this is really just getting rendered as a plain text file. I would argue that you can't even call it an html submission without <html> </html>
— Cruncher

@Cruncher Google Chrome actually adds an HTML skeleton including a <pre> which contains the file's contents (you can use Chrome dev tools for verifying this behavior).
— ComFreek

1
@Cruncher Well, maybe if you're using IE6, but in any modern browser, you can omit the <html> tags, as well as the <body> and <head> tags, and the browser will automatically fill out the "skeleton". For example, try <div style="background:#ff0">Hello</div> in a modern browser, and it will universally render "hello" with a yellow background.
— Braden Best

3

PowerShell: 162 124 114 or 20


The Long Way Around

($t=($a='New-Object Windows.Forms')+".Label"|iex).Text='Hello World';($x=iex $a".Form").Controls.Add($t);$x.Show()

Since PowerShell really doesn't have any built-in GUI functionality, I'm having a hard time coming up with anything shorter than this which I feel really fits the original spirit of the challenge. (Or, at least, fits within the parameters several of us have assumed were implied.)

enter image description here

Changes from original:

  • Removed window size definition. Apparently, it's optional and the default is plenty large enough.
  • Incorporated changes provided by SpellingD in comments. Note: The window which spawns will hang - you'll need to kill PowerShell via Task Manager.

Alternative 20-Character Approach

Removing some assumed-implied requirements, we can also meet this challenge a-la Johannes Kuhn with this:

'Hello World';for(){}

Save as a .ps1 file. Make sure the system's ExecutionPolicy allows unsigned scripts. Right-click and select "Run with PowerShell".

enter image description here


Show instead of ShowDialog should do it, right?
— It'sNotALie.

Show() does work, but doesn't let you close the window. Which isn't a requirement!
— SpellingD

My edit to golf this was rejected, and my code isn't sufficiently different enough to warrant making a new answer, so here's how you could golf this to 114, I guess. ($t=($a='New-Object Windows.Forms')+".Label"|iex).Text='Hello World';($x=iex $a".Form").Controls.Add($t);$x.Show()
— SpellingD

@SpellingD Thanks. I've incorporated your changes to the "true" solution, and also added a "cheap method" which currently beats all contenders. (Except, arguably, HQ9+ of course.)
— Iszi

3

Factor, 36 code + 23 imports = 59

USING: ui ui.gadgets ; "Hello World" <label> "" open-window

When this is run inside the listener, the imports will be brought in automatically. You only need them to deploy a standalone executable.



2

Groovy, 68 27

Using console.

print"Hello World";for(;;);

Using Frame.

new java.awt.Frame(){{add new java.awt.Label("Hello World")}}.show()

Inspired by @swilliams Java answer.


2

Processing, 37 chars:

void draw(){text("Hello World",0,9);}

Various things used to reduce strokes:

  • Sketch window is spawned by default; no need to manually create it
  • Using draw is shorter than setup (although the text is then redrawn each frame)
  • Uses default size, background, fill, font, and font size
  • You don't actually need all 10 pixels height for the text


2

Ghostscript 50

0 0 moveto/Courier 20 selectfont(Hello World)show

Could make it 49 by using a 9-point font, but it's a little hard to read.

Can make a smaller window by invoking gs with a geometry argument for an additional 8 chars.

gs -g200x30 hello.ps

2

C#, 72

class P{static int Main(){System.Console.Write("hello world");for(;;);}}

Based on the answer by @Noctis. I would have suggested it as a comment if I had enough Rep.


2

Delphi - 73 62

uses Dialogs;begin MessageDlg('Hello World',mtCustom,[],0)end.

Edit after @manatwork and @Gareth 's suggestions. Which actually brings me to a character count of 62.


How you get that character count? The code you posted has 77 characters and the minimum to which it can me reduced is 64: uses Dialogs;begin MessageDlg('Hello World',mtCustom,[],0)end.
— manatwork

1
You need to count newlines as part of your character count. That's why many answers on this site are all on one line.
— Gareth

Ah, I didn't know that. I'll edit my answer.
— R-D


2

Ti84-Basic, 25

ClrHome
Disp "HELLO WORLD

Arduino, 27

Serial.print("Hello World")

Place this in void setup()

Game Maker Language, 40

show_message_ext("Hello World","","","")

I'm pretty sure this is the shortest way without adding any extension packages.


If you would accept an OK button, show_message("Hello World") is 27 characters.
— Timtech

Extremely necroing this one, but I have 2 (slight) remarks about your Ti84-Basic one. 1: couldn't you drop the final "? 2: Should you count it in bytes, we have a clear winner here ;)
— ɐɔıʇǝɥʇuʎs

@Synthetica Yeah. Forgot that :)
— Timtech

Your TI-BASIC answer does not open a window, and it outputs capital rather than lowercase letters.
— lirtosiast
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.