-2
\$\begingroup\$

Make a program that outputs the number of seconds from the beginning of today (00:00:00 of the day you run it) to the second you ran it. However, if this number is divisible by three, print Fizz instead. If it is divisible by five, print Buzz instead. If it is divisible by three and five, print FizzBuzz.

Don't pad the number printed with extra zeroes (44 instead of 00044). You don't need to take leap seconds into account (saying for the universe in which people answer this years after I post it). Standard loopholes apply, shortest program wins.

\$\endgroup\$
  • \$\begingroup\$ Beginning of today as in 13th of June or Midnight of the day you run it? \$\endgroup\$ – Veskah Jun 13 at 15:49
  • \$\begingroup\$ Midnight of the day you run it. \$\endgroup\$ – Andrew Jun 13 at 15:51
  • 11
    \$\begingroup\$ I know you're not a new user, but I still strongly suggest using the sandbox to help iron out your challenges. The couple of days' worth of feedback is always well worth it! \$\endgroup\$ – Giuseppe Jun 13 at 15:52
  • 12
    \$\begingroup\$ This is a just a composition of an existing challenge with 'get the seconds since midnight'. I don't see what that adds. \$\endgroup\$ – Jonathan Allan Jun 13 at 16:34
  • \$\begingroup\$ I more intended this as a way to add a time element to FizzBuzz. I guess this adds text replacement but I dunno. \$\endgroup\$ – Andrew Jun 13 at 16:42

14 Answers 14

3
\$\begingroup\$

Jelly, 26 bytes

A simple port of Dennis's "1-2-fizz-4-buzz" solution which evaluates the formatted time as seconds first

7ŒTṣ”:Vḅ60µ3,5ḍTị“¡Ṭ4“Ụp»ȯ

Try it online!

\$\endgroup\$
2
\$\begingroup\$

05AB1E, 33 30 bytes

-3 bytes from Grimy

žažbžc)60βÐ3Öi"Fizz"?}5Öi”ÒÖ”,

Try it online!

\$\endgroup\$
  • 2
    \$\begingroup\$ žažbžc)60β for -3 bytes. \$\endgroup\$ – Grimy Jun 14 at 7:35
2
\$\begingroup\$

Python 2, 73 bytes

import time
a=time.time()%86400//1
print(a%3<1)*"Fizz"+(a%5<1)*"Buzz"or a

Try it online!

-37 bytes using time.time instead of datetime thanks to negative seven
-4 bytes thanks to ArBo (switched to Python 2)

\$\endgroup\$
  • \$\begingroup\$ 77 with time.time() \$\endgroup\$ – negative seven Jun 15 at 6:55
  • \$\begingroup\$ @negativeseven oh huh, good idea. thanks! \$\endgroup\$ – HyperNeutrino Jun 15 at 7:24
  • \$\begingroup\$ You can save two bytes on the print parentheses by switching to Python 2. Also, if outputting numbers with a trailing .0 is allowed, you can change int(...) to ...//1 for two more bytes. \$\endgroup\$ – ArBo Jun 15 at 11:54
  • \$\begingroup\$ @ArBo Oh nice, thanks! \$\endgroup\$ – HyperNeutrino Jun 15 at 14:10
1
\$\begingroup\$

Batch, 145 bytes

@set s=%time:~,8%
@set/as=((%s::=)*60+%,f=s%%3,b=s%%5,t=f+b
@for %%a in (Fizz.%f% Buzz.%b% FizzBuzz.%t%)do @if %%~xa==.0 set s=%%~na
@echo %s%

Explanation: %time% is (at least on my system) formatted hh:mm:ss.ff so we start by chopping off the fractions of seconds. Then the shortest way to do the base 60 conversion is to replace the :s with operators and evaluate, and the divisibility by 3, 5 and 15 is also calculated. This is then tested and the number of seconds replaced with the appropriate string if necessary before being printed.

\$\endgroup\$
1
\$\begingroup\$

MathGolf, 24 bytes

t♪/╔%_╕Σ╠δ╕┌╠δ`+Γ\35α÷ä§

Try it online!

Explanation

t                          unix timestamp as integer milliseconds
 ♪/                        divide by 1000
   ╔%                      modulo 86400
     _                     duplicate TOS
      ╕Σ╠δ                 Decompress "Σ╠" and capitalize to get "Fizz"
          ╕┌╠δ             Decompress "┌╠" and capitalize to get "Buzz"
              `            duplicate the top two items
               +           pop a, b : push(a+b)
                Γ          wrap last four elements in array
                 \         swap top elements (swaps 2nd copy of time to TOS)
                  35α      push [3, 5]
                     ÷     is divisible
                      ä    convert from binary
                       §   get from array
\$\endgroup\$
1
\$\begingroup\$

PowerShell, 117 94 90 71 bytes

-23 bytes thanks to mazzy
-4 bytes thanks to AdmBorkBork
-19 bytes thanks to mazzy again

(([int]$x=date|% tim*|% t*ls*),('Fizz'*!($x%3)+'Buzz'*!($x%5))|sort)[1]

Try it online!

An even cheaper way to compute the day's seconds. TotalSeconds also returns as a float so that had to be truncated as well. Plugs that value into this Fizzbuzz answer by AdmBorkBork so give him a thumbs-up as well.

\$\endgroup\$
  • 1
    \$\begingroup\$ TimeOfDay ? \$\endgroup\$ – mazzy Jun 13 at 18:23
  • 1
    \$\begingroup\$ You can just do date instead of Get-Date for -4. \$\endgroup\$ – AdmBorkBork Jun 13 at 20:24
  • \$\begingroup\$ @AdmBorkBork D'oh, thanks \$\endgroup\$ – Veskah Jun 14 at 3:29
  • 1
    \$\begingroup\$ 71 bytes? \$\endgroup\$ – mazzy Jun 15 at 16:12
0
\$\begingroup\$

Jelly, 45 bytes

%3,5¬ȧ"“Fizz“Buzz”o"““”Fȯ⁸
7ŒTṣ”:V×⁽½c,60,1SÇ

Try it online!

This is so bad

34 bytes if I steal Dennis's FizzBuzz

\$\endgroup\$
0
\$\begingroup\$

Bash, 154

z=$(($(date +%s)-$(date -d "$(date +%F) 0" +%s)))
[[ 0 -eq "($z%3)" ]]&&a=1&&echo -n "fizz"
[[ 0 -eq "($z%5)" ]]&&echo "buzz"||[ $a -eq 1 ]&&echo||echo $z

could probably golf down last two lines...

\$\endgroup\$
0
\$\begingroup\$

JavaScript (Node.js), 125 120 bytes

x=Date().match(/\d\d/g).slice(3,6).reduce((a,j,i)=>a+=60**(2-i)*j)
console.log((x%3==0?'Fizz':'')+(x%5==0?'Buzz':'')||x)

Try it online!


First line parses a date string for [hours, minutes, seconds] and adds them together, second line is just FizzBuzz.

\$\endgroup\$
  • \$\begingroup\$ 107 bytes (also fixes the bug that made your answer wrong in your reduce function) \$\endgroup\$ – Expired Data Jun 14 at 15:16
  • \$\begingroup\$ Very nice, thanks! We don't have to put console.log in the answer? \$\endgroup\$ – Ian Jun 14 at 17:09
  • \$\begingroup\$ Input/output methods are lax to a degree. Specifying a lambda is fine, so rather than outputting to a specific IO stream we just output from our function. \$\endgroup\$ – Expired Data Jun 14 at 17:11
0
\$\begingroup\$

Perl 5, 74 bytes

$t+=$_*60**$g++for(gmtime)[0..2];say+(($t%3==0&&Fizz).($t%5==0&&Buzz))||$t

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Bash, 76 bytes

date +'%H 60*%M+60*%S+[p]sc[[]sc[Fizz]n]sa[[]sc[Buzz]n]sbd3%0=ad5%0=blcx'|dc

Try it online!

\$\endgroup\$
0
\$\begingroup\$

APL (Dyalog Unicode), 40 bytesSBCS

{∨/d←0=4/3 5|⍵:d/'FizzBuzz'⋄⍵}60⊥3↑3↓⎕TS

Try it online!

⎕TSTime Stamp; e.g. [2019,06,14,07,48,20,317]

3↓ drop three; e.g. [07,48,20,317]

3↑ take three; e.g. [07,48,20]

60⊥ evaluate as base-60 digits; e.g. 28100

{} apply the following anonymous lambda to that:

 the argument; e.g. 28100

3 5| the division remainder when that is divided by 3 and 5; e.g. [2,0]

0= Boolean mask where that is equal to 0; e.g. [0,1]

4/ replicate those numbers for 4 copies of each; e.g. [0,0,0,0,1,1,1,1]

d← assign that to d

∨/: if any of those are true (OR-reduction); e.g. true:

  d/'FizzBuzz' use d to mask the characters of the string; e.g. "Buzz"

 else:

 the argument; e.g. 28100

\$\endgroup\$
0
\$\begingroup\$

AutoIt, 90 bytes

$a=(@HOUR*60+@MIN)*60+@SEC
ConsoleWrite($a&(Mod($a,3)=0?"Fizz":"")&(Mod($a,5)=0?"Buzz":""))

It looks really bad without whitespace.

(FYI: AutoIt is a Windows basic-like scripting language)

\$\endgroup\$
0
\$\begingroup\$

Pyth, 36 bytes

Js%.dZ84600|+*!%J3"Fizz"*!%J5"Buzz"J

Try it online!

Loosely based on the Python 2 answer.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.