# ASCII-art to numbers

Inspired by Digits in their lanes

## Input:

An ASCII-art of width ≤ 11, consisting of spaces and #. (You can choose any two distinct characters instead.) Example:

     #
###
#
#
# #
#   #
#     #
#  ###  #
#   ###   #
###########
#         #
#         #
#   ###   #
#   ###   #
#   ###   #
###########


## Output:

A list of integers, with one element for each line of the input. If you put a hash in each decimal digit's lane, including the minus sign, in the order -0123456789. Duplicated digits are allowed, but ignored. The order of the digits in the output is not important. Possible outputs for the above input include:

[ 4, 345, 4, 4, 35, 26, 17, 34580, -3459, -9876543210, -9, -9, -3459, -3459, -3459, -1234567890 ]
[ 4444444, 5345354354, 4, 44, 535, 2666, 71, 85430, -3495939495, -93678132645160234, -99, -99999, -934539, -935439, -9534, -9876543210 ]


Note that you have to distinguish between 0 and -0. If your output format doesn't support that, you can say there is a special value for -0 (e.g. None).

If a number is 0 (or -0), the zero is always counted.

Else, you have to move the zero after the first digit (not necessarily next to it): For example, -09 stands for - and 9, so you have to output -90 instead. So, even if you output the string "-09" where -, 0 and 9 are #, that is not right.

• In your output, leading zeroes are not counted (that is, the output is the same as if those leading zeroes are removed). This does also include zeroes directly after the minus signs.

• Here are some examples for clarification:

-0123456789    OK           not OK
##          -> -0
###         -> -10          -01
##        # -> -90          -09
##         -> 10           01
#         -> 01           10

• This does also apply when you output a string!

## General rules

• You can assume that in every line, at least one of 0-9 is a # (not empty or only -)
• You can submit a program or function
• Choose any reasonable input/output format (eg. list of lines, list of characters, etc.)

## Scoring

• Lowest score wins.

## Examples

Note that there is an infinite number of correct outputs for every input, here, only one is mentioned. If you need to verify an output, you can usually use an answer to Digits in their lanes and input your output. Then compare it's output with the original input.

     #         4
###        345
#         4
#         4
# #        35
#   #       26
#     #      17
#  ###  #     83450
#   ###   # -> -9534
###########    -9876543210
#         #    -9
#         #    -9
#   ###   #    -3459
#   ###   #    -3459
#   ###   #    -3459
###########    -1234567890

#########     123456780
#         #    -9
#  ##  ## #    -23679
# #   #   #    -159
# #   # # #    -1579
#  ##  ## # -> -23679
#         #    -9
##### ###     12346780
##        45
#         4

##   ##  ##    -45890
# # #   #      -137
##  #   #   -> -370
#   #   # #    -379
#    ##  ##    -4589

## ## ## ##    -2356890
#  #     ## -> -289
#  #           -2

##             -0
##            10
##           12
##          23
##      -> 34
##        45
##       56
##      67
##     78
##    89

• Why the minus sign? – fəˈnɛtɪk Apr 3 '18 at 15:09
• @fəˈnɛtɪk Well .. Digits in their lanes includes it ... – wastl Apr 3 '18 at 15:11
• Is -09 allowed when -9 is required? – l4m2 Apr 3 '18 at 15:53
• @l4m2 Yes, it is – wastl Apr 3 '18 at 15:54
• Is a list of digits allowed in place of a list of characters for input? – dylnan Apr 3 '18 at 18:44

# Stax, 11 bytes

ñ╬ü+U☻T→╡aN


Run and debug it

Unpacked, ungolfed, and commented, it looks like this.

m           for each line of input, run the rest and implicitly output
|(        rotate string left once
:A        get indices of maxima (indices of '#')
Vd'-+s    push "0123456789-" under the top of the stack
@         get characters at indices
r         reverse string; puts '-' at the front
output is implicit


Run this one

# Jelly, 13 bytes

...turns out it's slightly different to Dylnan's method, I thought they just beat me to it

ṙ€1T€ịØD;”-¤U


A monadic link accepting a list of lists of 1s and 0s which returns a list of lists of characters the output "numbers".

Try it online!

### How?

ṙ€1T€ịØD;”-¤U - Link: list of lists of integers (in {0,1})
ṙ€1           - rotate €ach list left by one
T€         - get the truthy (1-based) indices of €ach
ØD      -   decimal digit characters = "0123456789"
”-   -   literal '-' character
;     -   concatenate
ị        - index into (vectorises)
U - upend (reverses each resulting list of characters)

• OP commented on my answer, verbatim, that "No, this is not allowed (Specs: So, even if you output the string "-09" where -, 0 and 9 are #, that is not right)". I'm not sure if this answer is invalid too because of this. – Erik the Outgolfer Apr 3 '18 at 20:41
• This never outputs -09 – Jonathan Allan Apr 3 '18 at 20:45
• Yes, this one is correct. – wastl Apr 3 '18 at 20:54

# Perl 5-lp, 35 bytes

Uses # and ;

#!/usr/bin/perl -lp
s/./"$&@--1"/eeg;s/-1/-/;s;0(.);$+0


Try it online!

• Specs: So, even if you output the string "-09" where -, 0 and 9 are #, that is not right. – wastl Apr 3 '18 at 20:46
• @wastl I made the minimal fix to conform to the spec. I'll think about regolfing later – Ton Hospel Apr 3 '18 at 21:56

# 05AB1E, 18 17 bytes

Currently 3 bytes to make sure the number doesn't start with zero. Looking for a shorter way.

vžh'-ìyƶ0K<ΣΘ}èJˆ


• Fails for line 9 (leading zeroes do not count!) – wastl Apr 3 '18 at 15:52
• Maybe output the numbers reverse? – l4m2 Apr 3 '18 at 15:54
• @wastl: Missed that requirement. Fixed now. – Emigna Apr 3 '18 at 16:11
• Now, it seems to fail for asymmetrical input (I have no idea of 05AB1E, but probably you are reversing the input?) – wastl Apr 3 '18 at 16:43
• @wastl: Yeah, messed up the golf. I've gone back to the 18-byter again :( – Emigna Apr 3 '18 at 17:23

# APL+WIN, 58 bytes

Prompts for a character matrix:

(⊂[2]z[;1],⌽0 1↓z←' -0123456789'[1+n×(⍴n←⎕='#')⍴⍳11])~¨' '


Outputs digits in reverse order to cope with leading zeros.

# Jelly, 20 14 bytes

ØD”-;ẋ"Ð€ṙ€1Ṛ€


Try it online!

Function submission. Takes a list of lines as input. Characters are 1 for on and 0 for off.

Explanation

ØD”-;ẋ"Ð€ṙ€1Ṛ€
ØD               Digits 0-9 as characters
”-             Character literal -
;            Concatenate -> -0123456789
Turn each 0 and 1 from the input (characters) into an integer.
Ð€        For each list of integers 0 and 1 corresponding to the list of lines in the input...
"          Zip the characters -0123456789 with the 0s and 1s.
ẋ           Include each of the characters if paired with a 1, not if paired with a 0.
Characters that get included turn into ['3'] (3 as an example)
Those that don't turn into []. This is important for the next step.
€      For each of the lists of [character]s and []s.
ṙ 1     rotate it by 1. This moves the ['-'] or [] in place of ['-'] to the end of the line.
Ṛ€   Reverse €ach line. Brings the ['-'] to the front and the leading ['0'] if present to the end.

• Oh, very similar to mine, I did not notice. I'm questioning the need for V€€ by the way - it says "reasonable" which is a little subjective... (see my deleted post) – Jonathan Allan Apr 3 '18 at 18:40
• Ṛ€ may be replaced by U :) – Jonathan Allan Apr 3 '18 at 18:41
• @JonathanAllan Hmm I'll consider taking V€€ out. I'll ask OP about that. Unfortunately since each character is wrapped in a list U skips past the list of lines level and doesn't do anything here. – dylnan Apr 3 '18 at 18:44
• List of numbers is OK (05AB1E answer uses it too) – wastl Apr 3 '18 at 18:45
• Ah our methods differ - I used the "truthy" atom: ṙ€1T€ịØD;”-¤U – Jonathan Allan Apr 3 '18 at 18:45

# JavaScript (ES7), 60 55 bytes

Takes input as an array of strings with 0 instead of #. Returns an array of strings.

a=>a.map(r=>('-'+2**67).replace(/./g,c=>[c[r[++c|0]]]))


Try it online!

### Commented

a =>                    // given the input array a[]
a.map(r =>            // for each row r of a[]
('-' + 2**67)       //   generate the string '-147573952589676410000'
.replace(/./g, c => //   replace each character c of r with either c or ''
[                 //     wrap the result into [] so that undefined is coerced to ''
c[               //     read c['0'] (gives c) or c[' '] (gives undefined)
r[             //     read r[] --> gives '0' or ' '
++c | 0]]]   //     gives (NaN | 0) = 0 if c is '-', or (c + 1) if c is a digit
)                   //   end of replace()
)                     // end of map()

• Your code seems to work, but if you scroll down the test cases, you can see that your last one is longer, and there is an additional one – wastl Apr 3 '18 at 16:55
• @wastl Oops... Fixed :) – Arnauld Apr 3 '18 at 17:01

# Java 10, 176 136 bytes

c->{int l=c.length,i=0,j;var o=new String[l];for(String s;i<l;o[i]=c[i++][0]<8?"-"+s:s)for(s="",j=10;j>0;)s+=c[i][j--]<8?j:"";return o;}


Returns an array of Strings. Uses the BEL character instead of #.

Try it online here.

Thanks to Kevin Cruijssen for golfing 40 bytes.

Ungolfed version:

c -> { // lambda taking a char[][] as argument
int l = c.length, // the number of lines
i = 0, //used for iterating over all lines
j; // used for iterating over each line
var o = new String[l]; // output array
for(String s; // the output for the current line
i < l; // iterate over all lines
o[i] = c[i++][0] < 8 ? "-"+s : s) // add a minus if necessary
for(s = "", j = 10; j>0; ) // to avoid leading zeroes, we step through the line backwards
s += c[i][j--] < 8 ? j : ""; // append the next digit, if applicable
}
return o; // return the output array
}


# Python 2, 74 bytes

lambda s:[''.join(i-1[0]for i in[0]+range(10,0,-1)if' '<l[i])for l in s]


Try it online!

# Perl 6, 54 bytes

{.map:{(.ords.grep(:k,*>32)X-1).sort(1/*)>>.ord.chrs}}


Try it online!

Takes a list of lines. Explanation:

{
.map:{                     # For each line.
(.ords.grep(:k,*>32)   # Find non-whitespace indices.
X- 1)                 # Decrement each, range is now -1..9.
.sort(1/*)             # Sort by reciprocal, moving 0s to the end.
>>.ord.chrs            # Join first characters.
}
}

• You can save a byte if you use a lower character instead of space (e.g. \t) – wastl Apr 3 '18 at 18:03

# R, 83 bytes

for(i in gregexpr("#",readLines()))cat(sub(99,0,sort(c("-",99,1:9)[i])),'
',sep="")


Try it online!

A nasty 83 bytes; would have been so much shorter (and simpler of a challenge, I suppose) to not have to move the 0 to the end. Ah well. Uses 99 in place of 0 to utilize sort to move 0 to the end, but that comes at the cost of having to use sub.

using System.Linq;l=>l.Select(k=>{var c=k[0]!=' '?"-":"";for(int a=k.Length;a>1;a--)if(k[a-1]!=' ')c+=$"{a-2}";return c;});  Try it online! # Retina 0.8.2, 34 bytes (.)(.*)$2$1 -(?=.)$.%

%O^$.  Try it online! Takes input using -s instead of #s, but the linked header includes the substitution. Explanation: (.)(.*)$2$1  Move the first character of each line to the end. -(?=.)$.%


Replace each - not at the end of a line with its column number.





Delete the spaces.

%O^\$.


Reverse each line.