SQL(SQLite),533字节
with m as (select 0 as i, 1 as o union values (0,2),(1,0),(1,2),(1,4),(2,0),(2,1),(2,3),(2,5),(3,2),(3,6),(4,1),(4,5),(4,7),(5,2),(5,4),(5,6),(5,8),(6,3),(6,5),(6,9),(7,4),(7,8),(8,5),(8,7),(8,9),(9,6),(9,8))select o || substr('008', 2, 1) || substr('008', 3, 1)from m where substr('008', 1, 1) = cast(i as text)union select substr('008', 1, 1) || o || substr('008', 3, 1)from m where substr('008', 2, 1) = cast(i as text)union select substr('008', 1, 1) || substr('008', 2, 1) || o from m where substr('008', 3, 1) = cast(i as text)
不打高尔夫球
with m as (
select 0 as i, 1 as o
union
values
/*(0,1),*/(0,2),
(1,0),(1,2),(1,4),
(2,0),(2,1),(2,3),(2,5),
(3,2),(3,6),
(4,1),(4,5),(4,7),
(5,2),(5,4),(5,6),(5,8),
(6,3),(6,5),(6,9),
(7,4),(7,8),
(8,5),(8,7),(8,9),
(9,6),(9,8)
)
select o || substr(s, 2, 1) || substr(s, 3, 1)
from m, t
where substr(s, 1, 1) = cast(i as text)
union
select substr(s, 1, 1) || o || substr(s, 3, 1)
from m, t
where substr(s, 2, 1) = cast(i as text)
union
select substr(s, 1, 1) || substr(s, 2, 1) || o
from m, t
where substr(s, 3, 1) = cast(i as text)
说明
输入是表格上t带有列的单个文本行s。我的理解是根据这个元答案这是可接受的输入形式。可以如下创建输入。
drop table if exists t;
create table t (s text);
insert into t values('555'); -- Your input here
带注释的解决方案
with m as ( -- Using this in the "with" allows us to only type is once
select 0 as i, 1 as o -- The first pair is here and it names the columns
union
values
/*(0,1),*/(0,2),
(1,0),(1,2),(1,4),
(2,0),(2,1),(2,3),(2,5),
(3,2),(3,6),
(4,1),(4,5),(4,7),
(5,2),(5,4),(5,6),(5,8),
(6,3),(6,5),(6,9),
(7,4),(7,8),
(8,5),(8,7),(8,9),
(9,6),(9,8)
)
select o || substr(s, 2, 1) || substr(s, 3, 1) -- concat the first wrong char with two correct chars
from m, t
where substr(s, 1, 1) = cast(i as text) -- when the first char is in the i (input) column from above
union
select substr(s, 1, 1) || o || substr(s, 3, 1)
from m, t
where substr(s, 2, 1) = cast(i as text)
union
select substr(s, 1, 1) || substr(s, 2, 1) || o
from m, t
where substr(s, 3, 1) = cast(i as text)