“你好,世界!”(警察的话)


16

这是警察的话题。强盗的线程是这里

您的挑战是编写一个程序或函数,该程序或函数使用特定的输入来打印确切的字符串Hello, World!和换行符。大写字母,空格和标点符号必须准确。

输入可以通过标准输入,文件或命令行/函数自变量获取。输出可以通过返回值,写入文件或标准输出来给出。

您的程序必须Hello, World!至少打印一次输入。当您的程序输入错误时(即,不能打印的输入)Hello, World!),它可以执行您喜欢的任何操作-崩溃,打印随机废话,调用Chuck Norris等。

您不得使用哈希算法或任何类似的方法来遮盖所需的输入。

提交最好在TIO上可运行且可破解。允许在TIO上无法运行或破解的提交,但请提供下载/运行它们的说明。

一个星期后,这项挑战将在以后的警察提交中关闭。获胜者是发布它一周后未破解的最短代码(“它”是代码,而不是挑战)。获奖者将在两周后被接受。

自发布以来已过了一周,请标记您的答案为安全并显示输入(以表示> ! spoiler quote)。如果强盗破坏了您的提交(在本周结束之前),请将其标记为已破坏,并显示停止输入(中的> ! spoiler quote)。

寻找完整的作品?

fetch("https://api.stackexchange.com/2.2/questions/137742/answers?order=desc&sort=activity&site=codegolf&filter=!.Fjs-H6J36vlFcdkRGfButLhYEngU&key=kAc8QIHB*IqJDUFcjEF1KA((&pagesize=100").then(x=>x.json()).then(data=>{var res = data.items.filter(i=>!i.body_markdown.toLowerCase().includes("cracked")).map(x=>{const matched = /^ ?##? ?(?:(?:(?:\[|<a href ?= ?".*?">)([^\]]+)(?:\]|<\/a>)(?:[\(\[][a-z0-9/:\.]+[\]\)])?)|([^, ]+)).*[^\d](\d+) ?\[?(?:(?:byte|block|codel)s?)(?:\](?:\(.+\))?)? ?(?:\(?(?!no[nt][ -]competing)\)?)?/gim.exec(x.body_markdown);if(!matched){return;}return {link: x.link, lang: matched[1] || matched[2], owner: x.owner}}).filter(Boolean).forEach(ans=>{var tr = document.createElement("tr");var add = (lang, link)=>{var td = document.createElement("td");var a = document.createElement("a");a.innerHTML = lang;a.href = link;td.appendChild(a);tr.appendChild(td);};add(ans.lang, ans.link);add(ans.owner.display_name, ans.owner.link);document.querySelector("tbody").appendChild(tr);});});
<html><body><h1>Uncracked Submissions</h1><table><thead><tr><th>Language</th><th>Author</th></tr></thead><tbody></tbody></table></body></html>



13
就像我在沙盒中说的那样,我觉得这是暂停问题的重复,因为那里的任何答案都可以发布在这里,但可以使用代码for和infinite loop替换为代码来打印问候世界。我不会投票,因为我会锤子,但我很确信这是骗子。
FryAmTheEggman '17

5
显然sha3属于该类别,但是在其他方面您会画线吗?我的意思是,mod 1e3它也是一个哈希函数,我什至会争论很多,提交的都是哈希函数,因为这个挑战基本上就是这样。
瑕疵

1
根据我在过去一天中看到的答案,似乎没有什么可以说服我这不是重复的。我现在要结束警察挑战,如果社区不同意可以重新开放,并且如果社区同意,他们也可以关闭强盗线程。
FryAmTheEggman '17

1
@Dopapp这已经在这里讨论(删除了一些评论)并在聊天中进行了讨论。答案无法复制粘贴,也很难移植到该挑战中,因此它们不是重复的。
MD XF

Answers:


3

Python 3中,191个 186字节(SAFE!)

与我先前的答案相同,但没有noob eval语句,因此实际上必须解决我创建的问题。

import sys
from numpy import *
e=enumerate
c='Hello, World!'
print(''.join([c[int(sum([c*cos(n*i)for i,c in e(fromiter(sys.argv[1:],float))])+.01)]for n in[2*i+ord(n)for i,n in e(c)]]))

现在使用正确的参数执行它,例如 python3 hw.py 1 2 3


编辑:以前的版本在“ Hello,World!”中缺少逗号,并且我还意识到它具有不必要的枚举,现在已经消失了。


编辑2:只是为了好玩,这是几乎相同代码的Pyth版本(47字节):

KEJ"Hello, World!"jkm@J.Rs.e*b.t*dk1K0.e+*2kCbJ

输入来自 stdin并以参数列表的形式出现,例如[1,2,3]

我认为发布单独的答案毫无意义,因为如果您破解了Pthyon3版本,那么即使您不了解Pyth,您也会破解Pyth版本。


回答:

python3 hw.py 10.72800138 13.23008796 19.30176276 16.13233012 18.10716041 0.98306644 8.18257475 19.20292132 10.99316856 -2.15745591 6.01351144 5.45443094 10.41260889

代码说明:

''.join()从字符串的字符数组中创建hello world字符串"Hello, World!"。这些指标成立时,难题就解决了[0,1,2,3,4,5,6,7,8,9,10,11,12]。每个索引都是根据输入和命令行上给定的常数计算得出的。输入是一系列硬编码的:[2*i+ord(c) for i,c in enumerate('Hello, World!')]。与输入,常量和输出(指标)相关的功能是这样的:sum([c*cos(x*i) for i,c in enumerate(CONSTANTS)])。这是一个经典的建模问题,您试图在其中将数据拟合到模型中。

在python中到达解决方案:

from scipy import optimize
x = [2*i+ord(c) for i,c in eumerate('Hello, World!')]
y = [0,1,2,3,4,5,6,7,8,9,10,11,12].
# make your function: 13 terms means we can achieve 13 exact outputs
def f(x,a,b,c,d,e,f,g,h,i,j,k,l,m):
    return sum([c*cos(x*i) for i,c in enumerate([a,b,c,d,e,f,g,h,i,j,k,l,m])])
# curve fit
ans,_ = optimize.curve_fit(f,x,y)
# check answer
[round(f(a,*ans),0) for a in x] # should be 0-12


2
万一您不知道,可以literal_eval()ast模块中使用它来安全地计算表达式,以免print(代码注入问题起作用。在这里可能不相关,但是我只是想提到它。
硕果累累

2
您确定可以打印Hello, World!吗?尚未破解,但看起来好像缺少逗号(
联接

哦,您是对的,它缺少逗号。我将纠正它。
rexroni

@ Challenger5谢谢,我不知道。
rexroni

12

TeX-38个字节已破解(ish)

这是值得一试的,因为我无法想象网站上任何编写短代码的人都会知道TeX:

\read16to\x\message{Hello, World!}\bye

要运行它,您应该拥有某种允许交互模式的TeX。将其保存到文件,然后在其上运行TeX(或pdfTeX,XeTeX等)。

编辑:我目前正在考虑这半裂。预期的解决方案使用stdin的输入,但是从调用程序的方式进行的Texnically输入是有效的。如果有人获得了预期的方法,我将添加更多不完整的TeX答案。

这是预期的解决方案:

^ C Ia-第一个键是control-c,这将导致错误。然后,按I(大写i)输入命令。然后,您输入一个(或其他要排版的内容)。通常,打印到stdout的消息后会跟一个空格,然后是')'。键入内容时,它将导致在消息后输出字体信息。这意味着将插入换行符,然后再移动')'。

这可能是不明智的,但仍应在游戏规则之内。


欢迎来到PPCG。好第一个答案
ЕвгенийНовиков

使用tex \ Hello, world!\bye(23字节)是否足够?
Werner

@Werner允许用户输入?
一位金级男子

这真的意味着要破解吗?:o
Felix Palmen '17

3
texnically哦,天哪。
MD XF

7

> <>,538字节,被rexroni破解

v
\">/v>v\v</>"
/!?lp%*2di%*2di
a
v   "        "       "
   "l"      "o"  /  "e"
v   "        "     " "
      "   /       "l"/
v    "!"           "
 //   " " "      \
v     \"d"o"   " "    "
      " " "   "o"r"  "!"
v"   "H"       " "    "
"l"   ""
""    "r" "         "
    \  " "l"       "d"  "
v   "     "      "  "  "H"
   "e"         /","     "
v " " "     "  " "
 "e" "W"  /"d""l"
v " " "     "  "      "
   "H"               "!"
v   "                 "
                        v
>>"Hello world?"       >o<
                        ^

在线尝试,或者您可能要使用鱼游乐场

前三行从STDIN中读取一个字符串,并使用其字符代码mod 26作为坐标将字符“ >/v>v\v</>”放入下面的迷宫中。预期的解决方案是仅由字母A–Z组成的20个字符的字符串(尽管您当然可以使用所需的任何东西)。

解:

预期的输入是OCEANICWHITETIPSHARK(这是一条鱼!)。穿过迷宫的路径如下所示:

v
\">/v>v\v</>"
/!?lp%*2di%*2di
a                |  |
v   "        "   |  |"
| v"l"______"o"__/  "e"
v | "        "     " "
| |   "   /       "l"/
v |  "!"           "|
|//   " " "    v_\  |
v|    \"d"o"   " "  | "
||    " " "   "o"r" |"!"
v"   "H"       " "  | "
"l"___""_______ _/__/_____
""    "r" "    | |  "
|>__\  " "l"   | | "d"  "
v   "     "    | "  "  "H"
|  "e"v________/"," |   "
v " " "     "  " "  |
|"e"|"W"  /"d""l"|  |
v " " "     "  " |  | "
<  "H">__________ __\"!"__
v   "            |  | "
    >____________ __ ___v
>>"Hello world?" |  |  >o<
                 |  |   ^


破解! 永远带我
rexroni

3
嘿,我怀疑答案可能只是一个字,但我没有进行任何尝试。我的印象更加深刻。
rexroni

6

八度,59字节,破解

这在Octave 4.2.0中有效。我不能保证与所有版本都兼容。

i=input('');printf('%c',i*~all(isequal(i,'Hello, World!')))

注意:这不会打印任何尾随空格或换行符。看起来是这样的:

enter image description here

它基本上说:“打印输入字符串,除非输入是'Hello,World!',在这种情况下,它应该不打印任何内容(或空字符)。


我不确定%c字符串还是char ...也许您在隐藏什么?这也*~让我有些怀疑...
Egg the Outgolfer

我不确定,但破解了吗?
ბიმო

@BruceForte在输出末尾输出一个空字节,我不确定这是否有效... link
MD XF

1
我很确定预期的解决方案就是这种事情。
乔纳森·艾伦

1
@BruceForte,不。没有\n。我以为问题文本说“ 可选的尾随换行符 ”。
Stewie Griffin


5

MATL,6个字节。开裂

tsZp?x

在线尝试!


破解,但如果这不是预期的解决方案,则感觉有点像作弊。
丹尼斯,

@Dennis预期的解决方案是['Hello,' 1 'World!']。为什么要作弊?:-(的doc / help D表示,大多数32位以下的输入字符都由空格代替
Luis Mendo

我的意思是作弊,将LF换行符转换为CR + LF换行符。
丹尼斯

@丹尼斯啊,我明白了。好吧,我认为这也是完全正确的
Luis Mendo

5

爆炸,23字节,破解

@_?&4_-j>5&f^~c>&6\|4>7

更多的来临,这仅仅是开始> :)

在线尝试!

资源管理器说明

该程序有四个浏览器。我不能完全确定wait(>)是否正常运行。

@_?

读取用户输入(?),将磁带(@)向下延伸(_)。

&4_-j>5

对于4个滴答声(4),请&向下(_)修改磁带(5),然后减去(-)19(j),将其跳动5 ()。

&f^~c>

对于16个滴答声(f),请以波浪形(&)向上(^)修改磁带()~,交替更改无影响,+ 13,无影响和-13(c)。

&6\|4>7

对于6个滴答声(6),请&在两个方向(|)上修改色带(),每次将()减小\4(4),然后再跳跃7(7)。减少意味着它第一次减去4,第二次减去8,依此类推。


3
破裂,但随时可以进行以下解释:)
乔纳森·艾伦

@JonathanAllan添加了解释,对不起,我花了这么长时间
Stephen

5

的JavaScript(ES6),173个 169 163 150 151 148 143字节(裂纹)

让我们拥有完全不同的东西…… 完全邪恶的东西。

const e=eval,p=''.split,c=''.slice,v=[].every,f=s=>(t=c.call(s),typeof s=='string'&&t.length<81&&v.call(p.call(t,`\n`),l=>l.length<3)&&e(t)(t))

用法: f(something) // returns 'Hello, World!'

在线尝试!




Nice! That's a real crack.
Voile

This was really tough to crack. Good job!
DanTheMan

It's directly taken from one of the puzzles I've created on elsewhere :) (I'll let people figure out where I posted the original puzzle.)
Voile

4

C# (.NET Core), 130 152 bytes, CRACKED

+22 bytes, I forgot about trailing newline... Program works the same as before, the newline is added to any output.

a=>a.Distinct().Select((x,y)=>a.Reverse().Skip(y).First()*x%255).Take(a.First()-33).Concat(new int[]{10}).Select(x=>(char)x).ToArray()

Try it online!

Byte count also includes

using System.Linq;

For a start I went for something not too crazy. It can has multiple answers.

The "official" crack:

. !$0%>5&8'#?)S*TuE[MRX`+9



4

tcc, 89 bytes, cracked by Dennis

#!/usr/bin/tcc -run
#include <stdio.h>

int main()
{
    puts("\n");
}
#include "/dev/stdin"

This is particularly evil due to tcc's dynamic resolution. Lots of functions are predeclared and trying to overwrite them simply doesn't work.


Could you create a working TIO link for people to play with? (this is no doubt incomplete - maybe it needs compiler flags or something, I have no idea) TBH I don't even know how this is meant to take input...?
Jonathan Allan

Tio's tcc is not going to work. It doesn't get that this must be used as tcc -run rather than a separate compile and link phase.
Joshua

Maybe it's runnable via a shell through there then, bash is available (I know very little regarding either tcc or bash though). Otherwise I think you should give some detailed instructions to get people going (unless my personal lack of knowledge is the issue here - as I said I don't even know how your code gets any input, all I see is a puts and I thought that outputs.)
Jonathan Allan

Almost have a crack but I'm on mobile and mprotect is being a butt.
MD XF



4

brainfuck, 7 bytes cracked

,+[.,+]

Try it online!

Good luck. (doesn't work with every BF interpreter


Does your input work with any BF interpreter, including ones with different tape lengths? Does your input work locally, and not just on TIO?
Stephen

@StepHen any length of type afaik
Christopher


1
Does your intended solution work on TIO?
totallyhuman

@totallyhuman thanks, edited the comment so it looks pro. I don't know how to put non-printable input on TIO. I passed input on stdin from a C program with a single printf statement.
rexroni

3

JavaScript (ES6), 102 bytes (Cracked)

The previous version has a massive cheese. Let's try this again...

f=s=>{let r='',i=0;while(i<13)r+=!s[i][0]||s[i]=='Hello, World!'[i]||s[i++];return r};Object.freeze(f)

Try it online!

Author solution:

new Proxy({v:Array(13).fill(0)},{get:(o,p)=>['a','','Hello, World!'[p]][o.v[p]++]})

Usage:

var p=new Proxy({v:Array(13).fill(0)},{get:(o,p)=>['a','','Hello, World!'[p]][o.v[p]++]}) console.log(f(p))



3

Cubically, 159 bytes (Cracked)

+53$!7@6:2/1+551$?7@6:5+52$!7@66:3/1+552$?7@6:5+3/1+4$!7@6:5/1+3$?7@6:5+1/1+54$!7@6:3/1+552$?7@6:5+1/1+552$?7@6:5+52$!7@6:1/1+551$?7@6:5+1/1+3$!7@6:1/1+1$(@6)7

This will be pretty easy to those who are comfortable with Cubically. Try it online!


1
Is anybody comfortable with Cubically? :P
totallyhuman

@totallyhuman The language is actually pretty simple once you get used to it, and it's fun to use!
TehPers

@totallyhuman It looks like there aren't any turning instructions, so this seems like mostly just math with multiples of 9. Very, very convoluted math.
Robert Fraser

Cracked? I think I got the intended input, but it doesn't quite work, but I'm pretty sure it fails due to an interpreter bug. See my explanation in crack post. If I am right, then you were right that it was actually darn easy : )
rexroni

3

6502 machine code (C64), 51 53 bytes (Cracked)

00 C0                     .WORD $C000     ; load address
20 FD AE                  JSR $AEFD
20 EB B7                  JSR $B7EB
8A                        TXA
0A                        ASL A
45 14                     EOR $14
8D 21 C0                  STA $C021
45 15                     EOR $15
85 15                     STA $15
49 E5                     EOR #$E5
85 14                     STA $14
8E 18 D0                  STX $D018
A0 00                     LDY #$00
B1 14                     LDA ($14),Y
20 D2 FF                  JSR $FFD2
C8                        INY
C0 0E                     CPY #$0E
D0 F6                     BNE *-8
60                        RTS
C8 45 4C 4C 4F 2C 20 D7   .BYTE "Hello, W"
4F 52 4C 44 21 0D         .BYTE "orld!", $D

Online demo

Usage: SYS49152,[x],[n], where x is a 16bit unsigned integer and n is an 8bit unsigned integer.

Input is 52768 and 23 (SYS49152,52768,23)

The second parameter is directly written to D018, a control register of the VIC-II graphics chip. Using a suitable reference, you can deduce what to write there for setting lowercase mode without changing other modes and the address of the screen memory: $17, or decimal 23. With that, you can follow the arithmetics in the code, so the first parameter ends up with the correct string address in $14/$15 (little-endian). A more in-depth explanation can be found in the crack.

Screenshot

Invoked with wrong values, a crash is very likely.

For cracking, you might want to run it in a local installation of vice, so here's a BASIC loader to paste into the emulator (RUN it to place the program at $C000):

0fOa=49152to49202:rEb:pOa,b:nE
1dA32,253,174,32,235,183,138,10,69,20,141,33,192,69,21,133,21,73,229,133,20,142
2dA24,208,160,0,177,20,32,210,255,200,192,255,208,246,96,200,69,76,76,79,44,32
3dA215,79,82,76,68,33,13

Update: Added two bytes for the load address to make this an executable C64 PRG file in response to the discussion on meta


Are you sure you need to call the comma checking function at the beginning? I'm under the impression that b7eb does that check, too.
A Gold Man

b7eb calls aefd, but only after calling ad8a (parse number as float (!)(wtf)(MS)) and b7f7 (convert that float to 16bit unsigned int) -- so I have to first call aefd myself for consuming the first comma.
Felix Palmen

Cracked! Sweet sweet vengeance!
A Gold Man

@AGoldMan finally edited my post. Again, well done! Maybe I can come up with another C64 code that's a bit harder to crack (without being unfair), not sure yet :)
Felix Palmen

2

Python 2, 63 bytes, cracked

Just to get the ball rolling...

#coding:rot13
cevag vachg()==h'Hello, World!'naq'Hello, World!'

Try it online!


1
Is it generally accepted for the OP to crack submissions?
MD XF


3
That's interesting... I hadn't realized any "normal" language supports coding in ROT13 o_o
ETHproductions

13
@Arnauld And you're claiming PHP is a normal language?
NoOneIsHere

1
@NoOneIsHere Er... no. My bad. :-P
Arnauld



2

Jelly, 11 bytes (cracked)

sLƽ$Xṙ5O½Ọ

Try it online!

Intended input:

〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ



@HyperNeutrino Heh that was sneaky, given it lived for over half an hour. ;)
Erik the Outgolfer

Heh that's cuz I only saw it 10 minutes before seeing it ;P
HyperNeutrino



2

Python3, 192 bytes Cracked I guess

from sys import *
from numpy import *
e=enumerate
c='Hello World!'
w=eval(argv[1])
x=[ord(n)+2*i for i,n in e(c)]
print(''.join([c[int(sum([c*cos(n*i)for i,c in e(w)])+.01)]for i,n in e(x)]))

The text it reads is the first program argument: python3 hw.py '[1,2,3]'

Don't be lame and try to put a print("Hello World!") statement as the argument... it prints an error afterwards anyways (at least on the command line), so I don't think that should count. (Edit: somebody did exactly that)


4
Cracked. Lame crack, but unrestricted eval must be punished =)
Sisyphus


2

Lua 5.1, 44 bytes (Cracked)

s=...loadstring(#s>4+#s:gsub("%l","")or s)()

Note that Lua 5.1 is a different language than Lua 5.2 or Lua 5.3. "Try it online" doesn't have Lua 5.1. You can check your Lua version by running print(_VERSION). (There should be a solution in any implementation that uses PUC-Rio's Lua 5.1 core.)

As a test harness, you can use something like this:

function test(...)s=...loadstring(#s>4+#s:gsub("%l","")or s)()end

test[[
This is my input!
It can have multiple lines!
]]

Test harness on repl.it


2

C (GCC on TIO), 84 bytes golfed (Cracked)

#include<stdio.h>
main(x){scanf("%d",&x);printf("%2$s","Hello, World!\n",(void*)x);}

Here's an ungolfed version that works too:

#include <stdio.h>
int main(void)
{
    int x;
    scanf("%d",&x);

    printf("%2$s","Hello, World!\n",(void*)x);
}

2

JavaScript (ES6), 92 bytes (Cracked)

This simple string copy function seems to be really resisting you to copy any strings resembling Hello, World!...

f=s=>{let r='',i=0;while(i<13)r+=s[i]=='Hello, World!'[i]||s[i++];return r};Object.freeze(f)

Try it online!





2

JavaScript (ES6) 107 Bytes [Thanks Евгений Новиков] (Cracked)

i=r=>{for(e="",n=0;r.length>n;o=r.charCodeAt(++n),e+=String.fromCharCode(((3^o^19)<<1^15^13)<<1));return e}

Call on the i function using a string.

The console.log... is for testing purposes.

Try It Online!


Welcome to PPCG! You can save 8 bytes: (1) remove var, (2) () from one arrow-function argument, (3) replace return to eval("") (4) delete ; at the end. 110 bytes solution: pastebin.com/qwdm7fT7 Good luck
Евгений Новиков

Finally got 50 rep, so: Cracked
Voile
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.