Uncomment a COBOL program!

66

6

COBOL is a very old language, at the time of writing it is 58 years old. It is so old, in fact, that it has a very interesting quirk: the first six characters of each line are comments.

Why is this, you ask? Well, those 6 characters were intended to be used as line numbers, back in the day where programs weren't completely digital and typed out on a computer.

In addition, the seventh character could only be part of a very small set (it is usually * to comment out the line or a space to separate the line number from the code)

But what if you're on a more digital system, and you just want the raw program?

The comment system

There are two types of comments in COBOL: line comments and the aforementioned "line number" comments.

Uncommenting line numbers is simple: just take the first seven (six plus a single space) characters off each line.

000000 apple
000001 banana
celery donuts

would become:

apple
banana
donuts

Line comments make it a bit more difficult. A line comment is started with an asterisk * placed in the seventh character position on the line, like so:

000323* this is a comment

This is not a line comment:

*00000 this isn't a comment

To uncomment a line comment, just remove the whole line.

An example commented "program":

000000 blah blah
000001* apples
000002 oranges?
000003* yeah, oranges.
000*04 love me some oranges

The uncommented version:

blah blah
oranges?
love me some oranges

In other words, to uncomment a string, remove the first six characters of each line, then return all but the first character of every line that does not begin with a star.

The challenge

Create a program or function that takes a commented program and returns its uncommented variant.

Clarifications

  • Asterisks (*) will never be found anywhere outside the first seven characters on a line (we're not asking you to verify syntax)
  • Each line will always have at least 7 characters.
  • You may assume the seventh character is always an asterisk or a space.
  • Input or output may be a matrix or list.
  • Only printable ASCII characters (plus newline) must be handled.
  • You may output with a trailing newline. You may also assume that the input will have a trailing newline, if you so choose.

Scoring

Since this is , the answer with the least bytes wins!

DISCLAIMER: I do not actually know COBOL and do not claim to. If any of the claims about COBOL I have made in this question are incorrect, I take no responsibility.

LyricLy

Posted 2017-08-24T01:58:00.250

Reputation: 3 313

23Line numbers are not comments. They are a column. Terminology please. – user207421 – 2017-08-24T05:47:38.890

2Your examples all have a space after the *. Is this a coincidence? – Neil – 2017-08-24T10:13:00.373

1@Neil Yes, it is. The eighth character can be anything. – LyricLy – 2017-08-24T10:17:29.793

6Old does not automatically imply bad. I have worked in an Agile COBOL shop. They could do things on the AS/400 we could not do in Java. – Thorbjørn Ravn Andersen – 2017-08-24T12:06:42.370

1Heh... I actually wrote a COBOL CopyBook parser that only works if the fields aren't packed. Just transforms it into JSON key:{key:{key:length,key:length}}. Strips all formatting data and typing data though. – Magic Octopus Urn – 2017-08-24T14:50:56.250

4Can there be a space in the first 6 characters? – None – 2017-08-24T15:30:54.410

Are you assuming no wholly blank lines (just carriage returns)? I feel like that is something that'd be legal and important, but would force people to do a few more null-checks. – Southpaw Hare – 2017-08-24T17:24:03.423

Can you assume that at least one line is not a line comment? – betaveros – 2017-08-24T18:49:29.880

@stanri Yes, there can be. – LyricLy – 2017-08-24T20:20:00.677

@SouthpawHare An empty line would violate the rule that there will always be at least 7 characters in a line. Empty lines do not have to be handled. – LyricLy – 2017-08-24T20:21:24.853

@betaveros You cannot. – LyricLy – 2017-08-24T20:21:51.917

Would it be OK to have the input as an array where the last entry is something like NULL, to indicate end of input? e.g. char** program = { "000000 hello", "000001 world", NULL }; – simon – 2017-08-24T21:36:01.010

@gurka Sure, that's OK. – LyricLy – 2017-08-24T21:38:24.400

@EJP So true. Those of us who actually used punched cards had a strange fondness for our COBOL compilers which strictly enforced the ascending line numbers. – ClickRick – 2017-08-26T09:56:29.897

Is the line number significant, since it defines the order of program lines in COBOL? – Kwebble – 2017-08-26T21:51:14.143

@Kwebble It is not significant. – LyricLy – 2017-08-26T22:14:40.017

1Column 7 in addition to a space, could also contain not only * (asterix) a comment but also - (hyphen) indicating a continuation line and / (forward slash) form feed – Rolf of Saxony – 2017-08-27T06:31:35.000

@ClickRick Sure. I built one. Well it was an option. – user207421 – 2017-08-27T06:51:18.640

Hi Folks! Sorry, I know this is an off-topic comment (feel free to flag it as such)... Does anyone know what happened to the Code Golf sandbox? Is there one, still? – AJFaraday – 2019-09-25T13:22:29.817

Answers

102

COBOL (GnuCOBOL), 191 + 17 = 208 bytes

I "learned" COBOL for this answer, so it's probably not fully golfed.

This is a full program, taking input on what I presume to be standard input and writing to what I presume to be standard output. Perhaps one day I'll return to this and (1) determine whether COBOL has functions and, if so, (2) see whether a function solution would be shorter.

Byte count includes program and compiler flags (-free and -frelax-syntax).

program-id.c.select i assign keyboard line sequential.fd i. 1 l pic X(80). 88 e value 0.open input i perform until e read i end set e to true end-read if not e and l(7:1)<>'*'display l(8:73).

Try It Online

Ungolfed program

program-id. c.

select i assign to keyboard organization line sequential.

fd i.
    1 l pic X(80).
    88 e value 0.

open input i
perform until e
    read i
        end set e to true
    end-read
    if not e and l(7:1) <> '*'
        display l(8:73).

Limitations

The output is, technically speaking, not correct. From my cursory research, it seems the only practical way to store a string in COBOL is in a fixed-size buffer. I have chosen a buffer size of 80 characters, since this is the line length limit for fixed-format programs. This presents two limitations:

  • Lines longer than 80 characters are truncated.
  • Lines shorter than 80 characters are right-padded with spaces.

I'm guessing this is acceptable since, well, it's COBOL. If not, I'd be willing to look into alternatives.

Acknowledgments

  • -166 bytes thanks to Edward H
  • -2 bytes thanks to hornj

Jakob

Posted 2017-08-24T01:58:00.250

Reputation: 2 428

10Asterisks (*) will never be found anywhere outside the first seven characters on a line ... and yet ... ;) – Cœur – 2017-08-24T17:43:40.667

@Cœur Haha yes...but my solution doesn't use that assumption, so maybe it's appropriate! – Jakob – 2017-08-24T17:50:02.913

8You win one internet. – Joshua – 2017-08-25T18:58:47.537

@Cœur except in a COMPUTE statement. – ClickRick – 2017-08-25T19:21:53.953

I think you can remove the program-id. c.. – Kwebble – 2017-08-26T21:58:39.090

@Kwebble Doesn't work in TIO with the current setup. – Jakob – 2017-08-26T23:45:31.793

1Congratulations on your gold badge! – caird coinheringaahing – 2017-12-21T17:25:03.340

20

Python 2, 39 38 37 bytes

-1 byte thanks to LyricLy. -1 byte thanks to Mego.

lambda s:[i[7:]for i in s if'*'>i[6]]

Try it online!

I/O as lists of strings.

totallyhuman

Posted 2017-08-24T01:58:00.250

Reputation: 15 378

2Save a byte by replacing != with <, since a space's code point is lower than an asterisk's one, and the seventh character will always be a space or an asterisk. – LyricLy – 2017-08-24T02:34:08.633

So, the 7th character will always be a space or an asterisk? – totallyhuman – 2017-08-24T02:35:13.300

Yes. You may assume the seventh character is always an asterisk or a space. – LyricLy – 2017-08-24T02:37:42.927

1Save 1 byte with if'*'!=i[6] – Mego – 2017-08-24T02:43:30.183

13

Perl 5, 19 + 1 (-p) = 20 16 bytes

-4 bytes with Pavel's suggestions

s/.{6}( |.*)//s

Try it online!

Xcali

Posted 2017-08-24T01:58:00.250

Reputation: 7 671

2You can save three bytes if you replace (\*.*$| ) with ( |.*) – Pavel – 2017-08-24T06:10:38.597

Not as short as @Pavel's comment, but / /;$_=/\* /?$,:$' is another alternative

– Dom Hastings – 2017-08-24T07:35:01.610

You also don't need the ^. – Pavel – 2017-08-24T07:39:39.910

11

V, 13 11 10 bytes

Î6x<<
çª/d

Try it online!

Explanation

Î       ' On every line
  x     ' delete the first...
 6      ' 6 characters
   <<   ' and unindent the line (removes the leading space)
ç /     ' on every line
 ª      ' matching \*
   d    ' delete the line

Hexdump:

00000000: ce36 783c 3c0a e7aa 2f64                 .6x<<.../d

nmjcman101

Posted 2017-08-24T01:58:00.250

Reputation: 3 274

Couldn't you do 7x instead of 6x<<? – James – 2017-08-24T02:43:29.493

1Then it deletes the * – nmjcman101 – 2017-08-24T02:43:59.853

Would it work to delete the lins with * first and then do Î7x ? (assuming a * can not not in the chars 0-5) – 12431234123412341234123 – 2017-08-28T11:00:47.217

@12431234123412341234123 unfortunately no, because there can be a * in the first 6 characters. – nmjcman101 – 2017-08-28T14:37:22.873

9

Paradoc (v0.2.8+), 8 bytes (CP-1252)

µ6>(7#;x

Takes a list of lines, and results in a list of uncommented lines.

Explanation:

μ        .. Map the following block over each line (the block is terminated
         .. by }, but that doesn't exist, so it's until EOF)
 6>      .. Slice everything after the first six characters
   (     .. Uncons, so now the stack has the 6th character on top
         .. and the rest of the line second
    7#   .. Count the multiplicity of factors of 7 in the character
         .. (treated as an integer, so '*' is 42 and ' ' is 32)
      ;  .. Pop the top element of the stack (the rest of the line)...
       x .. ...that many times (so, don't pop if the 6th character was a
         .. space, and do pop if it was an asterisk)

Hi, I wrote a golfing programming language. :)

I'm still developing this and added/tweaked a bunch of built-ins after trying to write this so that there are more reasonable ways to differentiate between a space and an asterisk than "7#", but I feel like that would make this noncompeting. It's fortunate that it still worked out (this only uses features from v0.2.8, which I committed three days ago).

betaveros

Posted 2017-08-24T01:58:00.250

Reputation: 741

"Hi, I wrote a golfing programming language." Was the version you're using released before or after this challenge was posted? – Mast – 2017-08-24T19:18:55.283

1

It works on this version from three days ago: https://github.com/betaveros/paradoc/releases/tag/v0.2.8

– betaveros – 2017-08-24T19:23:01.010

Right, you mentioned that, but somehow it didn't register explicitly... – Mast – 2017-08-24T19:38:31.963

1

@Mast It doesn't really matter.

– Martin Ender – 2017-08-25T14:09:47.320

7

Octave, 23 bytes

@(s)s(s(:,7)~=42,8:end)

Try it online!

rahnema1

Posted 2017-08-24T01:58:00.250

Reputation: 5 435

4I never knew Octave could do strings like that... Take that, MATLAB. xD – Sanchises – 2017-08-24T07:47:53.337

Since R2016b's introduction of string arrays, I'm pretty sure this would work in MATLAB too @Sanchises! I only have access to R2015b currently so can't confirm though. MATLAB can do it in 74 bytes, probably fewer @(s)cellfun(@(r)r(8:end),s(cellfun(@(r)r(7)~=42,s)),'uniformoutput',false), where s is a cell array, not a string array. Using regexp or something would likely be shorter, but the method I've written is comparable to the methodology in this answer just for old MATLAB

– Wolfie – 2017-08-25T15:51:14.783

6

Jelly, 11 9 bytes

ṫ€7Ḣ⁼¥Ðf⁶

Try it online!

Inputs and outputs as a list of lines.

-2 bytes thanks to @EriktheOutgolfer and @JonathanAllan

How it works

ṫ€7Ḣ=¥Ðf⁶
 €           On each line:
ṫ 7            Replace the line with line[7:]
      Ðf     Keep all lines that meet condition:
     ¥         Dyad:
   Ḣ             First Element (modifies line)
    =            Equals
        ⁶    Space

fireflame241

Posted 2017-08-24T01:58:00.250

Reputation: 7 021

7$€ can be €7 – Erik the Outgolfer – 2017-08-24T09:29:15.903

take it down to 9 like so: ṫ€7Ḣ⁼¥Ðf⁶ – Jonathan Allan – 2017-08-24T12:40:06.050

5

PowerShell, 32 bytes

$input-replace'^.{6}( |.*)'-ne''

Try it online!

Pipeline input comes in as an array of strings, -replace works on every string, and -ne '' (not equal to empty string) applied to an array, acts to filter out the blank lines.

TessellatingHeckler

Posted 2017-08-24T01:58:00.250

Reputation: 2 412

4

C, 63 59 55 48 47 46 bytes

Thanks to "an anonymous user" for getting rid off yet another byte.

Thanks to Felix Palmen for reminding me of "You may assume the seventh character is always an asterisk or a space.", which shaved off one more byte.

f(char**a){for(;*a;++a)(*a)[6]&2||puts(*a+7);}

Use like:

char** program = { "000000 apple", "000001 banana", "celery donuts", 0 };
f(program);

Try it online!

simon

Posted 2017-08-24T01:58:00.250

Reputation: 351

3

Actually, 13 bytes

⌠6@tp' =*⌡M;░

Input and output is done as a list of strings.

Explanation:

⌠6@tp' =*⌡M;░
⌠6@tp' =*⌡M    for each line:
 6@t             discard the first 6 characters
    p            pop the first character of the remainder
     ' =         is it a space?
        *        multiply the string by the boolean - returns the string if true, and an empty string if false
           ;░  filter out empty strings

Try it online!

Mego

Posted 2017-08-24T01:58:00.250

Reputation: 32 998

3

Gaia, 9 bytes

6>¦'*«⁈ḥ¦

A function accepting a list of strings and returning a list of strings.

Try it online!

Explanation

6>¦        Remove the first 6 characters of each string
   '*«⁈    Filter out ones that start with *
       ḥ¦  Remove the initial space from each

Business Cat

Posted 2017-08-24T01:58:00.250

Reputation: 8 927

I count ten characters, and since three are non-ASCII, do they not take more than a byte? – WGroleau – 2017-08-24T06:35:46.470

@WGroleau and « are both 1 character. Out golfing languages that use non-ascii character (maybe except for Neim) use custom encodings, that allow all those non-ASCIIs to be counted as single bytes. Here is Gaia's code page.

– Mr. Xcoder – 2017-08-24T09:19:57.753

@Mr.Xcoder Neim has an encoding too. – Erik the Outgolfer – 2017-08-24T09:58:30.553

3

R, 47 45 bytes

function(x)gsub("(?m)^.{6}( |.*\\n)","",x,,T)

Sven Hohenstein

Posted 2017-08-24T01:58:00.250

Reputation: 2 464

If you take the input as a list of strings I think you can shorten the regex to "^.{6}( |.*$)" for -6. – CriminallyVulgar – 2017-08-24T11:37:49.043

@CriminallyVulgar Correct. In this case, I could also drop the pe=T argument. However, I am not sure whether input as a list of strings is allowed. – Sven Hohenstein – 2017-08-24T12:18:00.437

From the OP: Input or output may be a matrix or list. – totallyhuman – 2017-08-24T13:05:09.543

@CriminallyVulgar The problem is the presence of empty strings in the output. – Sven Hohenstein – 2017-08-24T13:24:14.587

@SvenHohenstein Ah of course, I hadn't considered that. – CriminallyVulgar – 2017-08-24T14:57:30.710

@Giuseppe Thanks for the hint. – Sven Hohenstein – 2017-12-13T18:59:05.243

3

Pyth, 9 bytes

Note that this only works if at least 1 line is not a comment and at least 1 line is a comment. All the other solutions work in all cases.

-2 bytes thanks to @pizzakingme!

m>d7.m@b6

Try it here!

Explanation

m>d7.m@b6     - Full program with implicit input. Takes input as a list of Strings.

m>d7          - All but the first 7 letters of 
    .m   (Q)  - The input, filtered for its minimal value using the < operator on
      @b6     - the 7th character -- note that "*" is greater than " "
              - Implicitly Output the result.

Pyth, 11 bytes

tMfqhTdm>d6

Try it here!

Explanation

tMfqhTdm>d6 - Full Program with implicit input. Takes input as a list of Strings.

       m>d6 - Remove the first 6 characters of each line.
    hT      - Get the first character of each.
  fq  d     - Keep those that have the first character an asterisk.
tM          - Remove the first character of each.
            - Output Implicitly.

Pyth, 11 bytes

m>d7fqd@T6Q

Try it here!

Explanation

m>d7fq@T6dQ  - Full program. Takes input as a list of Strings.

      @T6    - The sixth character of each.
    fq   dQ  - Keep the lines that have a space as ^.
m>d7         - Crop the first 7 characters.
             - Output implicitly.

Pyth, 12 bytes

tMfnhT\*m>d6

Try it here!

Explanation

tMfnhT\*m>d6 - Full Program with implicit input. Takes input as a list of Strings.

        m>d6 - Remove the first 6 characters of each line.
    hT       - Get the first character of each.
  fn  \*     - Filter those that aren't equal to an asterisk.
tM           - Remove the first character of each.
             - Output Implicitly.

Pyth, 12 bytes

m>d7fn@T6\*Q

Try it here!

Explanation

m>d7fn@T6\*Q  - Full program. Takes input as a list of Strings.

      @T6     - Get the sixth character of each string
    fn   \*Q  - And filter those that aren't equal to an asterisk.
m>d7          - Crop the first 7 characters.
              - Output implicitly.

Mr. Xcoder

Posted 2017-08-24T01:58:00.250

Reputation: 39 774

"Keep those that have the first character an asterisk." I think you meant "Keep those of which the first character is NOT an asterisk." – Kevin Cruijssen – 2017-08-24T13:25:10.657

m>d7.m@b6 should work at 9 bytes, abusing that * is after space in lexicographical order – Dave – 2017-08-24T13:27:07.927

I can edit it in with explanation / test link if you want! – Dave – 2017-08-24T13:36:02.840

@pizzakingme I'd be glad if you would edit in, because I am on mobile. Thanks a lot and don't forget to credit yourself for the new solution! – Mr. Xcoder – 2017-08-24T13:40:56.007

Does this work if all lines are line comments? (I'm not sure if you have to handle this case) – betaveros – 2017-08-24T18:50:30.260

@betaveros All the solutions except for the 9-byter work in that case. I will add the remark. – Mr. Xcoder – 2017-08-24T18:51:56.340

3

Haskell, 27 25 bytes

Laikoni's version is shorter than mine:

f n=[x|' ':x<-drop 6<$>n]

Try it online!

My version:

f n=[drop 7x|x<-n,x!!6<'*']

Try it online!

jferard

Posted 2017-08-24T01:58:00.250

Reputation: 1 764

25 bytes: f n=[x|' ':x<-drop 6<$>n]. – Laikoni – 2017-08-24T17:24:57.083

@Laikoni That's nice!! I didn't know it was possible to match patterns in a generator of a list comprehension. – jferard – 2017-08-24T19:43:58.083

3

C (gcc), 53 48 46 bytes

x;main(y){for(y=&x;gets(y-6);x&2||puts(y+1));}

Try it online!

-5 bytes: It was very tricky to get this "whole program" down to the same size as gurka's function. It's now writing out of bounds (in both directions) of an array of wrong type and relies on little endian and 4 byte integers to find the asterisk ... but hey, it works ;)

-2 bytes: Well, if we already write to some "random" .bss location, why bother declaring an array at all! So here comes the string handling program that uses neither the char type nor an array.

Felix Palmen

Posted 2017-08-24T01:58:00.250

Reputation: 3 866

Nice! And the *x&2 made me remember "You may assume the seventh character is always an asterisk or a space.", so I should be able to shave some bytes off my answer :-) – simon – 2017-08-25T18:56:45.097

@gurka thanks :D -2, hehe – Felix Palmen – 2017-08-26T05:39:12.600

3

Java 8, 40 bytes

Regular expressions: just about, but not quite, the wrong tool for the job. Lambda from String to String (assign to Function<String, String>). Input must have a trailing newline.

s->s.replaceAll("(?m)^.{6}( |.*\\n)","")

Try It Online

Acknowledgments

Jakob

Posted 2017-08-24T01:58:00.250

Reputation: 2 428

The right tool! :) – Olivier Grégoire – 2017-08-25T08:41:11.827

3

GNU Sed, 19 + 2 = 21 characters

Requires -E argument to sed to enable extended regular expressions.

/^.{6}\*/d;s/^.{7}/

Daniel Schepler

Posted 2017-08-24T01:58:00.250

Reputation: 1 001

you could do the same thing as the perl guy, s/^.{6}( |.*)//g – markasoftware – 2017-08-24T21:01:44.857

3

Vim, 14 bytes

Ctrl-VG5ld:%g/\*/dEnter

Loading the input file as the buffer to edit, then enter the above commands. Output is the new buffer.

David Heyman

Posted 2017-08-24T01:58:00.250

Reputation: 151

3

SNOBOL4 (CSNOBOL4), 72 70 66 50 bytes

R	INPUT POS(6) (' '  REM . OUTPUT | '*') :S(R)
END

Try it online!

Pattern matching in SNOBOL is quite different from regex but the idea here is still the same: If a line matches "six characters and then an asterisk", remove it, otherwise, remove the first seven characters of the line and print the result.

This now actually takes better advantage of SNOBOL's conditional assignment operator.

The pattern is POS(6) (' ' REM . OUTPUT | '*') which is interpreted as:

Starting at position 6, match a space or an asterisk, and if you match a space, assign the rest of the line to OUTPUT.

Giuseppe

Posted 2017-08-24T01:58:00.250

Reputation: 21 077

2

Ruby, 39 38 36 29 23 22 20 + 1 = 21 bytes

$_[/.{6}( |.*
)/]=''

Try it online!

Uses -p flag.

Explanation:

The -p flag adds an implicit block around the code, so the code that actually gets run looks like this:

while gets
    $_[/.{6}( |.*
)/]=''

    puts $_
end

gets reads a line of text and stores its result in $_.

$_[/.../]='' removes the first occurence of the regex ... in $_.

/.{6}( |.*\n)/ matches 6 of any character at the start of a line, followed by either a space or the rest of the line. Because the space appears first, it will try to remove only the first 6 characters and a space before attempting to remove the entire line.

$_ is then printed out, and this process is repeated for each line.

Pavel

Posted 2017-08-24T01:58:00.250

Reputation: 8 585

1Method calls in Ruby don't need parentheses, removing them will save you a byte. – m-chrzan – 2017-08-24T03:07:43.357

2

Retina, 23 15 bytes

5 bytes saved thanks to nmjcman101
1 byte saved thanks to Neil

m`^.{6}( |.*¶)

Try it online!

user72349

Posted 2017-08-24T01:58:00.250

Reputation:

2

C#, 160 145 90 89 bytes

t=>{var o="";foreach(var s in i.Split('\n'))if(s[6]!=42)o+=s.Substring(7)+"\n";return o;}

Thanks to Pavel & auhmaan for reducing the size.

snorepion

Posted 2017-08-24T01:58:00.250

Reputation: 43

Welcome to PPCG! I would suggest adding a try it online link to your answer so that others can test your code. Besides that, great first (well, second) answer!

– LyricLy – 2017-08-24T03:52:17.833

You can make this shorter by writing a lambda in the form t=>{...} – Pavel – 2017-08-24T05:46:11.773

@LyricLy I tried doing that, actually, but for some reason, this doesn't work there. It works perfectly fine in a VS console app, though. – snorepion – 2017-08-24T13:07:41.007

@Pavel Like so? I'm not sure if I did it completely correctly; I've never needed to use a lambda expression before. – snorepion – 2017-08-24T13:08:34.920

Yes, exactly. You can test it by assigning it to a func<string, string>. – Pavel – 2017-08-24T16:36:00.790

You can make it 90 bytes long: i=>{var o="";foreach(var l in i.Split('\n'))if(l[6]!=42)o+=l.Substring(7)+"\n";return o;}; – auhmaan – 2017-08-24T16:44:30.203

Why is there a trailing semicolon outside the lambda body? This is not a statement. It can only possibly be an expression. – recursive – 2017-09-22T21:30:12.243

delegate string y;y s=[my code...] This requires a semicolon after it and that is how I tested it. The semicolon is a remnant of testing. – snorepion – 2017-09-22T22:57:25.547

2

Pyke, 9 bytes

36 4C 3E 23 64 DE 29 6D 74

Try it here!

Readable:

6L>#d.^)mt

Try it here!

6L>        -   [i[6:] for i in input]
   #d.^)   -  filter(i.startswith(" ") for  i in ^)
        mt - [i[-1:] for i in ^]

Blue

Posted 2017-08-24T01:58:00.250

Reputation: 26 661

2

JavaScript (ES6), 48 bytes

s=>s.map(c=>c[6]<"*"?console.log(c.substr(7)):1)

Try it online!

sgtdck

Posted 2017-08-24T01:58:00.250

Reputation: 131

1This is neither a function, nor a full program as it assumes the input is stored in z, which isn't allowed here. You could however turn it into an anonymous arrow function, in order to make it valid. – caird coinheringaahing – 2017-08-27T11:35:16.857

1@cairdcoinheringaahing you're absolutely right. Updated the solution - not sure what the rules are regarding the ( and ) surrounding the fn, added them to be sure. – sgtdck – 2017-08-27T13:03:50.757

1You don't need the () around the function, but otherwise it looks fine. – caird coinheringaahing – 2017-08-27T13:06:03.307

2

><>, 57 53 Bytes

>i~i~i~i~i~i~i67*=\
<o$/?:$/?=a:;?(0:i<
\~$/~\ $
/  <o\?/

try it online

Explanation

>i~i~i~i~i~i~i67*=    Read in the first seven bytes of the line
 i~i~i~i~i~i~         Read, and discard 6 characters
             i        Read the seventh
              67*=    Check if the seventh character was an 
                      asterisk (and leave that value on the stack );

<o$/?:$/?=a:;?(0:i<    Read characters until a newline or eof
                 i     Read the next character of the line
            ;?(0:      If it's a -1, terminate the program
       /?=a:           If it's a newline, break out of the loop
   /?:$                If the seventh character was not an asterisk
<o$                    Output this character
\~$/                   otherwise discard it

   /~\ $    Having reached the end of the line, output
/  <o\?/    the newline only if it was not a comment

Edit: 53 bytes

>   i~i~i~i~i~i~i67*=\
/?=a<o/?$@:$@:$;?(0:i<
~   \~/

Basically the same stuff as before, but restructured slightly

As a side note: I'm disappointed no-one's done this in cobol yet.

Sasha

Posted 2017-08-24T01:58:00.250

Reputation: 431

2

Python 3, 71 bytes (no regexp)

def f(s):
 for w in s.split('\n'):
  t=w[6:]
  if t[0]!='*':print(t[1:])

It works!

>>> s="""000000 blah blah
000001* apples
000002 oranges?
000003* yeah, oranges.
000*04 love me some oranges"""
>>> f(s)
blah blah
oranges?
love me some oranges

Sagittarius

Posted 2017-08-24T01:58:00.250

Reputation: 169

1

JavaScript, 44 34 bytes

Crossed-out 44 is still regular 44.

6 bytes saved thanks to tsh

a=>a.replace(/^.{6}( |.*\n)/gm,'')

Try it online!

user72349

Posted 2017-08-24T01:58:00.250

Reputation:

s=>s.replace(/^.{6}( |\*.*\s)?/mg,'') – tsh – 2017-08-24T02:44:34.767

s.match(/(?<=^.{6} ).*/mg) ESNext (Nonstandard, Stage3) Chrome62+ – tsh – 2017-08-24T02:52:14.913

@tsh. Until there is a stable interpreter which allows it, I suppose it doesn't count as a valid programming language. – None – 2017-08-24T03:02:08.807

It doesn't seem like this gives the correct output if the last line is a comment line. – LyricLy – 2017-08-24T03:42:57.850

@LyricLy. It is because I assumed that input will always contain a trailing new line. You can see that it works is there is an empty line after the input. If I should not assume it, then fix will cost 1 byte (adding ? after \n).

– None – 2017-08-24T03:55:41.597

Ah. That makes sense. Yes, assuming a trailing newline on the input is fine. – LyricLy – 2017-08-24T03:57:21.550

1

Japt, 11 10 bytes

Takes input as an array of strings and outputs an array of strings.

k_g6 x
®t7

Test it (-R flag for visualisation purposes only)

  • Saved a byte thanks to ETH.

Explanation

Implicit input of array U.

f_

Filter (f) by passing each element through a function.

g6

Get the character at index (g) 6 (0-indexed).

x

Trim, giving either * (truthy) or an empty string (falsey).

®t7

Map (®) over the array and get the substring (t) of each element from the 7th character. Implicitly output the resulting array.

Shaggy

Posted 2017-08-24T01:58:00.250

Reputation: 24 623

think the first line can be k_g6 x – ETHproductions – 2017-08-24T21:09:45.127

@ETHproductions: Today was not a good day's golfing for me - I was playing around with solutions using x, as seen in my alt. solution, and I still didn't twig that! Thanks once again :) – Shaggy – 2017-08-24T23:15:35.250

1

05AB1E, 11 bytes

|ʒ6èðQ}ε7F¦

Try it online!

Erik the Outgolfer

Posted 2017-08-24T01:58:00.250

Reputation: 38 134

10 bytes: |ε6.$ćðQi,

– Grimmy – 2019-09-25T12:59:10.357

@Grimy Heh, .$ didn't exist back then. :P – Erik the Outgolfer – 2019-09-25T13:13:32.527

1

C++ (GCC), 121 112 bytes

Thanks to @gurka for saving 9 bytes!

#import<bits/stdc++.h>
void f(std::list<std::string>l){for(auto s:l)if(s[6]-42)std::cout<<s.substr(7,s.size());}

Takes input as a list of lines.

Try it online!

Steadybox

Posted 2017-08-24T01:58:00.250

Reputation: 15 798

#import? Also, I think that it's OK to omit standard includes. – simon – 2017-08-24T14:05:30.863

#import isn't standard C++, but at least GCC and MSVC support it. Omitting some includes works with C, but not with C++. The code doesn't work without the includes, so they have to be counted in the total bytecount. – Steadybox – 2017-08-24T14:15:17.813

Aha, I thought you could just skip includes since you don't see any import in python answers or using in C# answers. Also, wouldn't #include <bits/stdc++.h> be shorter for your answer? – simon – 2017-08-24T14:26:28.173

@gurka Yes, it would be shorter. Thanks! – Steadybox – 2017-08-24T14:53:05.313

@gurka the imports are counted in Python answers, it's just that Python has a lot of functions that don't need importing. C# tends to not have using statement because it's generally shorter to write system.foo() than using system;foo() – Pavel – 2017-08-24T19:45:20.423

bits/stdc++.h is not a standard header and thus is not "C++". You must specify a compiler and/or standard library implementation. – Cody Gray – 2017-08-25T01:41:47.560

1

Java 8, 95 54 53 bytes

s->s.filter(x->x.charAt(6)<33).map(x->x.substring(7))

-42 bytes thanks to @OliverGrégoire, by using a Stream<String> instead of String as in- and output.

Explanation:

Try it here.

s->                          // Method with Stream<String> as parameter and return-type
  s.filter(x->x.charAt(6)<33)//  Filter out all lines containing an asterisk as 7th char
   .map(x->x.substring(7))   //  And remove the first 7 characters from the remaining lines
                             // End of method (implicit / single-line body)

Kevin Cruijssen

Posted 2017-08-24T01:58:00.250

Reputation: 67 575

Looks like you can use a String[] or List<String> as input for -12 bytes. – Jakob – 2017-08-24T17:06:02.387

Or Stream<String> if that can help. Example : s->s.map(x->x.charAt(6)!=42?x.substring(7):"") – Olivier Grégoire – 2017-08-24T23:28:30.983

1Oh, it's needed to filter... then s->s.filter(x->x.charAt(6)!=42).map(x->x.substring(7)) for 54 bytes. – Olivier Grégoire – 2017-08-25T07:28:18.470

@OlivierGrégoire Could you provide a TIO regarding the input? java.util.Arrays(the_string_array).stream() it should be, right? – Kevin Cruijssen – 2017-08-25T08:27:14.303

java.util.Arrays.stream(yourStringWithNewLines.split("\n")) – Olivier Grégoire – 2017-08-25T08:28:11.200

Okay, you're aware of this, you're likely making the changes right now. I'll leave soon, so I can +1 before I forget. ;) – Olivier Grégoire – 2017-08-25T08:45:04.617

1Use <42 instead of !=42 because "You may assume the seventh character is always an asterisk or a space." – Olivier Grégoire – 2017-08-25T10:15:23.117

1@OlivierGrégoire Ah, missed that rule, otherwise I would have done so myself. Thanks for the correction. – Kevin Cruijssen – 2017-08-25T12:08:50.733

1

TeX - 139 bytes

\let~\def~\a#1#2#3#4#5#6{\b}~\d#1{\catcode`#1=12}\obeylines\d\ ~\b#1#2
{\if#1*\else\write1{#2}\fi\egroup
}\everypar{\bgroup\d\\\d\{\d\}\a}

Eats up the first six characters of each line, then checks if the next one is an asterisk or something else. Recurses over lines by eating up anything that tries to get typeset. The rest of my bytes are spent on changing category codes of syntax related characters so it's robust.

A Gold Man

Posted 2017-08-24T01:58:00.250

Reputation: 280

1

Javascript, 37 bytes

Regexp-based solution

s=>s.replace(/^.{6}( |(\*.+$\n?))/gm,'')

FliiFe

Posted 2017-08-24T01:58:00.250

Reputation: 543

1

Zsh, 29 bytes

try it online!

((##${1[7]}<42))&&<<<${1:7:$}

Checks the ascii value of the 7th character.

roblogic

Posted 2017-08-24T01:58:00.250

Reputation: 554

0

J, 20 bytes

7&}."1(#~'*'~:6&{"1)

This assumes the input is a matrix of equal-length space-padded lines.

Gregory Higley

Posted 2017-08-24T01:58:00.250

Reputation: 395

0

PHP, 50 bytes

foreach(file(C)as$s)$s[6]>" "||print substr($s,7);

same length:

foreach(file(C)as$s)$s[6]^a^q||print substr($s,7);
foreach(file(C)as$s)$s[6]^b^x&&print substr($s,7);
foreach(file(C)as$s)echo$s[6]^b^x?substr($s,7):"";

regex solution, 51 bytes:

<?=join(preg_filter("#^.{6} (.*)$#","$1",file(C)));

builtins only, 108 bytes:

<?=join(array_map(function($s){return substr($s,7);},array_filter(file(C),function($s){return$s[6]^b^x;})));

take code from a file named C. Run with -nr or try them online.

Titus

Posted 2017-08-24T01:58:00.250

Reputation: 13 814

0

CJam, 13 bytes

{{6>'*#},7f>}

Try it online!

Explanation:

{           }  e# Block. Input:                ["000000 blah blah" "000001* apples" "000002 oranges?" "000003* yeah, oranges."]
 {     },      e# Filter on the following:
  6>           e#   Remove first 6 characters: [" blah blah" "* apples" " oranges?" "*yeah, oranges"]
    '*#        e#   Find a '*':                [-1 0 -1 0]
               e# End filter:                  ["000000 blah blah" "000002 oranges?"]
         7f>   e# Remove first 7 characters:   ["blah blah" "oranges?"]

Esolanging Fruit

Posted 2017-08-24T01:58:00.250

Reputation: 13 542

0

Implicit, 22 bytes

('\6¯_0=`*!{]\1%ß1}]^ö

No explanation, sorry. I forgot how this works.

MD XF

Posted 2017-08-24T01:58:00.250

Reputation: 11 605

0

Jq 1.5, 24 bytes

select(.[6:]<"*")|.[7:]

Explanation

  select(.[6:] < "*")          # discard if '*' in column 7
| .[7:]                        # keep remaining portion

Sample run with paste to show input vs output

$ paste input <(jq -MRr 'select(.[6:]<"*")|.[7:]' input)
000000 blah blah                blah blah            
000001* apples                  oranges?                    
000002 oranges?                 love me some oranges 
000003* yeah, oranges.          
000*04 love me some oranges

$ wc -c <<<'select(.[6:]<"*")|.[7:]'
      24

Try it online

jq170727

Posted 2017-08-24T01:58:00.250

Reputation: 411

0

Pyth - 15

V.z*.DNU7n@N6\*

Explanation:

V.z*.DNU7n@N6\*
V.z              For each line N in input
                  Print
     N             N
   .D U7           but with characters 0-6 removed
  *                times
          @N6       Item six of N
         n          Does not equal
             \*     "*"

Tornado547

Posted 2017-08-24T01:58:00.250

Reputation: 389