那不是我的X,它的Y也太Z


17

这项挑战的灵感来自Fiona Watt和Rachel Wells的一系列幼儿读物,最近我和女儿一起很喜欢。

在每本书中,鼠标(插图,但不是本书的一部分)都抱怨说,连续出现的5种相同类型的事物不是其事物。然后,它通过声明事物的某些组成部分不具有其期望的属性来对此进行支持。

在第六次询问时,鼠标找到了它的东西并感到高兴,因为它具有预期的属性。

这是一个典型示例的文本:

That's not my bunny, its tail is too fluffy.
That's not my bunny, its paws are too rough.
That's not my bunny, its tail is too woolly.
That's not my bunny, its eyes are too shiny.
That's not my bunny, its nose is too wrinkled.
That's my bunny! Its ears are so soft.

现在,大多数编程人员会意识到这是一种产生某些文本的非常算法的方法。因为这是一个清晰的过程,所以我们应该能够通过编写一些代码来重现这一过程。

让我们从三个单词集合开始:

things = ["dinosaur", "lamb", "princess", "reindeer", "train"]
parts = ["back", "bells", "body", "bows", "crown", "dress", "ears",
  "engine", "fan", "flippers", "funnel", "hooves", "horns", "neck",
  "nose", "roof", "sash", "side", "spines", "spots", "tail", "teeth",
  "tiara", "wheels", "windows"]
properties = ["bumpy", "fluffy", "furry", "fuzzy", "glittery", "glossy",
  "hairy", "red", "rough", "rusty", "shiny", "silky", "slippery", 
  "soft", "sparkly", "squashy", "thick", "velvety", "woolly"]
  • 首先,我们决定要描述哪种类型的东西。
  • 然后5次,我们将生成一行“那不是我的东西,它的[部分]太[属性]。
  • 最后,我们生成一行“那是我的(东西)!它的(部分)是如此[属性]!

挑战

  • 生成“那不是我的……”故事的文本。
  • 它不能始终如一地复制相同的文本。
  • 这是代码高尔夫球,因此请尝试以最少的字节数进行操作。
  • 您可以使用任何语言。
  • 空格无关紧要,但是行之间必须有换行符。
  • 源词列表不是您的答案的一部分(在TIO中,它们可以添加到标题中)。
  • 您可以重命名源词列表。
  • 输出可以输出到终端,也可以将文本生成到对象中。
  • 请提供在线翻译的链接。
  • 忽略复数,“它的角是”就可以了。
  • 这没有必要。如果您的公主的漏斗太蓬松,那就说吧。

样本输出:

That's not my train, its engine is too rusty.
That's not my train, its hooves is too thick.
That's not my train, its sash is too fuzzy.
That's not my train, its tail is too velvety.
That's not my train, its horns is too glittery.
That's my train! Its hooves is so hairy.

打高尔夫球快乐!


2
@Shaggy第一个示例是其中一本书的实际文本。对于这个挑战,这不是一个有效的答案。我说过要忽略复数形式,以便稍微简化一下挑战。该示例基本上是背景信息。
AJFaraday


10
您声明“这没有必要。”,这是否会延伸到接近收缩的状态?(即“那不是我的兔子,它的眼睛太闪亮了。。。那是我的兔子!它的眼睛是如此的闪闪发光。”可以接受作为可能的输出吗?)-我猜是这样,只是以为我会检查一下。
乔纳森·艾伦,

13
是不是“它不能始终如一地复制相同的文本”和kolmogorov-complexity是不兼容的?
约瑟夫·西布尔-恢复莫妮卡

2
@ChrisH这是我的分类错误。尽管两者都被归类为Glires,但这是我今天学到的东西。
AJFaraday

Answers:


1

05AB1E,63 个字节

ΩU6F€Ω`XN5Qi“€Š's€¯ ÿ!€ç ÿ€ˆ€Ê ÿ.“ë“€Š's€–€¯ ÿ,€ç ÿ€ˆ…« ÿ.“}.ª,

在线尝试。

68 个字节的版本,不输出重复的部分或属性:

ΩUε.r6£}øεXª`N5Qi“€Š's€¯ ÿ!€ç ÿ€ˆ€Ê ÿ.“ë“€Š's€–€¯ ÿ,€ç ÿ€ˆ…« ÿ.“}.ª,

在线尝试。

这两个程序都假定事物列表是第一个输入,而包含零件列表和属性列表的列表是第二个输入。

说明:

Ω            # Pop and push a random element of the things-list
 U           # Pop and store it in variable `X`
  6F         # Loop 6 times:
    €Ω       #  Get a random element from both the parts and properties list
      `      #  Push them to the stack
       X     #  And also push variable `X`
             #  (the order on the stack is now: property, part, thing)
    N5Qi     #  If it's the last iteration:
        “€Š's€¯ ÿ!€ç ÿ€ˆ€Ê ÿ.“ 
            '#   Push dictionary string "that's my ÿ! its ÿ is so ÿ."
       ë     #  Else:
        “€Š's€–€¯ ÿ,€ç ÿ€ˆ…« ÿ.“
            '#   Push dictionary string "that's not my ÿ, its ÿ is too ÿ."
             #  (where the `ÿ` are automatically replaced with the words on the stack)
       }.ª   #  After the if-else: sentence-capitalize the strings
             #  (so the "That's " as well as the "! Its")
          ,  #  And output it with trailing newline


ΩU           # Pop and store a random thing in variable `X`
  ε          # Map the list of lists of parts/properties to:
   .r        #  Shuffle the list
     6£      #  And leave the first six elements
           # After the map: zip/transpose to create pairs of part & property
    ε        # Foreach over the pairs:
     `XN5Qi“€Š's€¯ ÿ!€ç ÿ€ˆ€Ê ÿ.“ë“€Š's€–€¯ ÿ,€ç ÿ€ˆ…« ÿ.“}.ª,
             #  And the rest of the code is the same as above

请参阅我的05AB1E技巧(如何使用字典?部分),以了解为什么“€Š's€¯ ÿ!€ç ÿ€ˆ€Ê ÿ.“"that's my ÿ! its ÿ is so ÿ."“€Š's€–€¯ ÿ,€ç ÿ€ˆ…« ÿ.“"that's not my ÿ, its ÿ is too ÿ."


10

Python 3,149字节

lambda a,*l:shuffle(a)or["That's "+s%(a[0],*map(choice,l))for s in["not my %s, its %s is too %s."]*5+["my %s! Its %s is so %s."]]
from random import*

在线尝试!

-9字节归功于movatica


干得好!更短的元组语法:149个字节
movatica,

1
@movatica哦,太好了。谢谢!
HyperNeutrino

“那不是我的驯鹿,它的耳朵太颠簸了。” -需要在is / are之间进行切换。
约翰·亨特

1
@JohnHunt规则说忽略复数。
HyperNeutrino

我的错。这很令人印象深刻
约翰·亨特

8

木炭,72字节

≔‽θθF⁵«That's not my θ, its ‽η is too ‽ζ.⸿»That's my θ! Its ‽η is so ‽ζ.

在线尝试!链接是详细版本的代码。期望的东西,部件和属性的阵列是在变量θη并且ζ,这是最容易通过在输入而不是头为他们提供布置。说明:

≔‽θθ

选择一个随机的东西。

F⁵«That's not my θ, its ‽η is too ‽ζ.⸿»

打印五个否定句子。

That's my θ! Its ‽η is so ‽ζ.

打印肯定的句子。


6

Japt v2.0a0,73 -R个字节

ö
6Æ`Tt's {`not `pT=Y<5}my {+`!,`gT} {73dT*H}ts {Vö}  {`tÑ?`ë2!T} {Wö}.

注意到三个列表为UVW。无论如何,这些都是默认的输入变量,因此只需将三个列表放在输入部分。

尝试一下

ö                         Saves the random object in variable U
6Æ                        Range [0..6), and map each to the following string
`That's                   The string "That's " plus
{`not `pT=Y<5}            "not " if the index is less than 5 (and store that in variable T), else ""
my                        Literal "my " plus
{+`!,`gT}                 U plus ',' if T, else '!'
{73dT*H}ts                "its " if T, else "Its "
{Vö}                      Random item from V
is                         
{`tsooo`ë2!T}             "too" if T, else "so"
{Wö}.                     Random item from V, plus a period

“ too / so”的技巧非常好:)
Shaggy

6

PowerShell 147字节

该主程序不会在运行中重复任何部分或属性,并且具有合理的随机性。

$t=$l|Random
$a=$a|Random -c 6
$r=$r|Random -c 6
0..4|%{"That's not my $t, its $($a[$_]) is too "+$r[$_]}
"That's my $t! Its $($a[5]) is so "+$r[5]

在线尝试!

get-random那么多次要花很多字符!但是,除非您愿意重复零件和属性,否则我看不到在Powershell中进一步缩小此范围的方法。除非您将前3条管道移到标题中3条分配线的末尾。有类似的东西

# Header
$l = ("dinosaur", "lamb", "princess", "reindeer", "train")|Get-Random
$a = ("back", "bells", "body", "bows", "crown", "dress", "ears",
  "engine", "fan", "flippers", "funnel", "hooves", "horns", "neck",
  "nose", "roof", "sash", "side", "spines", "spots", "tail", "teeth",
  "tiara", "wheels", "windows")|sort{Get-Random}
$r = ("bumpy", "fluffy", "furry", "fuzzy", "glittery", "glossy",
  "hairy", "red", "rough", "rusty", "shiny", "silky", "slippery", 
  "soft", "sparkly", "squashy", "thick", "velvety", "woolly")|sort{Get-Random}

# Main
(1..5)|%{echo("That's not my $t, its "+$a[$_]+" is too "+$r[$_])}
"That's my $t! Its "+$a[6]+" is so "+$r[6]

但这似乎是在作弊,但仍然没有击败尼尔。

编辑:感谢Matt的提示,也感谢AdmBorkBork充实了它们,删除了3组get-文本将其减少到159个字节,然后从Adm进行了更多的修改后将其减少到147个字节。我在考虑的代码允许重复和应用相同的高尔夫球技巧后,矛盾的陈述为144个字符

function n{(random 18)+1}
$t=$l[(n)%5]
0..4|%{"That's not my $t, its $($a[(n)]) is too "+$r[(n)]}
"That's my $t! Its $($a[$(n)]) is so "+$r[(n)]

在线尝试!

但是,它不仅倾向于多次说同一件事,而且几乎要求您输入的元素数相同。我相信所使用的伪随机数生成器在很大程度上取决于时钟,快速重复调用它通常可以得到相同的结果。然后它的条件是,如果所有列表的长度都相同,则仅使用整个列表。由于仅保存3〜5个字符并且有很多警告,我更喜欢本文开头的代码。


1
欢迎来到PPCG!零件和属性可以重复,这样可以节省一些字节。
毛茸茸的

2
您可以删除Get-Get-Random。它是评估命令时测试的默认动词。
马特

2
欢迎!一些简单的高尔夫球比赛将您压缩到147个字节
AdmBorkBork


2

JavaScript 129

(a,b,c)=>(z='',a.forEach((f,i)=>z+=`That's ${q=i!=5?"not ":""}my ${f}${q?", i":"! I"}ts ${b[i]} is ${q?"to":"s"}o ${c[i]}.\n`),z)

输入是三个数组,返回字符串



2

C# 204个 203字节

()=>{int a(int x)=>new Random().Next(x);var j=t[a(5)];string s()=>$"That's not my {j}, its {p[a(25)]} is too {o[a(19)]}.\n";return s()+s()+s()+s()+s()+$"That's my {j}! Its {p[a(25)]} is so {o[a(19)]}.";};

这是我在此站点上的第一个答案,所以我希望它能很好地工作。它还需要这三样东西,但是根据问题这些都不算:

   var t = new[] { "dinosaur", "lamb", "princess", "reindeer", "train" };
   var p = new[] {"back", "bells", "body", "bows", "crown", "dress", "ears",
          "engine", "fan", "flippers", "funnel", "hooves", "horns", "neck",
          "nose", "roof", "sash", "side", "spines", "spots", "tail", "teeth",
          "tiara", "wheels", "windows" };
   var o = new[] {"bumpy", "fluffy", "furry", "fuzzy", "glittery", "glossy",
          "hairy", "red", "rough", "rusty", "shiny", "silky", "slippery",
          "soft", "sparkly", "squashy", "thick", "velvety", "woolly"};

在线尝试!

多亏了Sok,少了一个字节。


1
欢迎来到PPCG!我已经自由地在指向您的答案的TIO链接中进行编辑,以便其他人可以轻松地自己尝试您的代码-我会在此评论中给您提供指向它的链接,但不幸的是URI太长了!希望您过得愉快:o)
Sok,

1
您也可以参加一场小型高尔夫-这\r不是必需的,这将为您节省2个字节。
索克

1

APL(Dyalog Unicode),117 字节SBCS

↑('That''s not my ',(tT⊃⍨?5),', its ')∘,¨P[5?25],¨' is too '∘,¨V[5?19]
'That''s my ',t,'! Its',P[?25],'is so',V[?19]

在线尝试!

?N 在前N个索引中生成一个随机索引。

M?N 在前N个索引中生成M个随机索引(无替换)。

, 是串联的

t←T⊃⍨……选择一个随机的东西,并t在最后一行中调用它以进行重用。

∘,¨ 将左侧的字符串连接到右侧的每个字符串。

将左侧的每个字符串连接到右侧的每个字符串。

 将字符串列表更改为字符矩阵,以便正确打印。


1

Pyth88 78 76字节

JONj_ms.ic"That's
 my 

ts 
 is 
o 
."b[?d" not"kJ?d", i""! I"OG?d\s"to"OH)6

在线尝试!

上面提供的代码需要以下标头:

=N["dinosaur""lamb""princess""reindeer""train")=G["back""bells""body""bows""crown""dress""ears""engine""fan""flippers""funnel""hooves""horns""neck""nose""roof""sash""side""spines""spots""tail""teeth""tiara""wheels""windows")=H["bumpy""fluffy""furry""fuzzy""glittery""glossy""hairy""red""rough""rusty""shiny""silky""slippery""soft""sparkly""squashy""thick""velvety""woolly")

在TIO和Pyth中使用“页眉”功能存在一个小问题,因为看起来TIO在换行符上加入了代码块,而换行符在Pyth中很重要。这是使用'Header'块到相同代码的链接,输出中有一个垃圾行。

JONj_ms.ic"That's¶ my ¶¶ts ¶ is ¶o ¶."b[?d" not"kJ?d", i""! I"OG?d"to"\sOH)6   Newlines replaced with ¶
                                                                               Implicit: k="", b=newline
                                                                               From header: N=things, G=parts, H=properties
JON                                                                            Choose a random element from N, store in J
     m                                                                     6   Map [0-6), as d, using:
                                        ?d" not"k                                If d is truthy (i.e. not 0), yield " not", else ""
                                                 J                               J (the chosen thing)
                                                  ?d", i""! I"                   ", i" if d else "! I"
                                                              OG                 Random element from G
                                                                ?d"to"\s         "to" if d else "s"
                                                                        OH       Random element from H
                                       [                                  )      Wrap the previous 6 results in an array
         c"That's¶ my ¶¶ts ¶ is ¶o ¶."b                                          Split the template string on newlines
       .i                                                                        Interleave the template string elements with the previous list
      s                                                                          Concatenate
    _                                                                          Reverse lines
   j                                                                           Join on newlines, implicit print

编辑:重写高尔夫10字节,以前的版本: J+" my "ONV5%"That's not%s, its %s is too %s."[JOGOH;%"That's%s! Its %s is so %s."[JOGOH


1

Perl 5.10,127个字节

用运行perl -M5.010 -f filename.pl

my @t = qw(dinosaur lamb princess reindeer train);
my @r = qw(back bells body bows crown dress ears engine fan flippers funnel
           hooves horns neck nose roof sash side spines spots tail teeth tiara
           wheels windows);
my @p = qw(bumpy fluffy furry fuzzy glittery glossy hairy red rough rusty shiny
           silky slippery soft sparkly squashy thick velvety woolly);

sub r{rand@_}$a=" my $t[r@t]";say"That's not$a, its $r[r@r] is too $p[r@p]."for(1..5);say"That's$a! Its $r[r@r] is so $p[r@p]."

1

JavaScript ES6,149(+15?)字节

a = ["dinosaur", "lamb", "princess", "reindeer", "train"]
b = ["back", "bells", "body", "bows", "crown", "dress", "ears",
  "engine", "fan", "flippers", "funnel", "hooves", "horns", "neck",
  "nose", "roof", "sash", "side", "spines", "spots", "tail", "teeth",
  "tiara", "wheels", "windows"]
c = ["bumpy", "fluffy", "furry", "fuzzy", "glittery", "glossy",
  "hairy", "red", "rough", "rusty", "shiny", "silky", "slippery", 
  "soft", "sparkly", "squashy", "thick", "velvety", "woolly"]

// r=x=>x[parseInt(Math.random()*x.length)] 164 for better random on fast pc

r=x=>x[new Date%x.length]
s=r(a)
g=j=>console.log(`That's ${j?`not my ${s}, its ${r(b)} is to`:`my ${s}! Its ${r(b)} is s`}o ${r(c)}.`)
a.map(g) 
g()


欢迎来到Code Golf!干得好!
AJFaraday

1
谢谢AJ!非常感谢:)
Onitz,

1

批处理文件,434 424 + 7个字节

通过执行cmd/q/c

不计算代码

set a=dinosaur lamb princess reindeer train
set b=back bells body bows crown dress ears engine fan flippers funnel hoobes horns neck nose roof sash side spines spots tail teeth tiara wheels windows
set c=bumpy fluffy furry fizzy glittery glossy hair red rough rusty shiny silky slippery soft sparkly squashy thick velvety woolly

码数

set q=random
set m=set/ar=1+%%%q%%%%%%%
call %m%5
for /f "tokens=%r%" %%x in ("%a%")do set x=%%x
:a
set/ad+=1
call %m%25
for /f "tokens=%r%" %%y in ("%b%")do set y=%%y
call %m%19
for /f "tokens=%r%" %%z in ("%c%")do echo That's not my %x%, its %y% is too %%z.
if %d% neq 5 goto a
call %m%25
for /f "tokens=%r%" %%y in ("%b%")do set y=%%y
call %m%19
for /f "tokens=%r%" %%z in ("%c%")do echo That's my %x%! Its %y% is so %%z.

我将处理您必须面对的一些挑战,并解释/证明我所做的事情,以便其他人可以改善。

从数组中选择一个随机元素
我是通过在1和之间创建一个随机数来完成nn操作的,该数组中的元素数量为。然后,我使用此随机数作为令牌来抓取每个for循环(tokens=%r%)。因为我是这样做的,所以我不能再嵌套这些for循环了,因为tokens=!r!对我不起作用(扩展延迟)。这样可以节省很多字节,因为它消除了将标记另存为变量(set x=%%x)的需要。

随机数生成
m是我的随机数生成宏。这样做比set/ar=%random%%%n+1每行节省32个字节。您可以半作弊并确定令牌yz将是同一元素:

call %m%19
for /f "tokens=%r%" %%y in ("%b%")do set y=%%y
for /f "tokens=%r%" %%z in ("%c%")do echo That's not my %x%, its %y% is too %%z.

这将在仍然保留一定随机性的同时,排除的最后6个元素c。这将至少节省20个字节,但是我认为这不符合op的要求。

理论上的改进
我花了很长时间尝试使此“伪代码”起作用,同时仍然节省字节:

set 1-5=echo That's not my %x%, its %y% is too %%z.
set 6=echo That's my %x%! Its %y% is so %%z.
...
set/ad+=1
for /f "tokens=%r%" %%z in ("%c%")do call %%d%%

不幸的是,事实证明,这种设置占用了太多的字节以致无法盈利(必须在<144字节内实现),但我不能撼动添加最后四行代码是多余而混乱的感觉。


您不允许通过预定义变量进行输入。你必须把它作为实际的输入通过任何标准IO方法
乔金

1
@JoKing来自挑战:The lists of source words are not part of your answer (in TIO they can be added to the header).
AdmBorkBork,

我不能确定是否允许或没有我已经看到它做在其他的答案两种方式,但对于那些你好奇它会在表单中添加29个字节到我的回答set a=%~1,等等
BDM

1

墨水,119字节

~a=LIST_RANDOM(a)
-(l)That's{l<6: not} my {a}{l<6:, i|! I}ts {LIST_RANDOM(b)} is {l<6:to|s}o {LIST_RANDOM(c)}
{l<6:->l}

列表定义为

LIST a=(dinosaur),(lamb),(princess),(reindeer),(train)
LIST b=(back),(bells),(body),(bows),(crown),(dress),(ears),(engine),(fan),(flippers),(funnel),(hooves),(horns),(neck),(nose),(roof),(sash),(side),(spines),(spots),(tail),(teeth),(tiara),(wheels),(windows)
LIST c=(bumpy),(fluffy),(furry),(fuzzy),(glittery),(glossy),(hairy),(red),(rough),(rusty),(shiny),(silky),(slippery),(soft),(sparkly),(squashy),(thick),(velvety),(woolly)

在线尝试!


尽管取决于什么算作列表,但还有其他方法。如果列表可以是随机返回列表项的函数,则以下方法仅为91字节:

~temp t=u()
-(l)That's{l<6: not} my {t}{l<6:, i|! I}ts {p()} is {l<6:to|s}o {q()}
{l<6:->l}

(“列表”定义如下)

==function u
~return "{~dinosaur|lamb|princess|reindeer|train}"
==function p
~return "{~back|bells|body|bows|crown|dress|ears|engine|fan|flippers|funnel|hooves|horns|neck|nose|roof|sash|side|spines|spots|tail|teeth|tiara|wheels|windows}"
==function q
~return " {~bumpy|fluffy|furry|fuzzy|glittery|glossy|hairy|red|rough|rusty|shiny|silky|slippery|soft|sparkly|squashy|thick|velvety|woolly}."

在线尝试!


还有以下方法。

~temp t="{~dinosaur|lamb|princess|reindeer|train}"
-(l)That's{l<6: not} my {t}{l<6:, i|! I}ts {~back|bells|body|bows|crown|dress|ears|engine|fan|flippers|funnel|hooves|horns|neck|nose|roof|sash|side|spines|spots|tail|teeth|tiara|wheels|windows} is {l<6:to|s}o {~bumpy|fluffy|furry|fuzzy|glittery|glossy|hairy|red|rough|rusty|shiny|silky|slippery|soft|sparkly|squashy|thick|velvety|woolly}
{l<6:->l}

在线尝试!

该解决方案为389个字节,但是如果将混洗文字(在这种情况下不能真正移动)视为列表定义并且可以从字节数中排除,则该字节数将降至80个字节。


0

Bash + awk,209个字节

T=$(shuf $1|head -1)
join <(sed "s/.*/$T\t&/" $2) <(sed "s/.*/$T\t&/" $3)|shuf|awk 'NR<6{printf "That'\''s not my %s, its %s is too %s.\n",$1,$2,$3}NR==6{printf "That'\''s my %s! Its %s is so %s.\n",$1,$2,$3}'

在线尝试!

接受输入,things parts properties因为每个输入都是一个文件,其中每一行都具有所需类型的一项。

这是一种以文件为中心的方法。稍后可以尝试以数组为中心的方法,看看是否可以改进。


-2

Python 3,130个字节

从字面上理解您的要求,然后每个都返回一个字节:

y=0
def x():
    global y
    y=1-y 
    print(("That's not my lamb, it's "+b[0:1][y]+" is too red\n")*5+"That's my lamb! Its fan is so red")

“它不能始终如一地复制相同的文本。” 据我所知,您的代码将始终在两个选项之一之间交替,这对我来说似乎是一致的输出。此外,注释说明中明确禁止在每一行上始终使用相同属性的情况。
Value Ink
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.