我们都知道程序员往往很懒。为了最大限度地利用您的空闲时间,您决定编写一个程序,该程序为输入的文本输出最少的击键次数。
输入:必须转换为击键的文本。您可以决定如何输入文本(STDIN /从参数中提供的文件中读取)
输出:以下格式的必要操作:
- 他们必须编号
H
它:按下一个键并立即释放它P
提示:按下一个键然后不松开(将键R
作为下一个击键时,这将永远不是最佳选择)R
elease:释放P
密钥
范例:
输入:
Hello!
输出:
一个幼稚的解决方案是:
1 P Shift
2 H h
3 R Shift
4 H e
5 H l
6 H l
7 H o
8 P Shift
9 H 1
10 R Shift
这样会更有效:
1 P Shift
2 H h
3 H 1
4 R Shift
5 H Left
6 H e
7 H l
8 H l
9 H o
环境:
- 编辑器使用等宽字体
- 文本采用80个字符的软包装
- 向上箭头和向下箭头保留该列,即使它们之间的行较短
- 剪贴板被认为是空的
- 假定启用了数字锁定
- 大写锁定被假定为禁用
- 大写锁定仅适用于字母(即无Shift锁定)
热键/快捷方式:
- Home:跳到当前行的开头
- End:跳到当前行的末尾
- Ctrl+ A:标记所有内容
- Ctrl+ C:复制
- Ctrl+ X:切
- Ctrl+ V:粘贴
- Shift+光标移动:标记
- Ctrl+ F:打开搜索对话框。
- 愚蠢的文字匹配,没有正则表达式
- 区分大小写
- 搜索环绕
- 用于搜索的单行文本输入
- 输入将被当前选择预填充,除非两者之间有换行符,否则将选择完整的输入
- 复制/粘贴照常进行
- 按下Enter执行搜索,选择当前光标位置之后的第一个匹配项
- F3:重复上一次搜索
- Ctrl+ H:打开替换对话框
- 愚蠢的文字匹配,没有正则表达式
- 区分大小写
- 全部替换,环绕
- 单行文字输入
- 搜索输入将预先填充当前选择,除非两者之间有换行符,否则将选择完整输入
- 替换输入为空
- 复制/粘贴照常进行
- Tab 跳转到替换输入
- 按下将Enter执行全部替换。光标放置在最后一次替换之后
规则:
- 解决方案必须是一个完整的程序,可以在不进行任何进一步修改的情况下进行编译/解析和执行
- 上面显示的键盘是要使用的键盘
- 不需要处理无法用它键入的字符
- 每个密钥必须在最后释放
- 游标不必位于文件末尾
得分:
您的分数是键入以下文本所需的操作总数之和。获胜者是得分最低的解决方案。使用天真的解决方案,我得到了1371 + 833 + 2006 = 4210
。打败它!我将在两周内选出一名优胜者。
1我天真的解决方案
number = 1
H = (char) -> console.log "#{number++} H #{char}"
P = (char) -> console.log "#{number++} P #{char}"
R = (char) -> console.log "#{number++} R #{char}"
strokes = (text) ->
shiftActive = no
for char in text
if /^[a-z]$/.test char
if shiftActive
R "Shift"
shiftActive = no
H char
else if /^[A-Z]$/.test char
unless shiftActive
P "Shift"
shiftActive = yes
H char.toLowerCase()
else
table =
'~': '`'
'!': 1
'@': 2
'#': 3
'$': 4
'%': 5
'^': 6
'&': 7
'*': 8
'(': 9
')': 0
'_': '-'
'+': '='
'|': '\\'
'<': ','
'>': '.'
'?': '/'
':': ';'
'"': "'"
'{': '['
'}': ']'
if table[char]?
unless shiftActive
P "Shift"
shiftActive = yes
H table[char]
else
H switch char
when " " then "Space"
when "\n" then "Enter"
when "\t" then "Tab"
else
if shiftActive
R "Shift"
shiftActive = no
char
R "Shift" if shiftActive
input = ""
process.stdin.on 'data', (chunk) -> input += chunk
process.stdin.on 'end', -> strokes input
2容易重复
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
3更复杂的重复
We're no strangers to love
You know the rules and so do I
A full commitment's what I'm thinking of
You wouldn't get this from any other guy
I just wanna tell you how I'm feeling
Gotta make you understand
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
We've known each other for so long
Your heart's been aching but
You're too shy to say it
Inside we both know what's been going on
We know the game and we're gonna play it
And if you ask me how I'm feeling
Don't tell me you're too blind to see
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
(Ooh, give you up)
(Ooh, give you up)
(Ooh)
Never gonna give, never gonna give
(Give you up)
(Ooh)
Never gonna give, never gonna give
(Give you up)
We've know each other for so long
Your heart's been aching but
You're too shy to say it
Inside we both know what's been going on
We know the game and we're gonna play it
I just wanna tell you how I'm feeling
Gotta make you understand
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
您可以使用我编写的重播程序来测试您的解决方案(注意:它尚不支持“搜索/替换”,其他所有功能都可以使用)。
6
我很乐意看到这样的vim程序。
—
Braden Best
通常,我会使用鼠标来完成部分操作。
—
Victor Stafusa 2014年
很有意思。我早上去; 3
—
cjfaure 2014年
您真的不需要Rick Roll我们,对吗?:)
—
Filip Haglund 2014年
我有点@ B1KMusic。对我来说,生成vimgolf的解决方案会更有趣。(这等效于您仅使用vim命令在此处尝试做的事情。)但这听起来很有趣,但是减少键击非常困难(或者至少我认为是这样),因为很难精确地进行选择。这使得复制和粘贴是一项非常艰巨的任务,并且几乎要进行与您尝试复制的事物相同的击键。(或者至少这是我在阅读复制和粘贴的方式。)而且我看不到其他许多减少按键的方法。
—
FDinoff 2014年