的J - 110个 103字节
为什么J没有好的函数来处理字符串,而只有数组函数?如果我发现一些聪明的地方,我会进行修改。
编辑:缩短并固定输出(之前有多余的空格)并检查。我也改进了解释。
f=:[:>,&.>/@('IEIINAAGGREASEFFIRE'&t=:(}.@[t{.@[(}:@],(((0{I.@E.)({.;LF;}.)])>@{:))])`]@.(0=#@[))@< ::]
说明:
我将函数用法表示为[<left argument>] <function name> <right argument>
,例如f <text>
。我也不会解释每个细节,因为该功能很长。
@
将右功能应用于左功能,例如 f@g x == f(g(x))
t=:(}.@[t{.@[(}:@],(((0{I.@E.)({.;LF;}.)])>@{:))])']@.(0=#@[)
是一个递归函数 <delimiters> t <boxed string>
,它使用每个定界符按顺序分割字符串。如果找不到某些定界符,则失败。
(((0{I.@E.)({.;LF;}.)])>@{:)
从定界符的左侧分割字符串,并在它们之间添加换行符。
>@{:
从列表中获取最后一个字符串(尚未拆分的字符串)
0{I.@E.
获取要分割的索引,如果分隔符不存在,则失败。
{.;LF;}.
连接拆分的左侧,换行符和拆分的右侧
}:@],
连接先前分割的结果和最后一个函数的结果(最后一个含义:查找)
']@.(0=#@[)
检查是否还有定界符,如果有则调用上述函数(5行)。否则返回。
'IEIINAAGGREASEFFIRE'&
将的左参数t
设置为该字符串
[:>,&.>/@
结合分裂的结果
::]
如果失败(我将搜索分割索引作为薄弱点),则返回原始字符串。
示例(时间太长?):
f 'Dear Boss, how are things? It has come to my attention that I received all the blame for the mishap last Friday. Not just the majority of it. Every last bit of it. Is it wrong for me to think that the rest of the team were at least in part responsible? After all, all six of us were involved from the get-go. Not that I think I should stand without blame. Not at all. All I''m saying is this: I do my best. I try hard. I improve constantly. And I am constantly taking responsibility. Generally speaking, I am very okay with taking full responsibility for my actions. But after this spring, it seems I get more than I deserve. Remember the Flakenhauser contract? Everything went down just about as smooth as one could have hoped. Or so it seemed at first. It was just at the very last minute that things fell apart. All of the team agreed that it was more akin to a freak accident than sloppy planning or mismanaged resources. Still, I - alone - took blame for it. Even though I said nothing then, my tolerance lev...
Dear Boss, how are things?
It has come to my attention that I received all the blame for the mishap last Friday. Not just the majority of it.
Every last bit of it.
Is it wrong for me to think that the rest of the team were at least in part responsible? After all, all six of us were involved from the get-go.
Not that I think I should stand without blame. Not at all.
All I'm saying is this: I do my best. I try hard. I improve constantly. And I am constantly taking responsibility.
Generally speaking, I am very okay with taking full responsibility for my actions. But after this spring, it seems I get more than I deserve.
Remember the Flakenhauser contract?
Everything went down just about as smooth as one could have hoped. Or so it seemed at first. It was just at the very last minute that things fell apart.
All of the team agreed that it was more akin to a freak accident than sloppy planning or mismanaged resources.
Still, I - alone - took blame for it.
Even though I said nothing then, my tolerance level for taking the blame took a serious dent then.
From that point on,
I have felt it necessary to always try twice as hard, just to escape scrutiny. And still, here we are again. In spite of all my accomplishments.
Right where we always seem to end up these days.
Every single project. It's becoming unbearable.
f 'Die in a grease fire. It''s fun. Every time.'
Die in a grease fire. It's fun. Every time.
f 'hai'
hai