Code Golf: Ghost Leg
Posted
by Anax
on Stack Overflow
See other posts from Stack Overflow
or by Anax
Published on 2010-04-27T13:18:25Z
Indexed on
2010/04/28
8:23 UTC
Read the original article
Hit count: 224
The challenge
The shortest code by character count that will output the numeric solution, given a number and a valid string pattern, using the Ghost Leg method.
Examples
Input: 3, "| | | | | | | | |-| |=| | | | | |-| | |-| |=| | | |-| |-| | |-|" Output: 2 Input: 2, "| | |=| | |-| |-| | | |-| | |" Output: 1
Clarifications
- Do not bother with input. Consider the values as given somewhere else.
- Both input values are valid: the column number corresponds to an existing column and the pattern only contains the symbols
|
,-
,=
(and [space], [LF]). Also, two adjacent columns cannot both contain dashes (in the same line). - The dimensions of the pattern are unknown (min 1x1).
Clarifications #2
- There are two invalid patterns:
|-|-|
and|=|=|
which create ambiguity. The given input string will never contain those. - The input variables are the same for all; a numeric value and a string representing the pattern.
- Entrants must produce a function.
Test case
Given pattern: "|-| |=|-|=|LF| |-| | |-|LF|=| |-| | |LF| | |-|=|-|" |-| |=|-|=| | |-| | |-| |=| |-| | | | | |-|=|-| Given value : Expected result 1 : 6 2 : 1 3 : 3 4 : 6 5 : 5 6 : 2
© Stack Overflow or respective owner