Last letter-first letter: Difference between revisions
Content added Content deleted
(Small fix in second D program) |
(Improved second D version) |
||
Line 91: | Line 91: | ||
rufflet trapinch haxorus seaking girafarig gabite exeggcute |
rufflet trapinch haxorus seaking girafarig gabite exeggcute |
||
emolga audino</pre> |
emolga audino</pre> |
||
Runtime: about 1.23 seconds. |
Runtime: about 1.23 seconds, dmd compiler. |
||
This is the same program, with some low-level optimizations: |
This is the same program, with some low-level optimizations: |
||
Line 97: | Line 97: | ||
std.typecons, std.exception; |
std.typecons, std.exception; |
||
struct Ref { |
|||
⚫ | |||
ushort index; |
|||
char lastChar, firstChar; |
|||
} |
|||
char lastChar, firstChar; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
foreach (item; items) |
foreach (item; items) |
||
enforce(item.length > 1); |
enforce(item.length > 1); |
||
⚫ | |||
⚫ | |||
foreach (ushort i, item; items) |
foreach (ushort i, item; items) |
||
refs ~= Ref(i, item[0], item[$-1]); |
refs ~= Ref(i, item[0], item[$-1]); |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
} |
|||
// try each item as possible start |
// try each item as possible start |
||
Line 171: | Line 172: | ||
writeln(" ", sol_nsol[0][i .. min(i+7, $)].join(" ")); |
writeln(" ", sol_nsol[0][i .. min(i+7, $)].join(" ")); |
||
}</lang> |
}</lang> |
||
Runtime: about 0. |
Runtime: about 0.67 seconds, dmd compiler. |
||
=={{header|Go}}== |
=={{header|Go}}== |