| Bytes | Lang | Time | Link |
|---|---|---|---|
| 271 | Bespoke | 250814T070332Z | Josiah W |
| 095 | brainfuck | 250306T121912Z | 鳴神裁四点一号 |
| 011 | Uiua | 241019T223519Z | nyxbird |
| 018 | APL | 241018T121159Z | Ven |
| 094 | Rockstar | 230622T103602Z | Shaggy |
| 052 | Erlang | 230621T203418Z | don_aman |
| 029 | sed 4.2.2 | 230621T204004Z | Yelp |
| 010 | Thunno 2 N | 230621T172036Z | The Thon |
| 035 | Zsh builtins only | 190907T133756Z | roblogic |
| 084 | GFortran | 211112T053726Z | roblogic |
| 039 | Pure Bash | 221119T231526Z | 鳴神裁四点一号 |
| nan | AWK | 220909T083704Z | 鳴神裁四点一号 |
| 028 | K ngn/k | 221108T141933Z | oeuf |
| 023 | APL | 221108T003540Z | Sebastia |
| 012 | Pyth | 221108T071145Z | hakr14 |
| 019 | Knight v2 | 221108T061942Z | EasyasPi |
| 277 | Scratch | 221108T025252Z | badatgol |
| 068 | C++ gcc | 221107T184920Z | c-- |
| 122 | Pascal | 221107T202752Z | Kai Burg |
| nan | Pure Bash | 211111T125209Z | user1004 |
| 116 | CLCINTERCAL | 210911T040746Z | user1004 |
| nan | sed | 210319T110947Z | user1004 |
| 007 | Stax | 210407T105229Z | Razetime |
| nan | Pxem | 210319T122923Z | user1004 |
| 040 | Excel | 210319T122609Z | Axuary |
| 026 | Dash | 210319T105759Z | user1004 |
| 062 | Python 3 | 190907T033932Z | Sagittar |
| 009 | Husk | 201127T052002Z | Razetime |
| 014 | Vim | 170825T143657Z | Vivian |
| 015 | Pyth | 171221T224532Z | Tornado5 |
| 050 | SNOBOL4 CSNOBOL4 | 171213T173518Z | Giuseppe |
| 045 | R | 170824T074222Z | Sven Hoh |
| 022 | Implicit | 170922T164924Z | MD XF |
| 089 | C# | 170824T034643Z | snorepio |
| 024 | Jq 1.5 | 170922T173622Z | jq170727 |
| 053 | ><> | 170828T011253Z | Sasha |
| 013 | CJam | 170912T062554Z | Esolangi |
| 037 | Javascript | 170830T161927Z | THC |
| 050 | PHP | 170828T015550Z | Titus |
| 139 | TeX | 170827T200834Z | A Gold M |
| 046 | C | 170824T142308Z | simon |
| 048 | JavaScript ES6 | 170827T111933Z | sgtdck |
| 009 | Jelly | 170824T024556Z | fireflam |
| 010 | Japt | 170824T063621Z | Shaggy |
| 046 | C gcc | 170824T153547Z | Felix Pa |
| 020 | J | 170826T052251Z | Gregory |
| 053 | Java 8 | 170824T132226Z | Kevin Cr |
| 112 | C++ GCC | 170824T103550Z | Steadybo |
| 034 | JavaScript | 170824T020844Z | user7234 |
| 015 | Retina | 170824T022413Z | user7234 |
| 025 | Haskell | 170824T153021Z | jferard |
| 040 | Java 8 | 170824T160545Z | Jakob |
| nan | GNU Sed | 170824T183413Z | Daniel S |
| nan | Paradoc v0.2.8+ | 170824T190120Z | betavero |
| 009 | Pyth | 170824T085133Z | Mr. Xcod |
| nan | COBOL GnuCOBOL | 170824T060010Z | Jakob |
| 009 | Pyke | 170824T135111Z | Blue |
| 016 | Perl 5 | 170824T034229Z | Xcali |
| 010 | V | 170824T020610Z | nmjcman1 |
| 011 | 05AB1E | 170824T095718Z | Erik the |
| nan | Ruby | 170824T021517Z | Pavel |
| 032 | PowerShell | 170824T062605Z | Tessella |
| 023 | Octave | 170824T035809Z | rahnema1 |
| 009 | Gaia | 170824T030454Z | Business |
| 037 | Python 2 | 170824T021146Z | totallyh |
| 013 | Actually | 170824T024833Z | user4594 |
Bespoke, 271 bytes
comment-cutting lines of COBOL?am I so early,no coder in C or BASIC is there?if I am,screw it
we read by line,ignoring six leading letters;seven is kept
now,if forty-two is read in,discount extra letters in it;else,output it totally
the end is a convenient exponent error
This program takes the form of an infinite loop, in which the following is done:
- 6 characters are read and popped from the stack (using
H SVto effectively pop 2 at a time, instead ofDO Pwhich pops 1 at a time). - The 7th character is read, which will be a space or
*if there are more characters to read, and -1 otherwise. - This character is taken to the power of itself. If we had read a -1, this will result in an error, ending the program.
- Until a newline is reached, new characters are read in one by one, and they are outputted if the 7th character is not equal to 42 (i.e. if subtracting 42 gives a nonzero number).
The input is assumed to end with a newline; otherwise, this will print Unicode codepoint 1,114,111 forever.
brainfuck, 95 bytes
--[>+<++++++]>-[>>,,,,,,,[<<[->>->+<<<]+[<,[->>+<<]>>>[<.<[-]]<[<[-]<]>>[-<+>]<----------]]>>>]
The last line of the input must have a trailing newline.
With comments, 994 bytes
generate 42 on cell 0
--[>+<++++++]>-
main loop
[
cell 2 stores seventh column
>>
read first to sixth columns
,,,,,,
read seventh column
,
reject eof
[
consume cell 0 value 42
subtract 42 from cell 2
preserve 42 to cell 3
<<
[->>->+<<<]
cell 0 stores eighth through newline columns
+[
read next column to store to cell 1
cell _1 as temporary
<,
[->>+<<]
>
cell 0 1 2 3
garbage VALUE 0/_10 42
^
output cell 1 and consume if cell 2 is minus ten
>>[<.<[-]]
memory layout and ptr
cell 0 1 2 3
garbage VALUE 0 42
^
or
cell 0 1 2 3
0 VALUE _10 42
^
reset cell 0 and move to _1
<[<[-]<]
now move cell 1 value to cell 0
>>[-<+>]<
exit loop if cell 0 is value 10
----------
]
]
move to cell 3
>>>
redo the things in this loop
reindex cell 3 as cell 0
]
INPUT NEEDS TRAILING NEWLINE
Uiua, 11 bytes
▽≠□@*⍚°⊂⍚↘₆
▽≠□@*⍚°⊂⍚↘₆
⍚↘₆ # drop the first 6 characters from each row
⍚°⊂ # split each row into head and tail
≠□@* # check which heads aren't equal to a boxed '*'
▽ # keep the tails whose heads aren't equal
# Experimental! because of the subscript on ↘ drop.
APL, 18 bytes:
{8↑¨⍵/⍨' '=⍵⌷⍨¨⊂7}
Explanation:
{8↑¨⍵/⍨' '=⍵⌷⍨¨⊂7}
{ ⍵⌷⍨¨⊂7} ⍝ Each 7th character of every line
{ ' '= } ⍝ is a space?
{ ⍵/⍨ } ⍝ if so, keep
{8↑¨ } ⍝ then remove the first 8 characters
Rockstar, 94 bytes
listen to S
while S
cut S in N
cut S
while N-S-7
roll S in C
if C-1
join S
say S
listen to S
Try it (Code will need to be pasted in)
Thunno 2 N, 10 bytes
¤æ6ið=;ı7ỵ
Explanation
¤æ6ið=;ı7ỵ # Implicit input
¤ # Split the multi-line input on newlines
æ ; # Filter this list of strings by:
6i # The 6th character (0-indexed)
ð= # Is a space
ı # Map over this new list of strings:
7ỵ # Remove the first 7 characters
# Implicit output, joined on newlines
Zsh (builtins only), 35 bytes
for l ("${(f)$(<p)}")<<<${l:7$l[7]}
Scans file p per this tip.
Other solutions: 45 bytes, 27b (illegal)
GFortran, 84 bytes
Yet again, Fortran beats Cobol ☺. Borrows stuff from this solution.
character(99)C;read*,n;do i=1,n;read'(A)',C
if(C(7:7)<'*')print'(A)',C(8:);enddo;end
Previously: 95 bytes ; 98 bytes(-47 by removing array) ; 145 bytes
Pure Bash, 39 bytes
Outgolfed user100411's answer
for x
{ ((1${x:6:1}1))||echo "${x:7}"
}
Usage
Each argument represents a line. e.g.
cat<<'EOF'>f
for x
{ ((1${x:6:1}1))||echo "${x:7}"
}
EOF
bash f '000000 blah blah' '000001* apples' '000002 oranges?' '000003* yeah, oranges.' '000*04 love me some oranges'
K (ngn/k), 28 bytes
{$["*"=x@6;"";" "/1_" "\x]}'
Takes a list of strings and returns a list of strings.
Explanations:
{$["*"=x@6;"";" "/1_" "\x]}' Main function. Takes implicit input
' For each string in the lists...
{ } Execute a function that
$[ ] Checks if
x@6 The character at the 6th position (0-indexed)
"*"= ; Is equal to an asterisk
""; If it does, return an empty string
x Else, return the string
" "\ Splitted by whitespace
1_ Trim the first element (i.e. the line numbers)
" "/ Join together by whitespace (to preserve the original text)
APL, 23 bytes
- 23 bytes assuming SBCS. In UTF-8 it'll be 42 bytes
This is my first ever attempt at a code golf challenge, feel free to improve, i'm sure i could have saved one or two characters if i wasn't so adamant on making this code 'tacit'
This assumes the input is a list of lines and return a list of uncommented lines, this makes everything a bit easier since APL was explicitly made to work on list!
(('*'≠7∘⌷)⊢⍤/(8≤⍳8)∘⊂)¨
Go ahead and try it! (Thanks @Sʨɠɠan)
Pyth, 12 bytes
tMfqdhT>R6.z
Explanation:
tMfqdhT>R6.z | Full program
-------------+----------------------------------------
R .z | For each line of input
> 6 | Remove the first 6 characters
f hT | Filter over whether the first character
qd | is a space
tM | Remove the first character of each
Knight (v2), 19 bytes
W=xP|?42A=xSxF6@O]x
There are a few ways to do this that all are 19 bytes, but the theoretically optimal way (= x SUBST(PROMPT 0 6 @)) suffers from keyword clashing, meaning it has to be =xS P0 6@, wasting two separators.
# for each line in stdin
WHILE (= x PROMPT)
# If not equal to to 42 (ASCII("*"))
# | | ASCII value of first char
# | | | Strip the first 6 chars of x
: | ? 42 ASCII (= x SUBST (x FALSE 6 @))
# Output the tail (all but the first char) of x
: OUTPUT (] x)
This uses the new ] and @ operators to simplify string operations, as ] replaces SxF1"" and @ replaces "" when coerced to String since empty list is empty string.
Input is in stdin, output is in stdout.
Scratch, 277 bytes.
define g[x
set[s v]to(
set[j v]to((x)+(1
repeat(length of(item(i)of[l v
set[s v]to(join(s)(letter(j)of(item(i)of[l v
change[j v]by(1
end
replace item(i)of[l v]with(s
define f
set[i v]to(1
repeat(length of[l v
g(6
if<(s)contains[*]?>then
delete(i)of[l v
else
g[1
change[i v]by(1
C++ (gcc), 68 bytes
[](auto&l){l.remove_if([](auto&s){int c=s[6];s=&s[7];return c&2;});}
Input is a std::list<std::string>, it's modified in place.
Pascal, 122 B
This is a complete program requiring a processor complying to ISO standard 10206 “Extended Pascal”:
program p(input,output);var l:string(80);begin while not EOF do begin readLn(l);if''=l[7]then writeLn(subStr(l,8))end end.
Ungolfed version with some explanatory comments:
program uncommentFixedFormatCobol(input, output);
var
{ This “discriminates” the built-in schema data type `string`
to have a capacity of up to 80 characters, i.e. the maximum
width of one COBOL _fixed-format_ source code line. }
line: string(80);
begin
{ `EOF` is shorthand for `EOF(input)`. }
while not EOF do
begin
{ `readLn(line)` is shorthand for `readLn(input, line)`. }
readLn(line);
{ Similarly, `write(x)` is shorthand for `write(output, x)`. }
{ ---- Remember, in Pascal `string` indices are 1-based. ----- }
{ This may look like an empty string check, and `''` is indeed
an empty string, yet in Pascal the `=`-comparison first pads
both operands to the same length using `' '`. This line is
in fact doing `if line[7] = ' ' then`, but one byte shorter. }
if line[7] = '' then
begin
{ `subStr(line, 8)` shorthand for
`subStr(line, 8, length(line) - 8 + 1)` }
writeLn(subStr(line, 8))
{ Wait! What if `line[8]` does not exist? The standard
says it shall be an error if `firstCharacterIndex +
substringLength − 1` is greater than the length of the
supplied string. If `length(line)` equals seven, then
we’re calling `subStr(line, 8, 0)` which is fine. }
end
end
end.
Pure Bash, 42 + 1 = 43 bytes
Filename must be x; it is for extra one byte.
read x||>x
((1${x:6:1}1))||echo ${x:7}
. x
Usage
- Input from stdin.
- Optional trailing LFs.
- Output to stdout.
CLC-INTERCAL, 116 bytes.
DO;1<-#6DO,1<-#999DOCOMEFROM.1DOWRITEIN;1+,1(91)DO.1<-,1SUB#2(1)DO.2<-.1~#1DDOCOMEFROM.2DO,1SUB#3<-#0(95)DOREADOUT,1
Try it online, although you need to copy and paste!
Assumption
- Each line should have <=80 characters except trailing newline character(s), although this program can handle up to 339 characters per line (or more, depending on what kind of characters are used).
- Does not matter whether input has trailing newline or not.
Explaination
DONOTE stores first six characters of line
DO;1<-#6
DONOTE stores rest of characters of line except trailing newline
DO,1<-#999
DONOTE label one
DOCOMEFROM.1
DOWRITEIN;1+,1
DONOTE goto label one if tail one is asterisk
DONOTE first two items of tail one shall be
DONOTE 91 and 95 if space, or
DONOTE 91 and 95 if asterisk
(91)DO.1<-,1SUB#2
DONOTE goto label two if line is not empty
DONOTE obtw every item of tail will be zero
DONOTE if empty line
(1)DO.2<-.1~#1
DONOTE die here
D
DONOTE label two
DOCOMEFROM.2
DONOTE erase the space
DONOTE obtw zeros on tail are ignored
DONOTE when reading out
DONOTE see source code for more info
DO,1SUB#3<-#0
DONOTE goto label 1 after reading out
(95)DOREADOUT,1
sed, 11 bytes + 3 bytes option -nr = 14 bytes.
s/^.{6} //p
sed, 16 bytes
#n
s/^.\{6\} //p
#n on top of line is for -n, which is GNU-extension POSIX-compatible.
Stax, 7 bytes
ê┬|Y¶à6
Explanation
m6%B42=C
m map each line:
6% split at index 6, push both parts
B uncons, pop and push first element
42=C if equal to 42, cancel
Pxem, 88 bytes (filename) + 0 bytes (content) = 88 bytes, with non-printable characters.
- Filename (some unprintables are escaped):
\001.t.i.m.+.w.i.s.i.s.i.s.i.s.i.s.i*.zAB.z.i.c.o\n.a\002.tXX.a.m\002.zAB.i\n.z.i\n.aXX.a\001.t.i.m.+.a - Content: empty.
Usage
/path/to/pxem/interpreter THAT_PROGRAM_AS_IN_ABOVE <input.txt
COBOL program to be input must be fed from stdin, with LF-styled newlines, whose last line is terminated with LF.
Alternative: Pxem, 100 bytes (filename) + 0 bytes (content) = 100 bytes, printables and LF only.
Filename is as follows:
ab.-.t.i.m.+.w.i.s.i.s.i.s.i.s.i.s.i*.zAB.z.i.c.o
.a02.-.tXX.a.mac.-.zAB.i
.z.i
.aXX.aab.-.t.i.m.+.a
Commented version
XX.z (this is just to format well
.a<0x01>.tXX.z (reg=1
.a.i.m.+.wXX.z (while getchar()!=EOF; do (obtw EOF is -1
.a.i.s.i.s.i.s.i.s.i.sXX.z (5.times { getchar(); }
.a.i*.zXX.z (while getchar()!='*'; do
.aAB.z.i.c.o<0x0A>.aXX.z (do print(c=getchar()) while c!=newline
.a<0x02>.tXX.z (reg=2
.aXX.aXX.z ( break; done
.a.m<0x02>.zXX.z (while reg!=2; do
.aAB.i<0x0A>.z.i<0x0A>.aXX.z (do c=getchar() while c!=newline
.aXX.aXX.z ( break; done
.a<0x01>.tXX.z (reg=1
.a.i.m.+.aXX.z (done
.a
Excel, 40 bytes
=FILTER(MID(A:A,8,73),MID(A:A,7,1)<>"*")
COBOL has a max line length of 80.
Dash, 26 bytes
cut -c7-|grep ^\ |cut -c2-
Dash, 29 bytes
cut -c7-|grep -vF \*|cut -c2-
OBTW it's POSIX-compatible, if I remember the specs correctly.
Python 3, 62 bytes (no regex)
def f(s):
for w in s.split('\n'):
if w[6]!='*':print(t[7:])
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
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.
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
\* "*"
SNOBOL4 (CSNOBOL4), 72 70 66 50 bytes
R INPUT POS(6) (' ' REM . OUTPUT | '*') :S(R)
END
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.
R, 47 45 bytes
function(x)gsub("(?m)^.{6}( |.*\\n)","",x,,T)
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.
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
><>, 57 53 Bytes
>i~i~i~i~i~i~i67*=\
<o$/?:$/?=a:;?(0:i<
\~$/~\ $
/ <o\?/
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.
CJam, 13 bytes
{{6>'*#},7f>}
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?"]
Javascript, 37 bytes
Regexp-based solution
s=>s.replace(/^.{6}( |(\*.+$\n?))/gm,'')
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.
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.
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);
Jelly, 11 9 bytes
ṫ€7Ḣ⁼¥Ðf⁶
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
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.
C (gcc), 53 48 46 bytes
x;main(y){for(y=&x;gets(y-6);x&2||puts(y+1));}
-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.
J, 20 bytes
7&}."1(#~'*'~:6&{"1)
This assumes the input is a matrix of equal-length space-padded lines.
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:
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)
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.
JavaScript, 44 34 bytes
Crossed-out 44 is still regular 44.
6 bytes saved thanks to tsh
a=>a.replace(/^.{6}( |.*\n)/gm,'')
Haskell, 27 25 bytes
Laikoni's version is shorter than mine:
f n=[x|' ':x<-drop 6<$>n]
My version:
f n=[drop 7x|x<-n,x!!6<'*']
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)","")
Acknowledgments
- -3 bytes thanks to Sven Hohenstein's regex
GNU Sed, 19 + 2 = 21 characters
Requires -E argument to sed to enable extended regular expressions.
/^.{6}\*/d;s/^.{7}/
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).
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
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
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
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
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
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.
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).
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
Pyke, 9 bytes
36 4C 3E 23 64 DE 29 6D 74
Readable:
6L>#d.^)mt
6L> - [i[6:] for i in input]
#d.^) - filter(i.startswith(" ") for i in ^)
mt - [i[-1:] for i in ^]
V, 13 11 10 bytes
Î6x<<
çª/d
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
Ruby, 39 38 36 29 23 22 20 + 1 = 21 bytes
$_[/.{6}( |.*
)/]=''
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.
PowerShell, 32 bytes
$input-replace'^.{6}( |.*)'-ne''
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.
Gaia, 9 bytes
6>¦'*«⁈ḥ¦
A function accepting a list of strings and returning a list of strings.
Explanation
6>¦ Remove the first 6 characters of each string
'*«⁈ Filter out ones that start with *
ḥ¦ Remove the initial space from each
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]]
I/O as lists of strings.
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
