我需要多少法力?


33

Dungeon Master是有史以来最早的实时角色扮演游戏之一,最初于1987年在Atari ST上发布。在当时其他令人兴奋的事情中,它提供了一个基于符文的相当复杂的咒语系统。

今天的任务是编写一个程序或函数,以评估在Dungeon Master中施放给定咒语所需的法力点数。

地牢大师截图

上图右上方的青色框是“拼写”系统。

法术,符文和法力

地下城主法术由2至4个符文组成,并按照以下顺序从以下类别中进行选择:

  1. 功率(强制性)
  2. 元素影响力(强制性)
  3. 表格(可选)
  4. 类/对齐(可选)

这意味着有效的咒语是:

  • 力量+元素影响
  • 力量+元素影响力+形式
  • 力量+元素影响力+形式+阶级/阵线

每个类别包含6个符文,每个符文都有一个相关的基础法力消耗:

=============================================================================
| Power               | Rune      |   Lo |   Um |   On |   Ee |  Pal |  Mon |
|                     +-----------+------+------+------+------+------+------+
|                     | Base cost |    1 |    2 |    3 |    4 |    5 |    6 |
=============================================================================
| Elemental Influence | Rune      |   Ya |   Vi |   Oh |  Ful |  Des |   Zo |
|                     +-----------+------+------+------+------+------+------+
|                     | Base cost |    2 |    3 |    4 |    5 |    6 |    7 |
=============================================================================
| Form                | Rune      |  Ven |   Ew | Kath |   Ir |  Bro |  Gor |
|                     +-----------+------+------+------+------+------+------+
|                     | Base cost |    4 |    5 |    6 |    7 |    7 |    9 |
=============================================================================
| Class / Alignment   | Rune      |   Ku |  Ros | Dain | Neta |   Ra |  Sar |
|                     +-----------+------+------+------+------+------+------+
|                     | Base cost |    2 |    2 |    3 |    4 |    6 |    7 |
=============================================================================

评估法力消耗

该法术的法力消耗是所有符文的法力消耗总和:

  • 能量符文的费用始终等于其基础费用(从1到6)。

  • 对于其他符文,以下公式适用:

    成本=地板((功率+1)*基本成本/ 2)

    其中,电源是电源符文的基本费用。

例子

Spell: Lo Ful
Cost : 1 + floor((1 + 1) * 5 / 2) = 1 + 5 = 6

Spell: Um Ful
Cost : 2 + floor((2 + 1) * 5 / 2) = 2 + 7 = 9

Spell: Pal Vi Bro
Cost : 5 + floor((5 + 1) * 3 / 2) + floor((5 + 1) * 7 / 2) = 5 + 9 + 21 = 35

澄清和规则

  • 您的输入将包含2至4个字符串,用于指定该咒语。您可以采用任何合理的格式,例如4个不同的参数,一个字符串数组(例如['Lo', 'Ful'])或仅一个带有您选择的单字符分隔符的字符串(例如'Lo Ful')。请在答案中指定所选的输入格式。
  • 符文保证有效。
  • 必须遵守类别的顺序。未使用的类别可能会丢失或被某些虚假的值替换。
  • 您可以接受以下任何一种格式的符文:1.大写字母后跟小写字母('Ful')2.所有小写字母('ful')3.所有大写字母('FUL')。但你不能混用不同的格式。
  • 很明显,我们不在乎该咒语是否确实在游戏中具有某种效果(因为好奇的有用的咒语在此列出)。
  • 这是,因此以字节为单位的最短代码获胜。
  • 记住:混沌大人在看着你!

测试用例

Spell          | Output
---------------+-------
Lo Ful         | 6
Um Ful         | 9
On Ya          | 7
Lo Zo Ven      | 12
Pal Vi Bro     | 35
Ee Ya Bro Ros  | 31
On Ful Bro Ku  | 31
Lo Zo Kath Ra  | 20
On Oh Ew Sar   | 35
Ee Oh Gor Dain | 43
Mon Zo Ir Neta | 68
Mon Des Ir Sar | 75

1
切线-但对于喜欢此系统的人来说,《沃兹的魔法王国》是一款日语SNES游戏(可提供英语翻译),其实现的系统几乎相同-任何字母串都变为咒语。google.co.jp/webhp?ie=UTF-8#q=magical+land+of+wozz
Coty Johnathan Saxman

我对看某人玩《地牢大师》的记忆有些模糊(我不认为这是在ST上)。他们为其中一名战士装备了一条魔术项链,每隔一段时间,他们就会检查它是否已充电,如果是,则再施放我认为是某种发光法术的符文,以便战士能够施放这个咒语每十分钟左右,并最终获得了魔法水平。
尼尔

@Neil这条项链可能是月长石(+3法力值)或吊坠野性(+1魔法师技能)。所有项目都在这里列出。
Arnauld

该脚本应输出所有可能的输入组合
NieDzejkob

Answers:


6

SOGL V0.12110个 78 字节

θKKι"LUOEPM”;W:A≤{B"⁶Μ↓§QΕņj“L─"¶Ζq«╝γDyΜ2¶S◄Μ$‘č¹I6nēwι{_Cb:ƧRA=┌*ΚKι=?aIc*»+

在这里尝试!

重做所有内容可能会使一两个字节打高尔夫球

说明:

θ            split on spaces
 K           pop the 1st item
  K          pop from the string the 1st character
   ι         remove the original string from stack
    "”;W     get the chars index in "LUOEPM"
        :A   save a copy to variable A
          ≤  put the power (used as the mana) on the bottom of the stack (with the thing above being the input array)

{            for the leftover items in the input do
 B             save the current name on B
  "..“         push 456779223467234567
      L─       base-10 decode it (yes, silly, but it converts it to an array of digits)
        ".‘    push "VEKIBGKRDN-SYVOFDZ"

      č        chop to characters
       ¹       create an array of those two
        I      rotate clockwise
         6n    group to an array with sub-arrays of length 6 (so each array in the array contains 3 items, corresponding to the categories, each with 6 arrays with the runes 1st letter (or "-" in the case of Ra) and base cost)
           ē   push variable e (default = user input number, which errors and defaults to 0) and after that increase it (aka `e++`)
            w  get that item in the array (the array is 1-indexed and the variable is not, so the array was created shifted (which somehow saves 0.9 ≈ 1 byte in the compression))

 ι             remove the original array
  {            for each in that (current category) array
   _             dump all contents on stack (so pushing the runes name and then base cost)
    C            save pop (base cost) on variable B
     b:          duplicate the name
       ƧRA=      push if pop = "RA"
           ┌*    get that many (so 0 or 1) dashes
             Κ   prepend the "" or "-" to the name
              K  pop the 1st letter of the name
               ι remove the modified name, leaving the 1st letter on the stack

         =?      if top 2 are equal (one of the dumped items and the 1st letter of the current inputs)
           a       push variable A (the power)
            I      increase it
             c     push variable C (the current base cost)
              *    multiply
               »   floor-divide by 2
                +  add that to the power

2
这就是让它变得更加有趣的原因
Walfrat

您能补充说明吗?
CalculatorFeline

@CalculatorFeline Kinda忘记了这个答案。可能会打高尔夫球,然后添加一个解释
dzaima

17

Python 2中135个 119 115字节

b=[int('27169735 2  4567 435262'[int(x,36)%141%83%50%23])for x in input()]
print b[0]+sum(a*-~b[0]/2for a in b[1:])

在线尝试!

输入是来自stdin的字符串列表


Outgolfed ...>。<
Xcoder先生,2017年

我也将您的TIO输入法也复制到我的答案中,希望您不要介意。
Xcoder先生17年

@ Mr.Xcoder我现在已包含所有测试用例。您可以根据需要复制它们
ovs

哦,在索引编制方面做得很好-请问我是否为我的JS解决方案借用了它?
毛茸茸的

11

05AB1E83 82字节

.•Y<εΔ•¹нk©.•M₄P畲нkÌ.•Jrû •³нkD(i\ë4 3‡4+}.•A1Δ#•I4èkD(i\ë3LJ012‡Ì})ćsv®>y*;(î(+

在线尝试!

-1感谢Emigna

SOOOOOOO非高尔夫:(

说明:

.•Y<εΔ•¹нk©.•M₄P畲нkÌ.•Jrû •³нkD(i\ë4 3‡4+}.•A1Δ#•I4èkD(i\ë3LJ012‡Ì})ćsv®>y*;(î(+ Accepts four runes as separate lines, lowercase. Use Ø for missing runes.
.•Y<εΔ•¹нk©                                                                        Index first letter of first rune into "aluoepm" ("a" makes 1-indexed)
           .•M₄P畲нkÌ                                                             Index first letter of second rune into "yvofdz", 2-indexed.
                      .•Jrû •³нkD(i\ë4 3‡4+}                                       Index first letter of third rune into "vekibg", 0-indexed, if it's not there pop, else, if index is 4 replace with 3, else keep as-is, then increment by 4.
                                            .•A1Δ#•I4èkD(i\ë3LJ012‡Ì}              Index fourth letter (modular wrapping) of fourth rune into "kodnra", if it's not there pop, else, if index is one of 1, 2 or 3, replace with 0, 1 or 2 respectively, else keep as-is, then increment by 2.
                                                                     )ćs           Wrap all numbers into a list, keeping the power rune behind.
                                                                        v          For each
                                                                         ®>y*;(î(   Apply the formula
                                                                                 +  Add to total sum

一个小小的高尔夫就是,如果您.•Y<εΔ•在开始时就索引,则不需要增加索引。
Emigna

@Emigna Ooh还没来得及尝试...
Outgolfer的Erik

11

的JavaScript(ES6),157 156 116 112 100 99 97个字节

将输入作为字符串数组。

a=>a.map(c=>t+=(v=+`27169735020045670435262`[parseInt(c,36)%141%83%50%23],+a?a*v+v>>1:a=v),t=0)|t
  • 通过从ovs的Python解决方案中借用索引技巧,节省了44字节的大量内容-如果您支持此答案,请也支持该解决方案
  • 感谢Arnauld指出,节省了13个字节,这应该是使用三元组的明显机会。

在线尝试!


说明

哦,男孩,这会很有趣-我对微不足道的解决方案的解释在最佳时机很糟糕!让我们去吧...

a=>

一个匿名数组,它通过parameter将数组作为参数a

a.reduce((t,c)=>,0)

通过将每个元素传递给函数来减少数组中的元素;该t参数是运行总计,该c参数是电流串和0是的初始值t

parseInt(c,36)

将当前元素从基数为36的字符串转换为十进制整数。

%141%83%50%23

对它执行一些模运算。

+`27169735 2  4567 435262`[]

从该索引处的字符串中获取字符,并将其转换为数字。

v=

将该数字分配给变量v

+a?

检查变量a是否为数字。对于第一个元素a将是字符串数组,尝试将其转换为数字将返回NaN,这是错误的。在随后的每个遍中,a将为正整数,这是正确的。

a*v+v>>1

如果a是数字,则将其乘以的值v,将的值相加,v然后将结果的位向右移1位,这得到的结果与除以2和下限相同。

:a=v

如果a不是数字,我们将为其分配值v,这也将使我们0在第一次通过时将其加到总数中。

t+

最后,我们将上述三进制的结果添加到运行总计中。


原始的156个字节

a=>a.reduce((t,c)=>t+(p+1)*g(c)/2|0,p=(g=e=>+`123456234567456779223467`["LoUmOnEePaMoYaViOhFuDeZoVeEwKaIrBrGoKuRoDaNeRaSa".search(e[0]+e[1])/2])(a.shift()))

您可以通过重复使用a来节省一个字节:(a=>a.reduce((t,c)=>t+(v=+'27169735020045670435262'[parseInt(c,36)%141%83%50%23],+a?a*v+v>>1:a=v),0)编辑:删除了关于输入中传递的整数的不相关注释-好像我不太了解自己的挑战^^)
Arnauld

整洁的技巧,谢谢,@ Arnauld。尝试进行计算,这将使我目前正在索引的数字以较少的字节为单位,但运气不佳。
毛茸茸的

6

JavaScript中,212个 210 207 206字节

直截了当的搜索算法,搜索字符串仅占总字节数。

s=>eval('p=q=+(e=s.map(r=>"1 2 3 4 5  6  2 3 4 5  6  7 4  5 6   7 7  9  2 2  3   4   6 7"["LoUmOnEePalMonYaViOhFulDesZoVenEwKathIrBroGorKuRosDainNetaRaSar".search(r)])).shift();e.map(c=>p+=((q+1)*c)>>1);p')

输入格式

字符串数组,每个项目都是首字母大写的字符串。示例:[“ Mon”,“ Zo”,“ Ir”,“ Neta”]

说明

e=s.map(r=>"1 2 3 4 5  6  2 3 4 5  6  7 4  5 6   7 7  9  2 2  3   4   6 7"["LoUmOnEePalMonYaViOhFulDesZoVenEwKathIrBroGorKuRosDainNetaRaSar".search(r)])

这查询基本费用。

p=q=+(/*blah*/).shift() 

使用上面数组结果中的第一项初始化2个变量,然后删除该项。必须先将其强制转换为数字,否则在下一部分中将其视为字符串连接。

e.map(c=>p+=((q+1)*c)>>1);

将非动力符文的成本加到基本动力上。使用移位代替了floor(blah)/ 2。

eval(/*blah*/;p)

评估最后的结果。(来源:Step Hen)

测试用例

Lo Ful | 6
Um Ful | 9
On Ya | 7
Lo Zo Ven | 12
Pal Vi Bro | 35
Ee Ya Bro Ros | 31
On Ful Bro Ku | 31
Lo Zo Kath Ra | 20
On Oh Ew Sar | 35
Ee Oh Gor Dain | 43
Mon Zo Ir Neta | 68
Mon Des Ir Sar | 75

编辑1:212> 210-删除了一对大括号

编辑2:210> 207-感谢Step Hen提醒大家有关JS规则和使用eval()函数的一些提示。由于AS3禁止使用eval(),因此我很长时间没有使用它了

编辑3:207> 206-感谢Shaggy提出用search()替换indexOf()的想法


1
除非您g在内部调用g,否则我们允许JS答案删除g=。另外,您可以通过将其切换为eval并删除以下内容来节省几个字节returnFiddle
Stephen

@StepHen感谢eval()的想法和JS规则,因为AS3禁止了eval(),所以我认为我不能再使用它了
Shieru Asakoto

好吧,它仍然有效,我们通过实现来定义语言:P
Stephen

1
search将为您节省一个字节indexOf
毛茸茸的

@Shaggy它的工作,感谢您的搜索想法;)
Shieru Asakoto

3

Haskell中159个 156 148 133 130 127字节

k(p:y)=sum$floor<$>c p:map(\x->c x*(c p+1)/2)y
c s=read["3764529516342767"!!(foldl(\c n->c*94+fromEnum n-9)0s%7086%17)]
(%)=mod

在线尝试!


3

Python 2中320个318 314 311 307字节

输入格式-字符串列表。完整程序:

i=input()
t=[x.split()for x in"Lo Um On Ee Pal Mon|Ya Vi Oh Ful Des Zo|Ven Ew Kath Ir Bro Gor|Ku Ros Dain Neta Ra Sar".split('|')]
c=t[0].index(i[0])+1;r=c+1;s=c+r*(t[1].index(i[1])+2)/2
if len(i)>2:s+=r*(t[2].index(i[2])+4-(i[2]=='Bro'))/2
if len(i)>3:s+=r*(t[3].index(i[3])+1+(i[3]in'KuRaSar'))/2
print(s)

在线尝试!


1
我有点放弃打高尔夫球,所以任何有打高尔夫球想法的人都可以自己编辑
Xcoder先生17年

3

Excel,339个字节

A1通过输入的输入D1。其他任何单元格中的公式。

=CHOOSE(MOD(CODE(A1),12),2,,,1,6,,3,5,4)+INT((CHOOSE(MOD(CODE(A1),12),2,,,1,6,,3,5,4)+1)*CHOOSE(MOD(CODE(B1),12),,3,,,2,7,4,6,,5)/2)+INT((CHOOSE(MOD(CODE(A1),12),2,,,1,6,,3,5,4)+1)*CHOOSE(MOD(CODE(C1),12),7,4,6,,,7,,,5,,9)/2)+INT((CHOOSE(MOD(CODE(A1),12),2,,,1,6,,3,5,4)+1)*CHOOSE(MOD(CODE(SUBSTITUTE(D1,"Ra","E")),11),4,3,6,,2,7,,,2,0)/2)

或者,以CSV格式导入:

Excel&CSV,228字节

,,,
=CHOOSE(MOD(CODE(A1),12),2,,,1,6,,3,5,4)+1
=A2-1+INT(A2*CHOOSE(MOD(CODE(B1),12),,3,,,2,7,4,6,,5)/2)+INT(A2*CHOOSE(MOD(CODE(C1),12),7,4,6,,,7,,,5,,9)/2)+INT(A2*CHOOSE(MOD(CODE(SUBSTITUTE(D1,"Ra","E")),11),4,3,6,,2,7,,,2,0)/2)

在第一行输入的输入,SPACE为空。结果显示在A3中。


2

SCALA,1106个字符,1106个字节

这很长,可能是可以优化的,但是这样做很有趣:)

输入格式:字符串中以空格分隔的符文。如果只有2个输入(例如“ Lo Ful”),我的代码将用它完成while(k.length<4)k:+=""(因此,如果我要求将其设置为“ ABC D”,则可以通过更改参数来节省24个字节)。

def n(i:Int,p:String):Int={Math.floor(i*((""+p(0)).toInt+1)/2).toInt}
def m(s:String):Int={var k=s.split(' ')

while(k.length<4)k:+=""

k match{case Array(p,i,f,a)=>{p match{case "Lo"=>1+m(1+"/ "+i+" "+f+" "+a)
case "Um"=>2+m(2+"/ "+i+" "+f+" "+a)
case "On"=>3+m(3+"/ "+i+" "+f+" "+a)
case "Ee"=>4+m(4+"/ "+i+" "+f+" "+a)
case "Pal"=>5+m(5+"/ "+i+" "+f+" "+a)
case "Mon"=>6+m(6+"/ "+i+" "+f+" "+a)
case _ if p.contains("/")=>i match{case "Ya"=>n(2,p)+m(p+" / "+f+" "+a)
case "Vi"=>n(3,p)+m(p+" / "+f+" "+a)
case "Oh"=>n(4,p)+m(p+" / "+f+" "+a)
case "Ful"=>n(5,p)+m(p+" / "+f+" "+a)
case "Des"=>n(6,p)+m(p+" / "+f+" "+a)
case "Zo"=>n(7,p)+m(p+" / "+f+" "+a)
case _ if p.contains("/")=>f match{case "Ven"=>n(4,p)+m(p+" / "+"/ "+a)
case "Ew"=>n(5,p)+m(p+" / "+"/ "+a)
case "Kath"=>n(6,p)+m(p+" / "+"/ "+a)
case "Ir"=>n(7,p)+m(p+" / "+"/ "+a)
case "Bro"=>n(7,p)+m(p+" / "+"/ "+a)
case "Gor"=>n(9,p)+m(p+" / "+"/ "+a)
case _ if p.contains("/")=>a match{case "Ku"=>n(2,p)
case "Ros"=>n(2,p)
case "Dain"=>n(3,p)
case "Neta"=>n(4,p)
case "Ra"=>n(6,p)
case "Sar"=>n(7,p)
case _=>0}
case _=>0}
case _=>0}
case _=>0}}}}

感谢您的挑战。在线尝试!


@Arnauld我只是注意到了一些关于我的代码的信息:它并没有真正检查事物是否存在!我的意思是,如果我输入“ Lo Whoo Gor”,它将输出5!可以吗 还是应该解决这个问题?
V. Courtois

很好,因为“保证符文有效”(第二条规则)。
Arnauld

哦,是的:)我没有考虑就这样做了,所以我忘记了这个规则。再次感谢。
V. Courtois

2

莎士比亚编程语言,4420字节

,.Ajax,.Ford,.Page,.Puck,.Romeo,.Act I:.Scene I:.[Enter Romeo and Page]Page:You big big big big big big cat.[Exit Romeo][Enter Ajax]Page:Open thy mind!Ajax:Open thy mind!Open thy mind!You is the sum of Romeo and the sum of a big big cat and a cat.Am I as big as you?If not,let us return to Scene V.Page:You is the sum of a big big cat and a cat.Let us return to Act V.Scene V:.Ajax:You is the sum of you and the sum of a big big big cat and a pig.Am I as big as you?If not,let us return to Scene X.Page:You big cat.Let us return to Act V.Scene X:.Ajax:You is the sum of you and the sum of a big cat and a cat.Am I as big as you?If not,let us return to Scene L.Page:You big big cat.Let us return to Act V.Scene L:.Ajax:You is the sum of you and the sum of a big big cat and a big cat.Am I as big as you?If not,let us return to Scene C.Page:You is the sum of a big cat and a cat.Let us return to Act V.Scene C:.Ajax:Am I as big as the sum of you and a big big big pig?Page:You is the sum of a big big cat and a big cat.If so,you is the sum of you and a cat.Ajax:Open thy mind!Act V:.Scene I:.[Exit Ajax][Enter Ford]Page:Open thy mind!Ford:Open thy mind!Open thy mind!You is the sum of Romeo and the sum of a big big big big cat and a pig.Am I as big as you?If not,let us return to Scene V.Page:You big big cat.Let us return to Act X.Scene V:.Ford:You is the sum of you and the sum of a big big big cat and a pig.Am I as big as you?If not,let us return to Scene X.Page:You is the sum of a big cat and a cat.Let us return to Act X.Scene X:.Ford:You is the sum of you and a big big cat.Am I as big as you?If not,let us return to Scene L.Page:You is the sum of a big big big cat and a pig.Let us return to Act X.Scene L:.Ford:Am I as big as the sum of you and a pig?If not,let us return to Scene C.Page:You big cat.Let us return to Act X.Scene C:.Ford:Am I as big as the sum of Romeo and a big big cat?Page:You is the sum of a big big cat and a cat.If so,you is the sum of you and a cat.Ford:Open thy mind!Act X:.Scene I:.[Exit Page][Enter Puck]Ford:You is the sum of the sum of Ajax and a pig and the quotient between the product of Ajax and I and a big cat.Puck:Open thy mind!Is you as big as a pig?If so,let us return to Act D.[Exit Puck][Enter Page]Ford:Open thy mind!Open thy mind!You is the sum of Romeo and the sum of a big big cat and a cat.Am I as big as you?If not,let us return to Scene V.Page:You is the sum of a big big cat and a cat.Let us return to Act L.Scene V:.Ford:Am I as big as the sum of you and a big big cat?If not,let us return to Scene X.Page:You is the sum of a big big big cat and a pig.Let us return to Act L.Scene X:.Ford:Open thy mind!Am I as big as the sum of Romeo and a big cat?If not,let us return to Scene L.Page:You is the sum of a big big big cat and a pig.Let us return to Act L.Scene L:.Ford:You is the sum of Romeo and the sum of a big big big cat and a pig.Am I as big as you?If not,let us return to Scene C.Page:You is the sum of a big big big cat and a cat.Let us return to Act L.Scene C:.Ford:Am I as big as the sum of you and a big big cat?If so,let us return to Scene D.Page:You big big cat.Let us return to Act L.Scene D:.Page:Open thy mind!You is the sum of a big big cat and a big cat.Act L:.Scene I:.[Exit Page][Enter Puck]Ford:You is the sum of you and the quotient between the product of Ajax and I and a big cat.Puck:Open thy mind!Is you as big as a pig?If so,let us return to Act D.[Exit Puck][Enter Page]Ford:You is the sum of Romeo and a big big cat.Am I as big as you?If not,let us return to Scene V.Page:You is the sum of a big cat and a cat.Let us return to Act C.Scene V:.Ford:You is the sum of you and the sum of a big big big cat and a pig.Am I as big as you?If not,let us return to Scene X.Page:You big cat.Let us return to Act C.Scene X:.Ford:Am I as big as the sum of you and the sum of a big cat and a cat?If not,let us return to Scene L.Page:You big big cat.Let us return to Act C.Scene L:.Ford:Am I as big as the sum of you and a big big big cat?If not,let us return to Scene C.Page:You is the sum of a big big big cat and a pig.Let us return to Act C.Scene C:.Page:Open thy mind!Is you as big as the sum of Romeo and a cat?You big cat.If so,you is the sum of you and a big big cat.Act C:.Scene I:.[Exit Page][Enter Puck]Ford:You is the sum of you and the quotient between the product of Ajax and I and a big cat.Act D:.Scene I:.Ford:Open thy heart![Exeunt]

将输入作为大写字符串。

解释即将推出...现在,有趣的事实: Microsoft是SPL中的否定名词。莎士比亚作品中出现了所有其他公认的词。

在线尝试!


1

Java(OpenJDK 8),252字节

r->{int c[][]={{2,3,4,5,6,7},{4,5,6,7,7,9},{2,2,3,4,6,7}},l=r.length,p="LUOEPM".indexOf(r[0].charAt(0))+1,a=p,i=0;String[]s={"YVOFDZ","VEKIBG","KRDNXS"};for(;i<l-1;)a+=(p+1)*c[i][s[i++].indexOf((l>3?r[i].replace("Ra","X"):r[i]).charAt(0))]/2;return a;}

在线尝试!

符文输入为String[]String)的形式首字母大写形式(首字母为大写,其余字母为小写)。

这是标准的“查找第n个字母”方法,同时在第4段中同时存在RosRa。我用的内联和显式替换Ra来处理该问题X


1

视网膜124个 123字节

Gor
9
[ZIBS]\w+
7
Mon|Des|Kath|Ra
6
..l|Ew
5
Ee|Oh|Ven|Neta
4
[OVD]\w+
3
[UYKR]\w+
2
Lo
1
\d
$*
(?<=^(1+) .*1)
$1
\G1
11
11

在线尝试!链接包括测试用例。需要空格分隔的符文。说明:初始阶段仅将每个符文转换为数字,然后将其转换为一元。第一个数字后面的数字乘以一个比第一个数字大的数字,然后第一个数字加倍。最后一级整数将所有结果除以2,然后求和。


1

C,274

#define c(p,r,x)(p+1)*b(r[x+1],x*17)/2
i;char*a="& ; $ # 4 %        ; B * 6 $ 8          6 5 - >3  +  A@( .   6 5    ";b(r,s)char*r;{for(i=0;i<17;i++)if(a[i+s]-3==(r[0]^r[1]))return i/2+1;return 0;}main(n,r)char**r;{n=b(r[1],0);printf("%d\n",n+c(n,r,1)+c(n,r,2)+c(n,r,3));}

更加虚张声势:

#include<stdio.h>
char*a="& ; $ # 4 %      "
       "  ; B * 6 $ 8    "
       "      6 5 - >3  +"
       "  A@( .   6 5    ";
int b(char*r,int s){
  for(int i=0;i<17;i++)
    if(a[i+s]-3==(r[0]^r[1]))
      return i/2+1;
  return 0;
}
#define c(p,r,i)(p+1)*b(r[i+1],i*17)/2
int main(int n,char**r){
  int x=b(r[1],0);
  printf("%d\n",x+c(x,r,1)+c(x,r,2)+c(x,r,3));
}

您需要提供四个命令行参数-因此,对于第一个测试用例,您需要运行 ./a.out Lo Ful "" ""



1

Go,205个字节

func c(s []string)int{f,l:=strings.IndexByte,len(s)
p:=f("UOEPM",s[0][0])+3
r:=p-1+p*(f("VOFDZ",s[1][0])+3)/2
if l>2{r+=p*(f("war o",s[2][1])+5)/2}
if l>3{r+=p*(f("it Ra",s[3][len(s[3])-2])+3)/2}
return r}

这是一个可调用的函数,将符文作为字符串的一部分,例如[]string{"Um", "Ful"}

Go Playground上尝试一下。


0

Haskell,623字节

使用ADT代替数字伏都教。

注意:添加36 {-# LANGUAGE GADTs,ViewPatterns #-}

  • 假定分数是用/编译/计算得出的 -XGADTs -XViewPatterns
data P=Lo|Um|On|Ee|Pal|Mon deriving(Enum,Read,Eq)
data E=Ya|Vi|Oh|Ful|Des|Zo deriving(Enum,Read,Eq)
data F=Ven|Ew|Kath|Ir|Bro|Gor deriving(Enum,Read,Eq)
data C=Ku|Ros|Dain|Neta|Ra|Sar deriving(Enum,Read,Eq)
data S where
  S::P->E->S
  Q::P->E->F->S
  R::P->E->F->C->S
k(a:b:x)=let{p=read a;e=read b}in case x of{[]->S p e;[c]->Q p e(read c);[c,d]->R p e(read c)(read d)}
c,d::Enum a=>a->Int
c=succ.fromEnum
d=(+2).fromEnum
e Bro=7
e x=(+2).d$x
f x|c x`elem`[1,5,6]=d x|2>1=c x
g p f x =(`div`2).(*f x).succ$c p
h(S x y)=c x+g x d y
h(Q x y z)=h(S x y)+g x e z
h(R x y z t)=h(Q x y z)+g x f t
main=print.h.k.words=<<getLine

输入:单个咒语作为普通字符串,例如

Lo Ful

Um Ful

可以通过将最后一行替换为多行来完成

main=interact$unlines.map(show.h.k.words).lines

但这会增加字节数

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.