Now I know my ABCs, won't you come and golf with me?

46

3

Write a program or function that outputs this exact text, case-insensitive:

A, B, C, D, E, F, G,
H, I, J, K, L, M, N, O, P,
Q, R, S,
T, U, V,
W, X, Y, Z.

(Based on the alphabet song that many American kids learn to help memorize the alphabet, though edited for more compressibility.)

The output must look exactly the same as the above (again, case-insensitive), but may contain trailing spaces on each line and/or trailing newlines. Notice the period at the end.

This is code-golf, so the shortest code in bytes wins.

ETHproductions

Posted 2016-09-30T17:50:23.093

Reputation: 47 880

4For regex based languages consider a 0 width lookahead... /(?=[HQTW])/ – Magic Octopus Urn – 2016-09-30T18:24:04.290

29I thought it was H, I, J, K, LMNO, P? – David says Reinstate Monica – 2016-09-30T21:00:59.470

7Shouldn't the last line end with "Y and Z."? – KM. – 2016-10-02T12:36:07.340

@KM. This was discussed in the sandbox, and we decided to stick with this version to make the challenge less complicated.

– ETHproductions – 2016-10-02T18:26:16.947

6Golf seems boring. Cricket is better. – Manoj Kumar – 2016-10-03T19:49:05.973

Answers

15

Vim, 42, 40 keystrokes/bytes

:h<_<cr>jjYZZP:s/./&, /g<cr>7f r<cr>9;.3;.3;.$ch.

Thanks to Lynn and her awesome vim answer for the tip to grab the alphabet from help.

Thanks to RomanGräf for saving two bytes!

Explanation:

:h<_<cr>                                      " Open up vim-help
        jj                                    " Move down two lines
          Y                                   " Yank this line (containing the alphabet)
           ZZ                                 " Close this buffer
             P                                " Paste the line we just yanked
              :s/./&, /g<cr>                  " Replace every character with that character followed by a comma and a space
                            7f                " Find the seven space on this line
                               r<cr>          " And replace it with a newline
                                    9;        " Repeat the last search (space) 9 times
                                      .       " Repeat the last edit (replace with a newline)
                                       3;     " Third space
                                         .    " Replace with newline
                                          3;  " Third space
                                            . " Replace with newline

Then, we move the end of the of the line with $, change back a character with ch and insert a dot.

James

Posted 2016-09-30T17:50:23.093

Reputation: 54 537

2You mustn't convert to uppercase. The OP said " this exact text, case-insensitive". – Roman Gräf – 2016-09-30T20:25:48.897

@RomanGräf Thanks for the tip! – James – 2016-09-30T20:26:25.927

Ha! Getting the alphabet from vim help is genius! Did you know that or did you look it up for this challenge? – Christian Rondeau – 2016-09-30T22:54:53.253

3

@christianRondeau I did not come up with it. Lynn did in this answer

– James – 2016-10-01T01:52:59.607

@RomanGräf +1 for using mustn't – FantaC – 2017-11-27T20:40:03.080

12

05AB1E, 16 bytes

Code

A',â79334S£»¨'.J

Explanation:

A                  # Push the alphabet.
 ',â               # Cartesian product with ','.
    79334S         # Push [7, 9, 3, 3, 4].
          £        # Contigious substring, pushes the substrings [0:7], [7:7+9], 
                     [7+9:7+9+3], [7+9+3:7+9+3+3], [7+9+3+3:7+9+3+3+4].
           »       # Gridify, join the inner arrays with spaces and join those arrays
                     with newlines.
            ¨      # Remove the last character.
             '.J   # Append a '.'-character.

Uses the CP-1252 encoding. Try it online!

Adnan

Posted 2016-09-30T17:50:23.093

Reputation: 41 965

11

Bash + GNU utilities, 36

  • 5 bytes saved thanks to Neil.
echo {A..Y}, Z.|sed 's/[HQTW]/\n&/g'

Ideone.

Digital Trauma

Posted 2016-09-30T17:50:23.093

Reputation: 64 644

2Why not just echo {A..Y}, Z.|sed 's/[HQTW]/\n&/g' ? – Neil – 2016-09-30T19:05:55.110

@Neil Ooh very good! thanks! – Digital Trauma – 2016-09-30T19:54:28.207

11

JavaScript (ES6), 66 65 bytes

Beating @Neil was impossible... That's why I did it. :-)

f=(i=10)=>i>34?"z.":i.toString(++i)+","+` 
`[9568512>>i-9&1]+f(i)

Golfed 1 byte thanks to a trick from @LevelRiverSt. Using String.fromCharCode is 7 bytes longer:

f=(i=65)=>i>89?"Z.":String.fromCharCode(i,44,i%86%83%80%71?32:10)+f(i+1)

How it works

This recursively generates each character of the alphabet from a to y, using .toString(). A comma is appended after each letter, plus a newline if 9568512>>i-9&1 is 1, or a space otherwise. When the recursion gets past 34, i.e. to z, the function simply returns "z.".

ETHproductions

Posted 2016-09-30T17:50:23.093

Reputation: 47 880

Wait what how does this even— explanation pls? :3 – Downgoat – 2016-09-30T23:09:29.313

10

Python 2.7, 67 66 63 bytes

a=65;exec"print'%c'%a+',.'[a>89]+'\\n'[a%42%39%9^2:],;a+=1;"*26

Dennis saved a byte.

Lynn

Posted 2016-09-30T17:50:23.093

Reputation: 55 648

Using exec instead of for should save a byte. – Dennis – 2016-09-30T20:21:33.433

6

Jelly, 19 18 bytes

ØAp”,ṁ79334DR¤GṖ”.

Thanks to @Adnan for golfing off 1 byte!

Try it online!

How it works

ØAp”,ṁ79334DR¤GṖ”.  Main link. No arguments.

ØA                  Yield "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
  p”,               Cartesian product with ','; append a comma to each letter.
             ¤      Combine the two links to the left into a niladic chain.
      79334D          Decimal; yield [7, 9, 3, 3, 4].
            R         Range; yield [[1, 2, 3, 4, 5, 6, 7], ..., [1, 2, 3, 4]].
     ṁ              Mold; reshape the array of letters with commata like the
                    generated 2D array.
              G     Grid; separate rows by spaces, columns by linefeeds.
               Ṗ    Pop; discard the last comma.
                ”.  Print the previous result and set the return value to '.'.
                     (implicit) Print the return value.

Dennis

Posted 2016-09-30T17:50:23.093

Reputation: 196 637

1131 seconds? Dang... – ETHproductions – 2016-09-30T17:52:33.387

5

JavaScript (ES6), 80 74 bytes

_=>[...`ABCDEFGHIJKLMNOPQRSTUVWXYZ`].join`, `.replace(/[HQTW]/g,`
$&`)+`.`

Probably possible to shorten this with atob/btoa if you can work out how to use ISO-8859-1 encoding. Edit: Saved 6 bytes thanks to @RickHitchcock.

Neil

Posted 2016-09-30T17:50:23.093

Reputation: 95 035

1@RickHitchcock Yes, I just realised that myself after reading the PHP answer. – Neil – 2016-09-30T19:09:04.187

@RickHitchcock You wanted .join\, ``? Put backslashes before the backticks. (Yes, comment markdown is different, sigh...) – Neil – 2016-09-30T19:10:41.697

5

Pyke, 23 19 17 bytes

G\,J\.+2cu  /P

Try it here!

G\,J\.+        -    ",".join(alphabet)+"."
       2c      -   split(^, size=2)
            /  -  split_sized(^, V)
         u     -   yield list [7,9,3,3] (actual bytes `u%04%07%09%03%03`)
             P - print(^)

Blue

Posted 2016-09-30T17:50:23.093

Reputation: 26 661

5

R, 83 71 bytes

a=rbind(LETTERS[-26],","," ");a[3,7+3*c(0,3:5)]="\n";cat(a,"Z.",sep="")

Try it online!

Makes a matrix of 3 rows (one with the letters, one with the commas and the other with either a space or a newline).

Edit: Thanks Billywob!

plannapus

Posted 2016-09-30T17:50:23.093

Reputation: 8 610

cat(a,sep="") saves a few bytes: a=rbind(LETTERS,","," ");a[3,7+3*c(0,3:5)]="\n";cat(a[,-26],"Z.",sep="") – Billywob – 2016-10-11T08:05:22.987

Thanks! That helped a lot! Using the [-26] on LETTERS directly saves yet another byte. – plannapus – 2016-10-11T15:01:54.250

4

Perl, 37 bytes

Credits to @Dom Hastings for this solution (3 bytes shorter than mine, see bellow).

say+(map"$_, ".$/x/[GPSV]/,A..Y),"Z."

Run with -E (or -M5.010) flag :

perl -E 'say+(map"$_, ".$/x/[GPSV]/,A..Y),"Z."'

My previous version, 3 bytes longer (total of 40 bytes) :

perl -E '$_=join", ",A..Z;s/[HQTW]/\n$&/g;say"$_."'

Dada

Posted 2016-09-30T17:50:23.093

Reputation: 8 279

1Slightly different approach (still uses the regex...) for 37 bytes: say+(map"$_, ".$/x/[GPSV]/,A..Y),"Z." – Dom Hastings – 2016-10-03T12:31:42.190

@DomHastings Nice one, Well done. And it's more beautiful to have one statement instead of three! ;-) – Dada – 2016-10-03T14:31:08.957

4

CJam, 26 bytes

'A79333Ab{{',S2$)}*N\}/'.@

Online interpreter

'A                             Push 'A'
  79333Ab                      Push [7 9 3 3 3]
         {           }/        For each number n in the previous array...
          {      }*              Execute n times...
           ',S                     Push a comma and a space
              2$)                  Copy last letter and increment
                   N\            Place a newline under the letter on top
                       '.@     Push '.' and rotate

Sp3000

Posted 2016-09-30T17:50:23.093

Reputation: 58 729

4

Brainfuck, 117 bytes

+[++[-<]-[->->]<]+++[->++>+++>+>+<<<<<--<<->>>]>+[[-<<<<<+.>-.+>.>>>]>[[-<+>]>]<<[<]<.>>]<<-[---<<<+.>-.+>.>]<<<+.>+.

The first four lines each have a trailing space, and the program assumes 8-bit cells. Try it online!

(Handling the last line is tricky...)

Sp3000

Posted 2016-09-30T17:50:23.093

Reputation: 58 729

4

JavaScript (ES6), 66 64 bytes

_=>`ABCDEFG
HIJKLMNOP
QRS
TUV
WXY`.replace(/./g,"$&, ")+"Z."

Regex matches the characters but not the carriage returns, so, using regex replace, I can add the ", " to each character.

Edit: Removed 2 characters thanks to ETHProductions

Grax32

Posted 2016-09-30T17:50:23.093

Reputation: 1 282

1I have no idea why the other JS golfers didn't go for this solution first. Here, have an upvote. – Mama Fun Roll – 2016-10-06T05:45:56.260

1Dang, nice one! I think you can remove the parens in the regex if you change $1 to $&. – ETHproductions – 2016-10-06T13:38:33.137

3

Cheddar, 70 bytes

->[65@"71,72@"80,"QRS","TUV","WXYZ"].map(@.chars.join(", ")).vfuse+'.'

Looks like it's not getting shorter than this. I've made other versions of this which use quite interesting methods but this is shortest

Try it online!

Explanation

->                        // Function with no arguments
  [                       // Array, each item represents a line
   65@"71,                // See below on what @" does
   72@"80,
   "QRS",
   "TUV",
   "WXYZ"
  ].map(                  // On each item...
    @.chars.join(", ")    // Join the characters on ", "
  ).vfuse                 // Vertical fuse or join by newlines
  + '.'                   // The period at the end

The @" operator is used to generate string ranged. It generates a string starting from the left char code to the right char code.

For example, 65 is the char code for A and 90 for Z. Doing 65 @" 90 would generate A through Z or the alphabet.

Downgoat

Posted 2016-09-30T17:50:23.093

Reputation: 27 116

3

C, 112 102 81 bytes

Thanks to cleblanc & LevelRiverSt!

i,c;main(){for(c=64;++c<91;)printf("%c%c%c",c,44+c/90*2,c=="‌​GPSVZ"[i]?++i,10:32)‌​;}

musarithmia

Posted 2016-09-30T17:50:23.093

Reputation: 531

Nice solution. you can save a few bytes as 44 is 1 less than ',' and 46 1 less than '.' – cleblanc – 2016-09-30T19:16:08.270

There's no need to declare int and you can make can d implicit ints as well, this is only 101 bytes i,c,d;main(){for(c=65;c<91;++c){if(c-"GPSVZ"[i])d=32;else d=10,++i;printf("%c%c%c",c,c-90?44:46,d);}} – cleblanc – 2016-09-30T19:21:30.163

You can get this approach down to 82 bytes: i,c;main(){for(c=64;++c<91;)printf("%c%c%c",c,44+c/90*2,c=="GPSVZ"[i]?++i,10:32);} . Note that you can stick absolutely anything between the ?: of a ternary operator, even several expressions separated by commas (it evaluates to the last one.) – Level River St – 2016-09-30T20:31:40.903

3

Brainfuck, 157 bytes

+++++[>+>+++<<-]>>[->+>++++>+++>++<<<<]>----->+++++.>-.>++.<<<<<+[->>>+.>.>.<<<<<]+++++++++>>.<<[->>>+.>.>.<<<<<]<---[+>+++>>.<<[->>>+.>.>.<<<<<]<]>>>>+.>++.

Try it online

gtwebb

Posted 2016-09-30T17:50:23.093

Reputation: 191

3

Ruby, 56 54 bytes

$><<(?A..?Y).map{|c|c+('GPSV'[c]?",
":", ")}.join+"Z."

The first line ends with a literal newline.

Edit: saved two bytes by replacing 'A'..'Y' with ?A..?Y.

pgks

Posted 2016-09-30T17:50:23.093

Reputation: 51

3

Vim, 32 bytes

26o<C-V><C-V>64,<Esc>r.V{g<C-A>8Jj9Jj3Jj.j4JcH<C-R>"

Leaves a blank line at the end, which was allowed, but it's weird being this clumsy. Even worse, I'm ending in insert mode. I've seen some other folks do it here, so I guess it's allowed? It feels dirty.

  • 26o<C-V><C-V>64,<Esc>: The first <C-V> makes the second one insert literally. The <C-V>64s this leaves in the buffer will be turned into ASCII code points, then into letters. Commas already in.
  • r.: Never going to be at the end again, so do the . now.
  • V{g<C-A>: Uses visual increment to turn all the 64s into the ASCII code points of the capital letters.
  • 8Jj9Jj3Jj.j4J: The arbitrary line joins. First one is 8J instead of 7J because we're dealing with the blank line. The repeated 3Js are eligible for a dot repeat.
  • cH<C-R>": People usually think of i<C-R> as an insert mode paste, but it's more like an insert mode macro. Stuff like <C-V>65 will run as if typed, and interpreted as a decimal code point. This leaves an extra (allowed) line at the end, and stays in insert mode.

udioica

Posted 2016-09-30T17:50:23.093

Reputation: 2 381

4if you have an issue with a policy (or a lack thereof), take it up on meta, not in an answer. – Mego – 2016-10-11T12:50:34.013

2

PowerShell v3+, 60 78 67 bytes

-join(65..90|%{[char]$_+'.,'[$_-le89]+" "+"`n"*($_-in71,80,83,86)})

OK. I've actually read, understood, and followed the spec this time. Promise. :D

Takes the array 65..90 and loops over each element |%{...}. Each iteration, we're constructing a new string using concatenation, indexing, and multiplication.

First, we take the current number and char cast it to make it an ASCII letter. That's concatenated with another char, based on indexing into the string '.,' whether we're at 90 or not (i.e., to account for Z. while having all the rest be commas). That's string concatenated with " " to space-separate the letters, and string multiplication of "`n" based on Boolean value for whether the current element is -in the specified array (i.e., whether we need to concatenate on a newline character). The resulting string is left on the pipeline.

Those strings are encapsulated in parens, and -joined together into a new string, which is then also left on the pipeline and implicit Write-Output at the end prints the result. Since we have `n in the string, it's automatically converted to newlines upon printing.

Requires v3+ for the -in operator. Has a trailing space on each line, which is OK per the challenge specs.

Example

PS C:\Tools\Scripts\golfing> .\now-i-know-my-abc.ps1
A, B, C, D, E, F, G, 
H, I, J, K, L, M, N, O, P, 
Q, R, S, 
T, U, V, 
W, X, Y, Z. 

AdmBorkBork

Posted 2016-09-30T17:50:23.093

Reputation: 41 581

1The period at the end is missing. – Downgoat – 2016-09-30T18:12:01.617

Shouldn't there be a comma at the end of the first four lines? – Neil – 2016-09-30T19:07:04.340

@Neil Good gravy. I'm going to delete this until I can actually understand the spec. – AdmBorkBork – 2016-09-30T19:08:03.740

2

MATL, 38 29 bytes

9 bytes saved thanks to @Luis!

1Y2X{', '&Zc46h1[CEII]I*11hY{

Try it Online!

Explanation

1Y2     % Push the upper-case alphabet to the stack
X{      % Break the character array into a cell array (similar to a list)
        % where each element is a letter
', '&Zc % Combine back into a string with ', ' between each element
46h     % Append '.' (via ASCII code) to the end of the string
1       % Push the number 1
[CEII]  % Push the array: [7, 9, 3, 3]
I*      % Multiply this array by 3: [21, 27, 9, 9]  
llh     % Append an 11 to this array: [21, 27, 9, 9, 11] 
Y{      % Break our comma-separated list of characters into groups of this size
        % Implicitly display the result

Suever

Posted 2016-09-30T17:50:23.093

Reputation: 10 257

2

PHP, 62 Bytes

<?=preg_filter("# ([HQTW])#","\n$1",join(", ",range(A,Z)));?>.

only for comparison 87 Bytes

<?="A, B, C, D, E, F, G,\nH, I, J, K, L, M, N, O, P,\nQ, R, S,\nT, U, V,\nW, X, Y, Z.";

Jörg Hülsermann

Posted 2016-09-30T17:50:23.093

Reputation: 13 026

You can save a byte by using an actual newline in place of the \n. – Alex Howansky – 2016-10-02T23:03:49.017

As you're allowed trailing spaces on each line you can save a byte by dropping the space from the regex. Also you can save a byte by using the (deprecated and removed in 7.0) ereg_replace as it lets you skip the delimiters in the regex. – user59178 – 2016-10-03T11:24:32.800

@user59178 I could save 3 Bytes but i would avoid this. Yes the trailing space is allowed. I could wrote as regex "# (?=[HQTW])#" and short the replace to "\n" same bytes and makes it clearer. To use a deprecated function can confuse beginners. And the physical break can interpreted wrong on other systems then Unix. You can post it as your own sugesstion. – Jörg Hülsermann – 2016-10-03T12:40:45.857

2

Japt, 24 bytes

;B¬qJ+S r"[HQTW]"@R+XÃ+L

Test it online!

How it works

;                        // Reset various variables. B is set to "ABC...XYZ", J is set to ",", and L is set to ".".
 B¬                      // Take the uppercase alphabet and split into chars.
   qJ+S                  // Join with ", ".
        r"[HQTW]"        // Replace each H, Q, T, or W with
                 @R+XÃ   //   a newline plus the character.
                      +L // Append a period to the result.
                         // Implicit: output last expression

ETHproductions

Posted 2016-09-30T17:50:23.093

Reputation: 47 880

2

R, 146 bytes

L=LETTERS
f=function(x,y=""){paste(x,collapse=paste0(", ",y))}
cat(f(c(f(L[1:7]),f(L[8:16]),f(L[17:19]),f(L[20:22]),f(L[23:26])),"\n"),".",sep="")

Explanation:

LETTERS is predefined for uppercase letters.
The f function is for concatenating vector x on , with additional y (used for newlines).
The cat is the used as it prints \n as newlines. f is called on the letters to form rows and then on the rows again to form the whole output.

Probably golfable - I don't like the multiple calls of f...

pajonk

Posted 2016-09-30T17:50:23.093

Reputation: 2 480

3The raw output is only 77 bytes long. Printing that directly might be shorter... – Lynn – 2016-09-30T21:54:29.933

@Lynn, I know, but here I see some golfing possibilities. – pajonk – 2016-10-01T16:09:39.420

2

CJam, 31 bytes

'[,65>", "*7933Ab{3*/(\:+}%N*'.

Explanation:

'[,65>                             push uppercase alphabet
      ", "*                        ", " between all letters
           7933Ab                  push [7 9 3 3]
                 {3*/(\:+}%        slices of lengths 21, 27, 9, 9
                           N*'.    join slices with newlines, add final "."

Try it online

Neorej

Posted 2016-09-30T17:50:23.093

Reputation: 179

2

Julia, 71 bytes

f()=join(join.(['A':'G','H':'P',"QRS","TUV","WXYZ"],[", "]),",\n")*"."

Requires 0.5 or better for broadcasting .()

Lyndon White

Posted 2016-09-30T17:50:23.093

Reputation: 1 021

On the one hand, this currently does not have a trailing period, and doesn't it need a print/function definition? On the other hand, not saving join to a variable saves a byte. – Sp3000 – 2016-10-02T13:27:57.070

My bad wrt missing the ".", and thanks for the pointer on join. I misscounted. Running the program returns the string. Isn't a program returning a string a valid output? (Or is it only functions that are allowed to return things to count as output. if so f()= is shorter thant print()) – Lyndon White – 2016-10-02T13:55:59.313

Sure, f()= or ()-> is fine - I think the idea is that functions are assignable and can be run multiple times, and in contrast this would be a code snippet. – Sp3000 – 2016-10-02T14:18:47.320

2

Cheddar, 57 bytes

->(65@"90).sub(/[GPSV]/g,"$0
").sub(/[^Z\n]/g,"$0, ")+"."

Try it online! Isn't that beautiful? It's a nice rectangle.

Two regex substitutions. (65@"90) is the uppercase alphabet, .sub(/[GPSV]/g,"$0\n") replaces GPSV with itself and "\n", .sub(/[^Z\n]/g,"$0, ") replaces all non newline and Z characters with itself and ", ", and "." adds a final ..

Conor O'Brien

Posted 2016-09-30T17:50:23.093

Reputation: 36 228

1Nice technique, and nice job outgolfing Downgoat ;) – ETHproductions – 2016-10-02T18:27:47.057

2

Java, 116 109 105 104

String f(){String s="";for(char c=65;c<91;)s=s+c+(c>89?46:',')+("GPSV".indexOf(c++)<0?' ':10);return s;}

Ungolfed:

String f() {
  String s = "";
  for (char c = 65; c < 91;) {
    s = s + c
      + (c > 89 ? 46 : ',')
      + ("GPSV".indexOf(c++) < 0 ? ' ' : 10);
  }
  return s;
}

user18932

Posted 2016-09-30T17:50:23.093

Reputation:

You can golf it by 7 bytes: All three || to | (-3); changing c==90 to c>89 (-1); changing '.' to 46 (-1); and changing '\n' to 10 (-2). – Kevin Cruijssen – 2016-10-03T09:06:43.157

@KevinCruijssen thanks, I tried using decimals but it looks like if I replace both character constants in a ternary it changes the expression type to integer, which broke it. Changing one constant worked and squeezed out a few bytes. – None – 2016-10-03T13:43:24.477

No problem. Don't forget to change the 116 to <s>116</s> 109 bytes. ;) – Kevin Cruijssen – 2016-10-03T13:45:08.550

2@KevinCruijssen thanks. If I had enough coffee in me I would have remembered to update it myself. – None – 2016-10-03T13:47:23.603

12 more bytes: "GPSV".contains(""+c) instead of c==71|c==80|c==83|c==86. – TNT – 2016-10-03T17:57:05.497

1@TNT I was able to do slightly better. I knew that part could be improved, thanks for the push in the right direction. – None – 2016-10-03T20:05:38.167

You can golf one more byte I now notice. You can remove the ++c from the for-loop, and put it at the last usage inside the for-body: .indexOf(c++). – Kevin Cruijssen – 2016-10-11T13:31:31.283

@KevinCruijssen thanks. I always overlook that. I also do a bit of C++ programming and that wanders into UB in C++, but not in Java. – None – 2016-10-11T13:35:51.040

1

PowerShell, 56 bytes

('ABCDEFG
HIJKLMNOP
QRS
TUV
WXY'-replace'.','$0, ')+'Z.'

Try it online!

mazzy

Posted 2016-09-30T17:50:23.093

Reputation: 4 832

153 bytes? – Gabriel Mills – 2019-03-06T14:24:19.110

Thanks. It's cool. A char range allowed in Powershell 6+ only. I think it would be better if you create a new post with Powershell 6. – mazzy – 2019-03-06T15:42:22.867

Ok, I will. Thanks. – Gabriel Mills – 2019-03-06T18:54:32.127

1

PowerShell 6, 53 52 47 bytes

"$('A'..'Y'|%{"$_,"-replace'[HQTW]','
$&'}) Z."

Try it online!

I believe PowerShell 6 is newer than this challenge. Originally posted as a suggestion for @mazzy's solution.

Gabriel Mills

Posted 2016-09-30T17:50:23.093

Reputation: 778

1

q, 46 bytes

-1@'(", "sv/:0 7 16 19 22_,:'[.Q.A]),'",,,,.";

skeevey

Posted 2016-09-30T17:50:23.093

Reputation: 4 139

1

PHP, 90 chars

A<?for($i=66;$i<91;$i++){echo", ";if(in_array($i,[72,81,84,87]))echo"\n";echo chr($i);}?>.

I know it's longer than 77 chars, but this is as short as it gets.

timmyRS

Posted 2016-09-30T17:50:23.093

Reputation: 329

timmyRS, When I noticed the "." outside your closing tag, I thought for a split second that you had an error, but I realized you were saving the trouble of concatenating that into your existing string. But, that also made me realize that anything greater than 77 bytes is overkill because you could to the whole thing as plain text and it would work just as well as your ".". – TecBrat – 2016-10-03T18:37:03.120

@TecBrat Well I fixed it now ;P – timmyRS – 2016-10-05T11:06:27.587

timmyRS - LOL :-) – TecBrat – 2016-10-05T16:18:19.273

1

Retina, 43 bytes


Z
{2`
$`
}T01`L`_L
.
$&, 
[HQTW]
¶$&
, $
.

Leading newline is significant. Try it online!

This is my first time using Retina, so any golfing tips are appreciated...

ETHproductions

Posted 2016-09-30T17:50:23.093

Reputation: 47 880

1

PHP, 67 65 64 bytes

Not exactly short, but it works.
This assumes that all errors are going to stderr.

foreach(range(A,Z)as$C)echo$C,",."[$C>Y],"
 "[!strstr(GPSV,$C)];

You can try it on http://ideone.com/VSK8Yu.

Thanks to @Jörg Hülsermann for saving 2 bytes! And thanks to @Titus for saving me 1 byte!

Ismael Miguel

Posted 2016-09-30T17:50:23.093

Reputation: 6 797

$C>Y instead of $C==Z saves one Byte and 'strstr(GPSV,$C)' instead of strpos(zGPSV,$C) should also save one Byte – Jörg Hülsermann – 2016-09-30T19:53:51.860

@JörgHülsermann That is pure genious! I should have though about that! – Ismael Miguel – 2016-09-30T20:30:00.790

@ETHproductions Duh, stupid me. Thanks, I totally forgot about it. – Ismael Miguel – 2016-09-30T20:33:06.827

Uhm ... don´t you need all doublequotes for -r? – Titus – 2016-10-01T10:56:16.317

@Titus Why would you? But, if you want, I can use doublequotes. It doesn't change the meaning at all. – Ismael Miguel – 2016-10-01T10:56:52.823

because you need the single quotes to hide the code from the shell. – Titus – 2016-10-01T10:58:54.813

@Titus You can always escape them, but I've made the change. – Ismael Miguel – 2016-10-01T11:00:02.677

@Titus What byte? – Ismael Miguel – 2016-10-01T11:00:58.653

You can save one more byte by swapping newline and space and removing one of the exclams. That´ll beat ETHproductions´ JavaScript answer. – Titus – 2016-10-01T11:02:10.820

@Titus I tried it, it gives me bizarre outputs in PHP 7.0.5. – Ismael Miguel – 2016-10-01T11:03:06.497

works fine for me in php 5.6.23 and php 7.0.11. Did you forget to swap the characters? Tryp copy & paste "\n "[!strstr(GPSV,$c)] – Titus – 2016-10-01T11:12:44.207

@Titus http://sandbox.onlinephpfunctions.com/code/8d778160ea897b462d64b332a77a150ff18d33fa gives a different output when compared to http://ideone.com/VSK8Yu which is SO weird!

– Ismael Miguel – 2016-10-01T11:21:09.170

1Unix LF Windows CR LF Apple CR can only works on an unix system "\n "[!strstr(GPSV,$c)] should work on every system. By the way the solution you have found Ismael is more genious – Jörg Hülsermann – 2016-10-01T11:56:28.013

Yep. But that´d cost the byte that the swapping saved. I tend to not use physical linebreaks anymore anyway, because in CLI it has to be escaped, which adds - in my understanding - one byte to the count. – Titus – 2016-10-01T12:03:55.400

@JörgHülsermann To be honest, yours is better. Also, all answers assume that you are using *NIX newlines. Using \n is 1 more byte than I want. If you really need Windows-style or Linux-style, just use \r\n or just state that you assume Windows newlines. – Ismael Miguel – 2016-10-01T12:04:32.880

Ismael your way is more interesting that the way I've found. You can take @Titus proposal and forget the output of the sandbox site – Jörg Hülsermann – 2016-10-01T12:09:18.290

@JörgHülsermann I found your way more interesting. I really didn't remember about using preg_filter(). And i will use Titus' suggestion. I didn't use it at first since it was spitting trashy output, but I will use now and give the link to ideone. An answer is valid as long as it is reproducible in, at least, 1 environment. – Ismael Miguel – 2016-10-01T12:11:52.773

It seems so we need judjes which way is more interesting. Normally I would use preg_replace (interest approaches zero) and the variation with preg_filter saves 1 Byte in some cases. You can be proud to find your way that is more genious – Jörg Hülsermann – 2016-10-01T12:26:22.610

@JörgHülsermann I think yours is more interesting because of preg_filter. In fact, I didn't even knew that that function existed. – Ismael Miguel – 2016-10-01T12:32:44.287

Beauty is in the eye of the beholder. :D – Titus – 2016-10-02T14:02:47.883

@Titus Agreed. But what would be trully beautiful would be to reduce strstr(GPSV,$C) to a single bitwise operation. – Ismael Miguel – 2016-10-02T14:15:15.463

1

Pyth, 25 bytes

+Pjmj\ dc*G\,j94092 23)\.

A program that prints the result to STDOUT.

Try it online

How it works

+Pjmj\ dc*G\,j94092 23)\.  Program. Input: none
          G                Yield string literal'abcdefghijklmnopqrstuvwxyz'
         * \,              Cartesian product of that with ',', yielding a list of
                           characters with appended commas
             j94092 23)    Yield the integer 94092 in base-23, giving [7, 16, 19, 22]
        c                  Split the comma-appended character list at those indices
   mj\                     Join each element of that on spaces
  j                        Join that on newlines
 P                         All but the last element of that, removing trailing ','
+                      \.  Append '.'
                           Implicitly print

TheBikingViking

Posted 2016-09-30T17:50:23.093

Reputation: 3 674

1

Forth, 85 bytes

This is a function that prints the string. Checking for when to print a new line is costly. This is still shorter than simply printing the required string, because it has new lines in it. The code does not need to be on this many lines, but there does need to be a line break within the DO LOOP somewhere. I don't know why.

: f 90 65 DO
I 72 = I 81 = I 84 = I 87 = + + +
if CR then
I emit ." , "
LOOP ." Z." ;

Try it online

The code is case-insensitive.

mbomb007

Posted 2016-09-30T17:50:23.093

Reputation: 21 944

1

Pip, 19 bytes

18 bytes of code, +1 for the -n flag. Outputs in lowercase.

(zJk).'.^@A*"?09B"

The ? represents a non-printing character, ASCII code 21. Try it online!

Explanation

 z                  Lowercase alphabet
  Jk                Join on ", "
(   ).'.            Append a period
          A*"?09B"  Map ascval() over that string, results in list: [21 48 57 66]
        ^@          Split at those indices
                    Join on newline and print (implicit, -n flag)

DLosc

Posted 2016-09-30T17:50:23.093

Reputation: 21 213

1

Ruby, 57 bytes

26.times{|i|$><<(i+65).chr+",."[i/25]+" 
"[2392128>>i&1]}

The space at the end of the first line is required: it's a literal [space][newline.]

C,74 bytes

c;main(){for(;++c<27;)printf("%c%c%c",64+c,44+c/26*2,4784256>>c&1?10:32);}

Basic bitshift and mask to determine when to print a space and when to print a newline. I noted that with the A and Z removed all groups are a multiple of 3 letters long, but I was unable to make use of this.

Level River St

Posted 2016-09-30T17:50:23.093

Reputation: 22 049

1That 4784256>>c&1 is a great idea. But you should probably post the two languages as two separate answers. – ETHproductions – 2016-09-30T22:13:55.580

1

Racket 173 bytes

(λ()(let((l(list 7 9 3 3 4))(s 65))(for((i 5))(define e(+ s(list-ref l i)))(for((j(range s e)))
(printf"~a~a "(integer->char j)(if(= j 90)"."",")))(printf"~n")(set! s e))))

Ungolfed:

(define f
  (λ()
    (let ((l (list 7 9 3 3 4))
          (s 65))
      (for ((i 5))
        (define e (+ s (list-ref l i)))
        (for ((j (range s e)))
          (printf "~a~a " (integer->char j) (if(= j 90) "." ",")))
        (printf "~n")
        (set! s e)
        ))))

Testing:

(f)

Output:

A, B, C, D, E, F, G, 
H, I, J, K, L, M, N, O, P, 
Q, R, S, 
T, U, V, 
W, X, Y, Z. 

rnso

Posted 2016-09-30T17:50:23.093

Reputation: 1 635

1

Haskell, 60 bytes

putStr$(['A'..'Y']>>= \x->x:", "++['\n'|elem x"GPSV"])++"Z."

Try it on Ideone.

putStr$(['A'..'Y']>>= \x->x:", "++['\n'|elem x"GPSV"])++"Z."
        ['A'..'Y']                                          --String "ABC...XY"
                      \x->x:", "++['\n'|elem x"GPSV"]       --function to append ", " and a "\n" when needed
       (          >>=                                )      --map function over the string and concat
                                                      ++"Z."--append "Z."
putStr$                                                     --print

Laikoni

Posted 2016-09-30T17:50:23.093

Reputation: 23 676

1

Fourier, 56 bytes

|~S44a32aS^|f|(iaf~i)10a|L65~i72L81L84L87L90(iaf~i)ia46a

Again, uses functions to take out repeated parts of the code.

Try it FourIDE!

Beta Decay

Posted 2016-09-30T17:50:23.093

Reputation: 21 478

1

Clojure, 154 bytes

#(print(loop[a(map char(range 65 91))[c & d][7 9 3 3 4]s""](if c(let[[l r](split-at c a)e(if d\,\.)](recur r d(str s(clojure.string/join", "l)e"\n")))s)))

That call to clojure.string/join is killer, although this wasn't competitive to begin with. Basically, it cuts the generated alphabet string a at the predefined line lengths, then adds each line to the acc.

It would have been significantly shorter for me to just "cheat" and print the string (91 bytes):

(print "A, B, C, D, E, F, G,\nH, I, J, K, L, M, N, O, P,\nQ, R, S,\nT, U, V,\nW, X, Y, Z.")

But where's the fun in that?

Ungolfed:

(defn abcs []
  (print
    (loop [alpha (map char (range 65 91))
           [c & cuts] [7 9 3 3 4]
           acc ""]
      (if c
        (let [[a-line a-rest] (split-at c alpha)
              e (if cuts \, \.)]
          (recur a-rest cuts (str acc (clojure.string/join ", " a-line) e "\n")))
        acc))))

Carcigenicate

Posted 2016-09-30T17:50:23.093

Reputation: 3 295

1

TI-Basic, 86 bytes

Cheers to anyone who can compress it further :3

Disp "A, B, C, D, E, F, G,","H, I, J, K, L, M, N, O, P,","Q, R, S,","T, U, V,
"W, X, Y, Z.

Timtech

Posted 2016-09-30T17:50:23.093

Reputation: 12 038

I think this is optimal, unfortunately. – Conor O'Brien – 2016-10-02T18:16:33.960

1

><>, 52 bytes

79334"A"\
or:?!~r&>:o1+:}&a" ,.["{=:}?$~o{?;{1-:}?$~

Try it online!

Sok

Posted 2016-09-30T17:50:23.093

Reputation: 5 592

1

PHP, 61 58 55 50 bytes

Note: uses Windows 1252 encoding.

for($a=A;$a<Z;)echo"$a,",~ßõ[!trim($a++,GPSV)]?>Z.

Run like this:

php -r 'for($a=A;$a<Z;)echo"$a,",~ßõ[!trim($a++,GPSV)]?>Z.' 2>/dev/null;echo

If your terminal is set to UTF-8, this shows that it works:

php -r 'for($a=A;$a<Z;)echo"$a,"," \n"[!trim($a++,GPSV)]?>Z.' 2>/dev/null;echo

Explanation

Iterates over the alphabet until Y is reached. Prints the letter with a comma, then prints a space, unless the letter is one of GPSV (found by !trim($a,"GPSV")). After the loop, print Z..

Tweaks

  • Saved 3 bytes by using strpos instead of char count
  • Saved 3 bytes by using trim instead of strpos
  • Saved 5 bytes by using the closing tag to print a literal Z. instead of echo

aross

Posted 2016-09-30T17:50:23.093

Reputation: 1 583

1

q, 41 bytes

@[", "sv,:'[.Q.A];20 47 56 65;:;"\n"],"."

How it works:

            .Q.A                          / Built-in alphabet
        ,:'[    ]                         / Flip data (to 1-row matrix)
  ", "sv                                  / Join with ", "
@[               ;20 47 56 65;:;"\n"]     / Replace spaces with newlines at indices
                                     ,"." / Append period

Boston Walker

Posted 2016-09-30T17:50:23.093

Reputation: 141

0

><>, 45 bytes

4339"A"7v$oa~<
"&+oo1+$>:1(?^1-$:o:"Z"=2*&" ,

Try it online!

Emigna

Posted 2016-09-30T17:50:23.093

Reputation: 50 798

0

MathGolf, 20 bytes

'A[793∙]öæ└╣·\n\\;'.

Try it online!

Explanation

'A                    Push "A"
  [793∙]              Push [7, 9, 3, 3, 3]
        ö             Start foreach-loop over index array using next 7 instructions
         æ            Start for-loop for current item of index array, using next 4 instructions
          └           Duplicate and increment, e.g. "A" -> "A", "B"
           ╣·         Push ", "
             \        Swap top two, keeping the letter on top after inner loop
              n\      Push newline and swap top two, keeping the letter on top
                \;'.  Swap top two, discard top, and push "." (remove trailing comma)

maxb

Posted 2016-09-30T17:50:23.093

Reputation: 5 754

0

Stax, 16 bytes

é╡₧!D☻àw╟`«▒Σ╪░↓

Run and debug it

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

'.          push "."
VA          push "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
',\         repeat zip alphabet with comma, yielding ["A,", "B,", ...]
J           join with spaces
)           overwrite end of joined string with period (pushed first)
"r!WEF"!    crammed array literal for [20, 47, 56, 65]
A&          assign 10 to these array indices.  10 is the codepoint for newline.

Run this one

recursive

Posted 2016-09-30T17:50:23.093

Reputation: 8 616

0

APL (Dyalog Unicode), 30 29 bytesSBCS

Full program.

↑'AHQTW'(∊⍨⊂⊢)'.',⍨∊', '∘,¨⎕a

Try it online!

⎕a the uppercase alphabet

', '∘,¨ prepend ", " to each letter

ϵnlist (flatten)

'.',⍨ append a period

'AHQTW'() apply the following tacit function with the string as left argument:

 the right argument (", A, B…")

 partitioned so a new partition begins at each True in

∊⍨ the Boolean mask indicating argument elements that are members of the left argument

 mix the list of strings into a character matrix

solved together with Adam

ngn

Posted 2016-09-30T17:50:23.093

Reputation: 11 449

0

///, 62 bytes

/c/, /AcBcCcDcEcFcG,
HcIcJcKcLcMcNcOcP,
QcRcS,
TcUcV,
WcXcYcZ.

Try it online!

Not much to golf here, but I reduced it from 77 bytes to 62 just by replacing , with c.

Erik the Outgolfer

Posted 2016-09-30T17:50:23.093

Reputation: 38 134

What would //, /ABCDE... do? – ETHproductions – 2016-10-01T12:34:12.970

@ETHproductions It might crash your computer. I put a c for comma. – Erik the Outgolfer – 2016-10-01T12:38:16.050

1@ETHproductions Substitutions are repeated until the search string is no longer found. So //.../ will always result in an infinite loop. – Martin Ender – 2016-10-02T11:35:58.907

0

ListSharp, 88 bytes

SHOW="A, B, C, D, E, F, G,\nH, I, J, K, L, M, N, O, P,\nQ, R, S,\nT, U, V,\nW, X, Y, Z."

downrep_nation

Posted 2016-09-30T17:50:23.093

Reputation: 1 152

1Couldn't you put the \n in the string? It looks like that would be shorter. – Timtech – 2016-10-02T16:48:53.427

@Timtech oh dang, I thought im smart but im not – downrep_nation – 2016-10-02T16:53:41.267

It's ok. Just something like SHOW="A, B, C, D, E, F, G,\nH, I, J, K, L, M, N, O, P,\nQ, R, S,\nT, U, V,\nW, X, Y, Z." is 88 bytes instead of 113. – Timtech – 2016-10-02T16:58:09.027

0

GameMaker Language, 85 bytes

b=""for(a=65;a<90;a++){d=chr(a)c=", "if string_pos(d,"GPSV")c=",#"b+=d+c}return b+"Z.

Boring alternate (94 bytes)

return string_replace_all("AaBaCaDaEaFaG,#HaIaJaKaLaMaNaOaP,#QaRaS,#TaUaV,#WaXaYaZ.","a",", ")

Pretty straightforward. Note that # is newline literal (think \n in most languages). Use \# for #.

Timtech

Posted 2016-09-30T17:50:23.093

Reputation: 12 038