1
\$\begingroup\$

Create a progress bar indicating year progress

Your code has to output the percentage of the year already passed form 1st of January of the current year.

You have to display a progress bar and the figure.

Input

You may use builtins to get the current date, if your language doesen't have it you can get date as input but it would be added to your byte count (has to ba a reasonable input format like 2017-05-12)

Output

Bar status: At least 10 different status relating to figure.

Figure: can be rounded or float, has to represent current (or input) day of the year / 365(366) * 100

Example

Today 2017-05-12

Output

▓▓▓▓▓░░░░░░░░░░ 36%

Take into account leap years informal definition (occurring evey 4 years) progess of the year for 12-Feb is 12% on leap years.

Inspiration

\$\endgroup\$
  • 3
    \$\begingroup\$ Are we free to choose the characters? \$\endgroup\$ – Jonathan Allan May 12 '17 at 15:11
  • \$\begingroup\$ you can use builtin date to get todays date or input date in an "adecuate" form (not unary). \$\endgroup\$ – marcosm May 12 '17 at 15:11
  • 5
    \$\begingroup\$ @MarcosM "as long as [it] looks like a bar" is very unclear. \$\endgroup\$ – Leaky Nun May 12 '17 at 15:17
  • 2
    \$\begingroup\$ @MarcosM This needs a tighter specification before it ready for main. Please could you address the issues raised? \$\endgroup\$ – Jonathan Allan May 12 '17 at 15:19
  • 4
    \$\begingroup\$ "take into account leap years" This contradicts the question which states that a year should be considered to be 365 days. If we are taking leap years into account, do we need to do so properly? As in a leap year is one that is divisible by 4, unless it's also divisible by 100, unless it's also divisible by 400. \$\endgroup\$ – Shaggy May 12 '17 at 15:42
4
\$\begingroup\$

PHP, 69 Bytes

for($p=date(z)/(364+date(L))*100^0;$i<100;)echo$i++>$p?_:Z;echo"$p%";

Try it online!

date

parameter z The day of the year (starting from 0) 0 through 365

parameter L Whether it's a leap year 1 if it is a leap year, 0 otherwise.

PHP+HTML, 49 Bytes Non-Competenting

<progress value=<?=date(z)?> max=<?=364+date(L)?>

add ></progress> if you don't want that the browser makes the rest

Output for today in the snippet

<progress value=131 max=364

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

Fourier, 68 bytes

Note, this has been invalidated by rule changes since it does not handle leap years

3d~D4d*30+D~s*100/365~p365(s>0{1}{9618asv~s}s{0}{9617a}i^~i)32apo37a

Try it in FourIDE!

Outputs the bar like in the question but with 365 segments instead of 15.

Makes the assumption that every year has 365 days and every month has 30 days.

Output for today, 12th May:

▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 36%

Explanation

Firstly, it looks at the day part of the date and the month part of the month. To get how many days have come before this month, you multiply the month by 30. You then add the day to number of days.

From that point, the calculations are academic and the only extra bytes are for drawing the bar.

\$\endgroup\$
  • \$\begingroup\$ How on earth did you answer 3 minutes ago when the question was closed 6 minutes ago? \$\endgroup\$ – Leaky Nun May 12 '17 at 15:25
  • \$\begingroup\$ @LeakyNun If you don't refresh the page while the question is open, you can still answer on closed questions ;) \$\endgroup\$ – Beta Decay May 12 '17 at 15:27
  • \$\begingroup\$ I thought this bug has been pointed out before I left (i.e. 9 months ago). \$\endgroup\$ – Leaky Nun May 12 '17 at 15:28
  • \$\begingroup\$ Maybe it has been on the desktop site, but it still exists on mobile \$\endgroup\$ – Beta Decay May 12 '17 at 15:29
  • \$\begingroup\$ "Each day has to display a different bar " \$\endgroup\$ – Jonathan Allan May 12 '17 at 16:04
1
\$\begingroup\$

JavaScript (ES8), 137 135 149 155 137 123 110 108 102 100 98 96 92 +7 bytes

Requires new Date to be passed as an argument for an additional 7 bytes.

n=>"=".repeat(v=(n-new Date(y=n.getFullYear(),0))/864e5/(y%4?3.65:3.66)|0).padEnd(100)+v+"%"

If we can't use spaces in the progress bar then 2 bytes will need to be added:

n=>"1".repeat(v=(n-new Date(y=n.getFullYear(),0))/864e5/(y%4?3.65:3.66)|0).padEnd(100,0)+v+"%"

Try It

o.innerText=(n=>"=".repeat(v=(n-new Date(y=n.getFullYear(),0))/864e5/(y%4?3.65:3.66)|0).padEnd(100)+v+"%")(new Date)
<pre id=o>

\$\endgroup\$
  • 1
    \$\begingroup\$ "Each day has to display a different bar " \$\endgroup\$ – Jonathan Allan May 12 '17 at 16:05
  • \$\begingroup\$ @Shaggy Turns out it was there from the start, just buried in the question... I wish it wasn't there though :P \$\endgroup\$ – Beta Decay May 12 '17 at 16:16
1
\$\begingroup\$

Ruby, 72+7 = 79 bytes

Uses -rdate flag. -1 byte from Tutleman.

t=Date.today;d=t.yday;e=t.leap??366:365;$><<?=*d+?-*(e-d)+" #{d*100/e}%"

Today's output (2017-05-17):

=========================================================================================================================================------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 37%
\$\endgroup\$
  • \$\begingroup\$ If I understand it correctly, you check with December 31st of the previous year, but this does not work for leap years. Dec 31st, 2016 is yday 366. \$\endgroup\$ – G B May 17 '17 at 14:12
  • \$\begingroup\$ If you use Date instead of Time, you can shave off a chunk of bytes using Date#leap? to check if it's a leap year, even after accounting for the -rdate flag. Also, you may be able to use String#ljust to shorten the number of bit where you add the dashes. \$\endgroup\$ – Tutleman May 17 '17 at 15:01
  • \$\begingroup\$ @GB yeah it seems I forgot the +1 on the year. The other comment meant I could take that check out anyways, though! \$\endgroup\$ – Value Ink May 17 '17 at 19:51
  • \$\begingroup\$ @Tutleman great! -1 byte, although I guess it would've been -3 because of my other mistake with the leap year check. ljust is too long, though; I lose 5 bytes using it. \$\endgroup\$ – Value Ink May 17 '17 at 19:52
0
\$\begingroup\$

C#, 133 bytes

using static System.DateTime;int k=Now.DayOfYear*100/(IsLeapYear(Now.Year)?366:365);()=>$" {k}%".PadLeft(103-k,'-').PadLeft(103,'@');

Uses '@' and '-' Symbols

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

Python 2, 134 bytes

Too long built-ins(

Try it online

from datetime import*
D=datetime
N=D.now()
Y=D(N.year,1,1)
P=100*(N-Y).days/-~(D(N.year,12,31)-Y).days
print'H'*P+'-'*(100-P)+'%s%%'%P

This line evaluates length of the current year to handle leap ones:

-~(D(N.year,12,31)-Y).days
\$\endgroup\$
0
\$\begingroup\$

Python 2, 91 bytes

from time import*
t=gmtime()
d=t.tm_yday
n=365+(t.tm_year%4<1)
print'#'*d+'-'*(n-d),d/.01/n

Progress bar is 366 characters long on the pseudo-leap years (from the specification) and 365 on others, but uses the actual day count as a numerator (so it will have precision errors on century non-leap years). This could be fixed with y=t.tm.year;n=[y%4,y%100,y%400].count(0)%2 in place of n=365+(t.tm_year%4<1)

Try it online! (added tomorrow's output for comparison using extra code in the footer)

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

Excel, 159 bytes

Relevant Quote: Quote

=LEFT(REPT("|",10*(Now()-DATE(YEAR(Now()),1,0))/(365+(MOD(YEAR(Now()),4)=0)))&"::::::::::",10) & 100*(Now()-DATE(YEAR(Now()),1,0))/(365+(MOD(YEAR(Now()),4)=0))

Example Output:

|||:::::::38.0821917808219

Note that the progress bar rounds down because of how REPT works.


If using multiple cells is acceptable (I would tend to say it's not), an alternative answer is 97 bytes.

A1: =YEAR(NOW())
A2: =10*(NOW()-DATE(A1,1,0))/(365+(MOD(A1,4)=0))
A3: =LEFT(REPT("|",A2)&"::::::::::",10)&10*A2

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

CJam, 75 bytes

et3<~@[sS+2m<~e|4%!:L28+T31@"\x1F\x1E\x1F\x1E\x1F\x1F\x1E\x1F\x1E\x1F":i~]@<:++e2 365L+/_'#*100'_*.e<S@'%

The bar goes up to 100, so it's a straight percentage bar.

The code for detecting leap years has been "borrowed" from Dennis's answer on another challenge.

The code contains several unprintable characters. They have been replaced by hex codes like \x1F in this answer.

Try it online!

or try it for every day in 2017

Explanation

et                e# Get the date/time.
3<~               e# Get the first three elements ([year month day]) and dump it on the stack.
@                 e# Bring the year to the top.
[                 e# Begin an array:
 sS+2m<~e|4%!     e#  Check if the current year is a leap year, returning 0 or 1.
 :L               e#  Save the result in L.
 28+              e#  Add it to 28.
 T31@             e#  Push 0 and 31, bring (28 or 29) to the top. 
                  e#    The 0 is there because you can't reduce an empty array (later...).
 "..........":i~  e#  Dump the char codes of the unprintable string into the array.
]                 e# Close array. This now contains the length of each month.
@                 e# Bring the month to the top.
<                 e# Slice the array before the month, to get only those that have passed.
:+                e# Sum the days in those months.
+                 e# Add that sum to the day of the month.
e2                e# Multiply the result by 100.
365L+/            e# Divide by 365+L to get the percentage.
_'#*              e# Duplicate it, and repeat '#' that many times.
100'_*            e# Push a string containing 100 underscores.
.e<               e# Superimpose the hashes onto the underscores.
S@'%              e# Push a space, bring the percentage to the top, and push '%'.
\$\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.