A resposta mais curta vence.
Ele deve ser classificado e em 24 horas. A linha final não possui vírgula.
A saída deve ser a seguinte:
'00:00',
'00:30',
'01:00',
'01:30',
'02:00',
'02:30',
'03:00',
'03:30',
'04:00',
'04:30',
'05:00',
'05:30',
'06:00',
'06:30',
'07:00',
'07:30',
'08:00',
'08:30',
'09:00',
'09:30',
'10:00',
'10:30',
'11:00',
'11:30',
'12:00',
'12:30',
'13:00',
'13:30',
'14:00',
'14:30',
'15:00',
'15:30',
'16:00',
'16:30',
'17:00',
'17:30',
'18:00',
'18:30',
'19:00',
'19:30',
'20:00',
'20:30',
'21:00',
'21:30',
'22:00',
'22:30',
'23:00',
'23:30'
code-golf
kolmogorov-complexity
sequence
Espen Schulstad
fonte
fonte
Respostas:
Pitão, 26 bytes
Demonstração.
Começamos com o produto cartesiano de
range(24)
(U24
) com a string"03"
.Em seguida, mapeamos esses valores para a substituição de formatação de string apropriada (
m%"'%02d:%s0',"d
).Em seguida, as cadeias resultantes são unidas no caractere de nova linha (
jb
).Finalmente, removemos a vírgula à direita (
P
) e imprimimos.fonte
Befunge-93, 63 bytes
(animação feita com BefunExec )
fonte
Bash:
584746 caracteresfonte
echo \'{00..23}:{0,3}0\'|sed 's/ /,\n/g'
de 40 caracteres. Agradável. Obrigado. Mas eu prefiro fazer uso dabash
própria força.printf "'%s',\n" {00..23}:{0,3}0
printf "'%s'\n" {00..23}:{0,3}0|sed $\!s/$/,/
é 45 bytesCJam,
31 3029 bytesIsso é bem simples, usando a formatação printf:
Experimente online aqui
fonte
Python 2,
5856 bytesLike sentiao's answer but using a
for
loop, with slicing to remove the comma. Thanks to @grc for knocking off two bytes.fonte
"'%02d:%s0',"[:57-i]
Java - 119 bytes
I started with Java 8's StringJoiner, but that means including an import statement, so I decided to do it the old way:
Perhaps this can be improved by getting rid of the multiple occuring
String
andSystem
keywords.fonte
a
, move thei
increment, lose thefor
braces, and move the comma/newline to the beginning (which lets you use the shortersubstring
and get rid oflength()
). Since functions are allowed by default, you can get make it even shorter by eliminating boilerplate:void f(){String s="";for(int i=0;i<24;)s+=String.format(",\n'%02d:00',\n'%02d:30'",i,i++);System.out.print(s.substring(2));}
Even a bit more if you make it just return the string instead of printing it, but that seems to go against the spirit, if not the letter.String.format
tos.format
. Your compiler/IDE may complain about it, but it works ;)Ruby,
94615651Thanks to @blutorange (again) for his help in golfing!
fonte
puts (0..47).to_a.map{|h|"'%02d:%02d'"%[h/2,h%2*30]}.join","
(there's a newline after the last comma)puts Array.new(48){|i|"'%02d:%02d'"%[i/2,i%2*30]}.join','
.join
with*
:)Perl,
52504845BWith help from ThisSuitIsBlackNot :)
fonte
JAVA
9594 bytesI love the fact that printf exists in Java:
Ungolfed
EDIT Replaced the
','
with44
fonte
Pyth,
3231 bytesI golfed something in python but it turned out to be exactly the same as Sp3000's answer. So I decided to give Pyth a try:
It's a exact translation of Sp3000 answer:
It's my first go at Pyth, so please do enlighten me about that 1 byte saving.
fonte
PHP, 109 bytes
fonte
Ruby,
5451 bytesfonte
\n
to actual newlines and removing the space betweenjoin
and"
. On the other hand, take note that the specified output has leading zeros for the hours.puts
to$><<
(without space) and.join
with*
. You still have the leading zero problem for the hours, though.C,
116,115,101,100,95,74,73, 71May be able to scrape a few more bytes off this...
fonte
T-SQL,
319307305 bytesUn-golfed version:
fonte
Pyth, 34 bytes
This can definitely be improved.
Try it online: Pyth Compiler/Executor
Explanation:
fonte
j+\,bm%"'%02d:%s0'",/d2*3%d2 48
with string formattingPython 2, 69 bytes
Quite obvious, but here's an explanation:
'0'
and'3'
in string format is shorter than a list%02d
does the padding forh
m
doesn't need padding as the alternating character is on a fixed position'\n'.join()
solves the final-line requirementsI have no idea if it can be done shorter (in Python 2).by Sp3000, 61 bytes :
print',\n'.join("'%02d:%s0'"%(h/2,h%2*3)for h in range(48))
fonte
print',\n'.join("'%02d:%s0'"%(h/2,h%2*3)for h in range(48))
m
. (Also it's 59 bytes, not 61)Haskell, 85 bytes
Unfortunately
printf
requires a 19 byteimport
, so I cannot use it.fonte
Julia:
656461 charactersJulia: 64 characters
(Kept here to show Julia's nice
for
syntax.)fonte
Fortran 96
Standard abuse of types & requirement only for the final
end
for compiling. Sadly, due to implicit formatting, the'(a)'
in the finalprint
statement is required. Still, better than the C and C++ answers ;)fonte
JavaScript (ES6),
7786+1 bytesDidn't realize there had to be quotes on each line (+1 is for
-p
flag with node):old solution:
ungolfed version (using a for loop instead of
Array.from
):fonte
Array.from(Array(48),(d,i)=>`'${i>19?"":0}${0|i/2}:${i%2*3}0'`).join`,\n`
. Replace \n with an actual newline.golflua
5251 charsUsing ascii 44 =
,
and 0 a space saves a character.An ungolfed Lua version would be
The
if
statement is much like the ternary operatora > b ? 44 : 0
.fonte
C# - 120 bytes
fonte
Python,
60 5864 bytesUngolfed:
Try it online here.
fonte
𝔼𝕊𝕄𝕚𝕟, 39 chars / 67 bytes (non-competing)
Try it here (Firefox only).
Not a single alphabetical character in sight...
fonte
PHP,
69 7062 bytesTry it online
Outputting
'23:30'
at the end is a bit lame, and so is closing the php context using?>
without opening or re-opening it. An cleaner alternative (but 65 bytes) would be:Try it online
Thank you @Dennis for the tips. Alternative inspired by the contribution of @ismael-miguel.
fonte
<?...?>'23:30'
saves three bytes. Also, you can replace\n
with an actual newline.Swift, 74 bytes
Updated for Swift 2/3...and with new string interpolation...
fonte
Javascript, 89 bytes
fonte
Array.push()
supports? ;)for(i=a=[];i<24;)a.push((x=("0"+i++).slice(-2))+":00",x+":30");alert(a.join(",\n"))
"'"+
pieces to one:for(i=a=[];i<24;)a.push((x="'"+("0"+i++).slice(-2))+":00'",x+":30'");alert(a.join(",\n"))
Python 2: 64 bytes
fonte
print',\n'.join("'%02d:00',\n'%02d:30'"%(h,h)for h in range(24))
Ruby - 52 bytes
fonte
.join
for*
... It's common courtesy to instead of just posting a new answer with a minor improvement, to suggest the improvement to the original poster. See meta.codegolf.stackexchange.com/questions/75/…$><<
!Python 2,
7465 bytesWe generate a 2 line string for each hour, using text formatting:
This code is fairly clear, but the clever indexing and integer maths in the answer by Sp3000 gives a shorter solution.
fonte
"'%02u:00',\n'%02u:30'"%(h,h)
print',\n'.join("'%02u:%02u'"%(h,i)for h in range(24)for i in[0,30])