| Bytes | Lang | Time | Link |
|---|---|---|---|
| 122 | JavaScript Node.js | 250721T192656Z | Fhuvi |
| 096 | JavaScript Node.js | 250722T074329Z | rougepie |
| 036 | Uiua | 250718T123524Z | nyxbird |
| 021 | Vyxal 3 | 250716T190528Z | pacman25 |
| 062 | PowerShell 6+ | 200916T145753Z | mazzy |
| 027 | Japt R | 200831T143720Z | Shaggy |
| 024 | 05AB1E | 200831T123909Z | Kevin Cr |
| 026 | Brachylog | 200829T003540Z | Unrelate |
| 023 | Jelly | 200828T094850Z | Unrelate |
| 064 | x8616 machine code | 200828T164921Z | 640KB |
| 071 | Kotlin | 200828T154130Z | user |
| 040 | Jelly | 161003T190745Z | Erik the |
| 151 | /// | 161003T180750Z | Erik the |
| 080 | Haskell | 161003T190810Z | Angs |
| 131 | Prolog | 120312T124940Z | marinus |
| 062 | Ruby | 120115T174852Z | Hauleth |
| 063 | Q | 120309T005148Z | tmartin |
| 063 | Q | 120309T142329Z | skeevey |
| 045 | J | 120115T131355Z | Gareth |
| 043 | APL | 120116T011408Z | Dillon C |
| 099 | Smalltalk | 120115T185913Z | Hauleth |
| 098 | C | 111203T161610Z | han |
| 070 | Scala | 111208T071035Z | user unk |
| 073 | Python | 111205T203554Z | Steven R |
| 083 | JavaScript | 111205T185130Z | Ilmari K |
| 073 | Groovy | 111205T171920Z | Armand |
| 073 | Mathematica | 111203T045424Z | Mr.Wizar |
| 063 | Perl | 111202T121346Z | Ilmari K |
| 124 | D | 111202T120731Z | ratchet |
| 073 | Perl | 111202T094246Z | Toto |
| 075 | R | 111202T102131Z | Andrie |
| 094 | Haskell | 111202T045243Z | hammar |
| 103 | Javascript | 111202T043911Z | stephenc |
JavaScript (Node.js), 122 125 bytes
-3 bytes with some refactoring.
Still,j>34?(...):[33,63,44,46][j-31]costs a lot to obtain the ASCII codes for "!?,.".
I wonder if it's possible to obtain them with a single shorter calculation.
I tried to do an ASCII codes approach to avoid having the hard-coded 40 bytes string and the for and substr, but somehow ended up with around 40 more bytes than the currently shortest JS answer :'(
console.log(""+Buffer(151).map((c,i)=>++i%4?[(j=i-(i>>2)*3)%10+48,85-j,j+54,j>34?125-j:[33,63,44,46][j-31]][--j/10|0]:10))
Here's the explanation in case of need of further debugging:
""+Buffer(151).map(...) handles the conversion of ASCII codes to string, and a loop over the 151 needed characters (including newlines)
i%4 is used to transform every fourth character into a newline (ASCII code 10 at the end)
The variable j=i-(i>>2)*3 is used to transform the 1-based-index 123456... into the corresponding wanted value 123234... (ignoring line breaks for the example)
We initialize an array with:
[ first_quarter_computing = (j)%10+48
second_quarter_computing = 85-j
third_quarter_computing = j+54
fourth_quarter_computing = 125-j or the codes 33,63,44,46 for "!?,." ]
We use --j/10|0 to access the needed "quarter computing"
JavaScript (Node.js), 96 bytes
Pretty decent solution, IMO, but it can hardly beat the one from Ilmari Karonen
[...'1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'].map((e,i,a)=>i<38&&console.log(e+a[i+1]+a[i+2]))
The explanation is simple:
- Like a lot of solution, I use a pre-order string.
- I split it and iterate over i.
- For every item, I display the concatenation of this current item and the 2 next items
Uiua, 36 bytes
⧈⊟₃♭⍥⇌◿2°⊏↯4_∞⊂+@0↻1⇡10⊂+@A⇡26".,?!"
Try it!
this feels too long. hm.
⧈⊟₃♭⍥⇌◿2°⊏↯4_∞⊂+@0↻1⇡10⊂+@A⇡26".,?!"
".,?!" # punctuation
⊂+@A⇡26 # add alphabet
⊂+@0↻1⇡10 # add numbers
↯4_∞ # turn into 4x10
⍥⇌◿2°⊏ # flip every other row
⧈⊟₃♭ # flatten and take windows
PowerShell 6+, 62 bytes
0..37|%{'1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'|% s*g $_ 3}
where s*g is the shorcut for the Substring method.
Japt -R, 27 bytes
;9õ pUB".,?!" ¬ò10 ËzEÑìã3
;9õ pUB".,?!" ¬ò10 ËzEÑìã3
9õ :Range [1,9]
p :Push
U : 0
; B : Uppercase alphabet
".,?!" : String literal
¬ :Join
ò10 :Partitions of length 10
Ë :Map each string a 0-based index E
z : Rotate clockwise 90 degrees
EÑ : E*2 times
à :End map
¬ :Join
ã3 :Substrings of length 3
:Implicit output, joined with newlines
05AB1E, 24 bytes
žhÀAu".,?!"«Tô2Å€R}J«ü3»
Minor alternative:
Au".,?!"«TôžhÀšεNFR]Jü3»
Explanation:
žh # Push builtin "0123456789"
À # Rotate it once to the left: "1234567890"
Au # Push the uppercase alphabet
".,?!"« # Append ".,?!" to it
Tô # Split it into parts of size 10:
# ["ABCDEFGHIJ","KLMNOPQRST","UVWXYZ.,?!"]
2Å€ } # For every 2nd item (0-based index modulo 2 == 0):
R # Reverse it
# ["JIHGFEDCBA","KLMNOPQRST","!?,.ZYXWVU"]
J # Join the list together to a single string again:
# "JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"
« # Merge it to the digits:
# "1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"
ü3 # Create overlapping triplets
» # Join the list by newlines
# (after which it is output implicitly with trailing newline)
Au".,?!"«Tô # Same as above: ["ABCDEFGHIJ","KLMNOPQRST","UVWXYZ.,?!"]
žhÀ # Same as above: "1234567890"
š # Prepend it to the list:
# ["1234567890","ABCDEFGHIJ","KLMNOPQRST","UVWXYZ.,?!"]
ε # Map each string to:
NF # Loop the 0-based map-index amount of times:
R # Reverse the string every iteration
] # Close both the loop and map
J # Join the list together to a single string again:
# "1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"
ü3» # Same as above
# (after which it is output implicitly with trailing newline)
Brachylog, 26 bytes
Ị↺,Ạ,".,?!"ụḍ₄{i↔ⁱ⁾}ᶠcs₃ẉ⊥
Essentially a translation of my Jelly answer. A full program which prints the desired output with a trailing newline.
Ị "0123456789"
↺ rotated once to the left
, concatenated with
Ạ the alphabet (lowercase)
,".,?!" concatenated with ".,?!",
ụ uppercased,
ḍ₄ sliced into quarters.
c Concatenate
{ }ᶠ every possible result from
i taking a slice with its 0-index
↔ and reversing it
ⁱ⁾ a number of times equal to the index.
ẉ Print with a newline
s₃ a substring of length 3 from the concatenation,
⊥ then try again with a different substring.
If a trailing newline is unacceptable:
Brachylog, 27 bytes
Ị↺,Ạ,".,?!"ụḍ₄{i↔ⁱ⁾}ᶠcs₃ᶠ~ṇ
Outputs as a function.
Jelly, 24 23 bytes
ØDṙ1;ØA;“.,?!”s⁵UÐeFṡ3Y
Generates the keyboard top to bottom left to right, then boustrophedonizes it afterwards.
ØD "0123456789"
ṙ1 rotated once to the left
; concatenated with
ØA the uppercase alphabet
;“.,?!” concatenated with ".,?!".
s Chop it into slices of length
⁵ 10,
U (vectorized) reverse
Ðe the slices at even 1-indices,
F smash the slices back together,
ṡ3 take every contiguous sublist of length 3,
Y and join on newlines.
x86-16 machine code, PC DOS, 64 bytes
Binary:
00000000: b409 bb1b 01ba 1801 bf0a 24b1 2687 3fcd ..........$.&.?.
00000010: 2187 3f42 43e2 f6c3 3132 3334 3536 3738 !.?BC...12345678
00000020: 3930 4a49 4847 4645 4443 4241 4b4c 4d4e 90JIHGFEDCBAKLMN
00000030: 4f50 5152 5354 213f 2c2e 5a59 5857 5655 OPQRST!?,.ZYXWVU
Listing:
BB 011B MOV BX, OFFSET KB+3 ; pointer to end of 3 char substring
BA 0118 MOV DX, OFFSET KB ; pointer to beginning of 3 char substring
BF 240A MOV DI, 240AH ; string '$' + 0AH
B1 26 MOV CL, 38 ; number of lines
B4 09 MOV AH, 9 ; DOS API output string function
CLOOP:
87 3F XCHG DI, WORD PTR[BX] ; swap string term and LF char after 3 chars
CD 21 INT 21H ; write substring to console
87 3F XCHG DI, WORD PTR[BX] ; swap back
42 INC DX ; increment string start pointer
43 INC BX ; increment string end pointer
E2 F6 LOOP CLOOP ; loop until 38 lines
C3 RET ; return to DOS
KB:
DB '1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'
It's a bit of a naïve approach, but still fits well below the spec size (and is a nice power of 2). Loops through the string and swaps the relative 4th and 5th character with a LF followed by a string terminator and then outputs it.
Standalone DOS executable COM program. Output:
Head:
Tail:
Kotlin, 140 71 bytes
"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU".windowed(3).map{println(it)}
I just realized it's easier to use the string itself instead of generating it using ranges.
///, 151 bytes
123
234
345
456
567
678
789
890
90J
0JI
JIH
IHG
HGF
GFE
FED
EDC
DCB
CBA
BAK
AKL
KLM
LMN
MNO
NOP
OPQ
PQR
QRS
RST
ST!
T!?
!?,
?,.
,.Z
.ZY
ZYX
YXW
XWV
WVU
Can't golf it more? This is, in a sense, <152 bytes.
Haskell, 80
mapM_(putStrLn.take 3.(`drop`"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"))[0..37]
Prolog, 131
This is probably why you never see Prolog entries. The newline is required (actually, any whitespace will do but there has to be whitespace).
z(S,L):-append(_,X,L),append(S,_,X),length(S,3).
:-forall(z(X,"1234567890JIHFEDCBAKLMNOPQRST!?,.ZYXWVU"),writef("%s\n",[X])),halt.
Ruby 69 65 62
Based on Groovy example
38.times{|i|p"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"[i,2]}
Q, 63
{(x;3)sublist"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"}'[(!)38]
Q (66 63 chars)
(((!)38),'3)sublist\:"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"
J, 66 62 45 characters
Turns out I was being too clever by half.
3]\'1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'
is all I needed all along.
Previously:
_2}.|:>(];1&|.;2&|.)'1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'
and:
38 3$($:@}.,~3$])^:(3<#)'1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'
APL, 43 characters
⍪3,/(1⌽⎕D),(⌽10↑⎕A),(10↑10⌽⎕A),'!?,.',6↑⌽⎕A
This works on Dyalog APL. I managed to save a couple characters by generating the output string (everything after ⊃). I'll write up an explanation when I get some time!
Here's how the output looks:
⍪3,/(1⌽⎕D),(⌽10↑⎕A),(10↑10⌽⎕A),'!?,.',6↑⌽⎕A
123
234
345
456
567
678
789
890
90J
0JI
JIH
IHG
HGF
GFE
FED
EDC
DCB
CBA
BAK
AKL
KLM
LMN
MNO
NOP
OPQ
PQR
QRS
RST
ST!
T!?
!?,
?,.
,.Z
.ZY
ZYX
YXW
XWV
WVU
Explanation, from right to left:
- First, we construct the string seen in all of the other entries:
6↑⌽⎕A:⎕Agives us a string of the uppercase alphabet, from A to Z. We then reverse it (⌽) and take (↑) the first 6 characters of it, giving us'ZYXWVU'. (In retrospect, this approach doesn't end up saving any characters, but I'll leave it because it fits in better.)'!?,.',: We concatenate (,) the string'!?,.'with the previous result.(10↑10⌽⎕A),: We take the first 10 characters (10↑) of the alphabet, which is first rotated ten times (10⌽), and concatenate this with the previous result. As an example of rotation,5⌽'abcdef'(the string'abcdef'rotated 5 times) gives us'cdefab'.(⌽10↑⎕A),: Take the first 10 characters of the alphabet and reverse them, and concatenate this with the previous string.(1⌽⎕D),:⎕Dgives us the digits as a string, from 0 to 9, inclusive. We then rotate ('⌽') this string by 1, yielding'1234567890'. As before, we concatenate this with the previous result.
- Now that we have our string built (which saved us 3 characters from the APL representation, due to surrounding quotes), we do some magic to build our final output:
3,/: We take the string, in groups of three characters, and concatenate them.- To finish it off, we use
⍪to ravel our vector of strings (really a vector of character vectors) along the first dimension. This has the effect of changing its shape from38to38 1(a 38x1 matrix).
Smalltalk 102 99
1to:38 do:[:i|x:='1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'copyFrom:i to:i+2.Transcript cr show:x]
I don't know Smalltalk very well so it's a little bit strange to me. It's compiles with gst others are not tested.
C, 98 104 characters
Since no one else has done so yet, I thought I would try actually generating the string on the fly, using some kind of run-length encoding for ascending and descending runs.
EDIT: After a number of iterations, here's finally a "clever" solution that ties with the shortest "dumb" solution in C at 98 characters:
char*s="0º.ÿK»Jº ü=ÿ*ø[×",a[99],*p=a,i;main(j){for(;i-=i<8?j=*s++,*s++:8;puts(p++))p[2]=j+=i%4-1;}
The code requires an 8-bit Latin-1 encoding (ISO-8859-1 or Windows-1252), which should work fine on all commonly used platforms, but saving the source with some less popular 8-bit code page, or UTF-8 will not work.
The data string was created by the following piece of emacs lisp:
(require 'cl)
(apply 'concat
(let ((last-remainder 0))
(loop for (begin count step twiddle)
in '((?1 9 +1 4) (?0 1 +2 4) (?J 10 -1 4) (?K 10 +1 0)
(?! 1 +1 4) (?? 1 +2 4) (?, 2 +2 4) (?Z 6 -1 8))
append (prog1 (list (char-to-string (- begin step))
(char-to-string
(logand 255 (- last-remainder
(+ (* 8 (- count 1)) (+ step 1)
twiddle)))))
(setq last-remainder (+ (logand twiddle 7) step 1))))))
The "twiddle" bit is used to avoid unprintable ASCII control characters in the encoded data string, and to ensure that i==0 only at the end of the output.
C, 98 characters
However, even in C you can get a short program by simply printing consecutive triplets from the original string:
main(){char s[]="12,34567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU",*p=s+2;for(;*p=p[1];puts(p-3))*++p=0;}
Scala 70 chars:
"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU".sliding(3,1).mkString("\n")
Python, 73
for i in range(38):print"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"[i:i+3]
JavaScript, 83 chars
for(i=0;i<38;)console.log('1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'.substr(i++,3))
Decided to see if I could beat stephencarmody's solution. This is what I came up with.
Groovy, 73
(0..37).each{println"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"[it..it+2]}
All the clever stuff I tried turned out to be longer than doing it the dumb way.
Mathematica, 73
I independently arrived at the same method as everyone else:
Grid@Partition[Characters@"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU",3,1]
Perl, 63 chars
say for"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"=~/(?=(...))/g
This solution uses the say function (available since Perl 5.10.0 with the -E switch, or with use 5.010). Without it, the best I can do is 67 chars (and an extra newline at the end of the output):
print"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"=~/(?=(...))/g,$,=$/
Earlier 65-char solution:
s//1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU/;s!(?=(...))!say$1!eg
Replacing say$1 with print$1.$/ lets the code run on older perls, at the cost of 5 extra characters.
D 124 chars
import std.stdio;void main(){enum s="1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU";
foreach(i;3..s.length){writeln(s[i-3..i)]);}}
Perl, 73 characters:
print substr('1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU',$_,3),$/for 0..37
Perl, 66 characters:
say substr"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU",$_,3for 0..37
when called by:
perl -E 'say substr"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU",$_,3for 0..37'
R (75 characters)
embed(strsplit("1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU","")[[1]],3)[,3:1]
What does this do?
strsplitsplits a string into substrings, in this case individual charactersembedis a really useful function that turns a vector into an array of overlapping elements- The rest is just indexing and sorting columns in the right order.
This produces and prints an array of characters:
> embed(strsplit("1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU","")[[1]],3)[,3:1]
[,1] [,2] [,3]
[1,] "1" "2" "3"
[2,] "2" "3" "4"
[3,] "3" "4" "5"
[4,] "4" "5" "6"
[5,] "5" "6" "7"
[6,] "6" "7" "8"
[7,] "7" "8" "9"
[8,] "8" "9" "0"
[9,] "9" "0" "J"
[10,] "0" "J" "I"
[11,] "J" "I" "H"
[12,] "I" "H" "G"
[13,] "H" "G" "F"
[14,] "G" "F" "E"
[15,] "F" "E" "D"
[16,] "E" "D" "C"
[17,] "D" "C" "B"
[18,] "C" "B" "A"
[19,] "B" "A" "K"
[20,] "A" "K" "L"
[21,] "K" "L" "M"
[22,] "L" "M" "N"
[23,] "M" "N" "O"
[24,] "N" "O" "P"
[25,] "O" "P" "Q"
[26,] "P" "Q" "R"
[27,] "Q" "R" "S"
[28,] "R" "S" "T"
[29,] "S" "T" "!"
[30,] "T" "!" "?"
[31,] "!" "?" ","
[32,] "?" "," "."
[33,] "," "." "Z"
[34,] "." "Z" "Y"
[35,] "Z" "Y" "X"
[36,] "Y" "X" "W"
[37,] "X" "W" "V"
[38,] "W" "V" "U"
Haskell, 94
main=putStr.unlines.take 38$take 3`map`iterate tail"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"
Javascript, 103
for(a='1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU';a.length>2;a=a.substring(1))console.log(a.substr(0,3))

