这……是……要塞!


11

Fortress是由Sun编程语言研究小组(RIP Fortress)开发的一种语言,具有独特的属性,可以用不同的字体样式(例如,黑板粗体,粗体,斜体,罗马等)。目标是在HTML标记中表示一个单字符的Fortress变量。

这是一字符变量设防的工作方式(出于代码查询目的,从文档中进行了简化/修改):

  • 如果该变量是重复的大写字母(例如ZZ),则其格式为黑板粗体(𝔸𝔹ℂ𝔻𝔼𝔽𝔾ℍ𝕀𝕁𝕂𝕃𝕄ℕ𝕆ℙℚℝ𝕊𝕋𝕌𝕍𝕎𝕏𝕐ℤ
  • 如果该变量前面带有下划线,则该变量将以罗马字体呈现(单独保留)
  • 如果变量后面带有下划线,则该变量将以粗体(<b>v </b>)呈现。
  • 如果该变量既不带下划线也不带下划线,则该变量以斜体(<i>v </i>)呈现。
  • 黑板粗体的代码点是::𝔸1D538,𝔹:1D539, :2102,𝔻:1D53B,𝔼:1D53C,𝔽:1D53D,𝔾:1D53E,:210D,𝕀:1D540,𝕁:1D541,𝕂:1D542,𝕃:1D543,𝕄:1D544,:2115,𝕆:1D546,:2119,:211A,:211D,𝕊:1D54A,𝕋:1D54B,𝕌:1D54C,𝕍:1D54D,𝕎:1D54E,𝕏:1D54F,𝕐:1D550,:2124。它们在程序中每个一个字节(如果您选择的语言完全可以处理这些字符)

输入将是重复的ASCII大写字母,或者是没有下划线,前导下划线或末尾下划线的单个ASCII字母(AKA _a_将不是输入)。这是代码高尔夫球,因此最低字节数为准!

测试用例:

a => <i>a</i>
BB => 𝔹
c_ => <b>c</b>
_d => d
E => <i>E</i>
G_ => <b>G</b>
_H => H
ZZ => ℤ

链接:规范直接下载版本0.1 alpha

参考实现(这在Fortress中,但是Fortress不喜欢大多数双连字符,因此该实现在D中):

dstring fortify(string arg) {
    import std.string, std.conv;

    alias D = to!dstring; //Convert to a string that accepts the unicode needed
    dstring BB = "𝔸𝔹ℂ𝔻𝔼𝔽𝔾ℍ𝕀𝕁𝕂𝕃𝕄ℕ𝕆ℙℚℝ𝕊𝕋𝕌𝕍𝕎𝕏𝕐ℤ"d; //blackboard bold capitals
    string UC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //normal ASCII capitals

    if(arg.length == 1)
        return D("<i>" ~ arg ~ "</i>");
    if(arg[0] == a[1])
        return D(BB[UC.indexOf(arg[0])]);
    if(arg[0] == '_')
        return D(arg[1]);
    return D("<b>" ~ arg[0] ~ "</b>");
}

我忘了删除,沙箱链接:codegolf.meta.stackexchange.com/a/13383/55550
扎卡里

唯一的大写变量是重复的双精度变量,还是其他三个小写变量?
乔纳森·艾伦

大写可以是正常,斜体和粗体。小写不能重复使用。
扎卡里

_____将不会输入。
扎卡里

哦...所以这不是我们要转换的字符串,只是一个字符?
魔术章鱼缸

Answers:


1

果冻,73 个字节

事实证明,无法在代码中使用BBB字母非常昂贵。

5ŀ”i
“Ðñṡ’Dẋ@€“¡ḞḄ’ż“¿¿Æ€¢¬µ‘+⁽ø³F⁸ṪO¤+ị¥Ọ
Ṫ
Ḣ5ŀ”b
;j“<>/”ṃ@“¢ʠf’
i”_+LµĿ

一个带有一个参数并打印结果的完整程序。

在线尝试!或查看测试套件

怎么样?

主入口点是代码的最后一行(“主链接”)。

5ŀ”i - Link 1: list of characters, s (length 1 & no underscore)
  ”i - literal character 'i'
5ŀ   - call link 5 as a dyad with s on the left and 'i' on the right

“Ðñṡ’Dẋ@€“¡ḞḄ’ż“¿¿Æ€¢¬µ‘+⁽ø³F⁸ṪO¤+ị¥Ọ - Link 2: list of characters, s (length 2 & no underscore)
“Ðñṡ’                                 - base 250 literal              1007245
     D                                - to decimal list               [1,0,0,7,2,4,5]
         “¡ḞḄ’                        - base 250 literal              111673
      ẋ@€                             - repeat with reversed @rguments for €ach -> [[111673],[],[],[111673,111673,111673,111673,111673,111673,111673],[111673,111673],[111673,111673,111673,111673],[111673,111673,111673,111673,111673]]
               “¿¿Æ€¢¬µ‘              - code page index list          [11,11,13,12,1,7,9]
              ż                       - zip together                  [[111673,11],[11],[13],[[111673,111673,111673,111673,111673,111673,111673],12],[[111673,111673],1],[[111673,111673,111673,111673],7],[[111673,111673,111673,111673,111673],9]]
                         ⁽ø³          - base 250 literal              8382
                        +             - addition (vectorises)         [[120055,8393],[8393],[8395],[[120055,120055,120055,120055,120055,120055,120055],8394],[[120055,120055],8383],[[120055,120055,120055,120055],8389],[[120055,120055,120055,120055,120055],8391]]
                            F         - flatten                       [120055,8393,8393,8395,120055,120055,120055,120055,120055,120055,120055,8394,120055,120055,8383,120055,120055,120055,120055,8389,120055,120055,120055,120055,120055,8391]
                                ¤     - nilad followed by link(s) as a nilad:                                                                                    ^
                             ⁸        -   chain's left argument, s  e.g.    "CC"                                                                                 |
                              Ṫ       -   tail (last character)             'C'                                                                                  |
                               O      -   cast to ordinal                   67                                                                                   |
                                   ¥  - last two links as a dyad:                                                                                                |
                                  ị   -   index into (1-indexed & modular)  8383 (this is at index 67%26=15 -----------------------------------------------------+ )
                                 +    -   add the ordinal                   8450
                                    Ọ - convert from ordinal to character   'ℂ'

Ṫ - Link 3: list of characters, s (length 2 & underscore at index 1)
Ṫ - tail (get the first character

Ḣ5ŀ”b - Link 4: list of characters, s (length 2 & underscore at index 2)
Ḣ     - head s (the non-_ character)
   ”b - literal character 'b'
 5ŀ   - call link 5 as a dyad with the non-_ character on the left and 'b' on the right

;j“<>/”ṃ@“¢ʠf’ - Link 5, wrap in a tag: element, tagName      e.g. 'a', 'i'
;              - concatenate the element with the tagName          "ai"
  “<>/”        - literal list of characters                        "<>/"
 j             - join                                              "a<>/i"
         “¢ʠf’ - base 250 literal                                  166603
       ṃ@      - base decompression with reversed @rguments
               -   "a<>/i" is 5 long, so 166603 is converted to
               -   base 5 [2,0,3,1,2,4,0,3] with digits "a<>/i"    "<i>a</i>"

i”_+LµĿ - Main link: list of characters, s (as specified only):
 ”_     - literal '_'
i       - index of '_' in s (1-indexed; 0 if not found)
    L   - length of s
   +    - addition
     µĿ - call link with that number as a monad with argument s
        - implicit print

输入失败ZZ
扎卡里

哦,这是在Unicode的另一个地方吗?他们做出了奇怪的选择。
乔纳森·艾伦,

是的,双重打击,C H N P Q R并且Z在Unicode中位于不同的位置。
扎卡里

(阅读第五个项目符号点)
扎卡里

大声笑,看到果冻这样的翻牌很有趣!
扎卡里

4

蟒3.6,159个 131 128字节

@Zacharý节省了1个字节

@VаlueInk节省了3个字节

@Rod节省了28个字节

lambda s:len(s)<2and f"<i>{s}</i>"or s[0]==s[1]and"𝔸𝔹ℂ𝔻𝔼𝔽𝔾ℍ𝕀𝕁𝕂𝕃𝕄ℕ𝕆ℙℚℝ𝕊𝕋𝕌𝕍𝕎𝕏𝕐ℤ"[ord(s[0])-65]or[f"<b>{s[0]}</b>",s[1]][s[0]=='_']

在线尝试!


len(s)<2 and=>len(s)<2and
扎卡里

查看帖子的新编辑,每个𝔸𝔹ℂ𝔻𝔼𝔽𝔾ℍ𝕀𝕁𝕂𝕃𝕄ℕ𝕆ℙℚℝ𝕊𝕋𝕌𝕍𝕎𝕏𝕐ℤ计为1个字节。
扎卡里


2

红宝石104 106 105 + 1 = 105 107 106 “字节”

在视网膜上可能效果更好。使用-p标志。

来自Zacharý的-1个字节。

gsub /^.$/,'<i>\0</i>'
gsub(/(.)\1/){$1.tr"A-Z","𝔸𝔹ℂ𝔻-𝔾ℍ𝕀-𝕄ℕ𝕆ℙℚℝ𝕊-𝕐ℤ"}
gsub /(.)_/,'<b>\1</b>'
gsub ?_,''

在线尝试!


你忘了JJKKLLTTUUVVWW。!(这可能是为什么MM
扎卡里

@Zacharý固定。
价值墨水

2
我认为您可以通过节省一个字节𝕊-𝕏𝕐 𝕊-𝕐
扎卡里

您没有为保存1字节而更新TIO链接。此外,这在使用UTF-16的Retina中严重失败,因此无法将单个AY转换为两个char16_t blackbold字符。
尼尔

@Neil哎呀。固定链接。
价值墨水

1

JavaScript,97个字符

([a,b])=>a==b?[...'𝔸𝔹ℂ𝔻𝔼𝔽𝔾ℍ𝕀𝕁𝕂𝕃𝕄ℕ𝕆ℙℚℝ𝕊𝕋𝕌𝕍𝕎𝕏𝕐ℤ'][a.charCodeAt()-65]:b?b=='_'?a.bold():b:a.italics()

为什么一种语言具有诸如String.prototype.italics和的方法String.prototype.bold

感谢Neil,节省9个字节,使用[...s]代替s.match(/./u)


这是ES6还是ES7?
扎卡里

uRegExp中的标志是ES6功能。String.prototype.italicsString.prototype.bold只是一些旧功能。
tsh

我知道这是ES6,因为箭头很粗。
扎卡里

在上面的注释中将“ ES6”更改为“ ES6或ES7”。
扎卡里

[...'𝔸𝔹ℂ𝔻𝔼𝔽𝔾ℍ𝕀𝕁𝕂𝕃𝕄ℕ𝕆ℙℚℝ𝕊𝕋𝕌𝕍𝕎𝕏𝕐ℤ']应该为您节省一些字节。
尼尔
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.