# Uptime Progress Bar

Write a program which parses the output of uptime and generates an anatomically suggestive progress bar (as shown) with a length equal to the current uptime in days:

$uptime 23:01 up 34 days, 7:30, 5 users, load averages: 0.23 0.27 0.24$ uptime|<command>
8==================================D


(34 days = 34 equal signs)

• @dmckee: Thanks for the edit. However, there's a minor spelling error: 'a anotomically' should read 'an anatomically'. – Joey Adams Mar 13 '11 at 0:11
• @Joey: And I misspelled "anatomically", too. Thanks. – dmckee --- ex-moderator kitten Mar 13 '11 at 0:13
• Hmm, just a nitpick, a "progress bar" for something that doesn't have a known end (so, you can't measure its progress) sounds weird. Maybe just "bar" would be enough? – houbysoft Mar 13 '11 at 1:19
• My uptime is 27 minutes :( – steenslag Mar 13 '11 at 22:24
• @userunknown It had relevance in the first version of this question. Have a look at the edits... – Gareth Apr 13 '12 at 11:24

# Ruby, 39

No input required (by shelling out):

w=~/up (\d*)/;puts '8'+'='*$1.to_i+'D'  Or from stdin (40 chars): gets=~/up (\d*)/;puts '8'+'='*$1.to_i+'D'

• Reduce by 2 characters by using string interpolation and a character literal: gets=~/up (\d*)/;puts "8#{?=*$1.to_i}D" – Michael Kohl Mar 13 '11 at 13:27 • The character count is exactly the same using interpolation and concatenation in this case. – david4dev Mar 13 '11 at 13:32 • It's not, copy paste them into your editor: twitpic.com/49413j – Michael Kohl Mar 13 '11 at 13:39 • 'gets=~/up (\d*)/;puts "8#{"="*$1.to_i}D"'.length=="gets=~/up (\d*)/;puts '8'+'='*$1.to_i+'D'".length #true – david4dev Mar 13 '11 at 13:46 • Save some chars in the last line:$><<?8+?=*$1.to_i+?D – steenslag Mar 13 '11 at 14:25 ## Bash, 71 characters a=uptime a=${a#*p } a=${a%% *};while((a--));do p==$p;done;echo I${p}I  I'm not that much into exposing my genuptimes on the internet, so I'm drawing a fence instead. It's the same character count. Think of resetting p between calls. Pure bash, 71 characters including uptime. $ uptime
23:35:12 up 159 days,  4:15, 15 users,  load average: 1.07, 0.63, 0.38


Well, well, well... mine's bigger than yours.

• In case it wasn't clear: you can shell out to your favorite language if you want (it doesn't need to be pure bash). Should I clarify the question? – Magnus Holm Mar 12 '11 at 22:55

## Perl - 26 24 characters

/p (\d+)/;say+8,"="x$1,D  Ran like so: $ uptime
04:52:39 up 17 days, 11:27,  3 users,  load average: 0.21, 0.07, 0.02
$uptime | perl -nE '/p (\d+)/;say+8,"="x$1,D'
8=================D


edit: Unquoted the final 'D' - thanks J B

• You can unquote the D. – J B Apr 1 '11 at 12:10

## Haskell, 88 characters

As is often the case, Haskell doesn't offer the most extreme golfability of some other languages, but does allow an elegant expression of the mathematical structures underlying the problem. Building on their seminal work in this field, I aim to introduce a Haskell implementation of the Holkins-Krahulik Approximation operator. Briefly, the operator ignores both its inputs and returns a phallus-printing function parameterized by shaft length.

_⁑≈≈≈⊃_=(\n->concat["8",take n$repeat '=',"D"]) main=interact$(0⁑≈≈≈⊃1).read.(!!2).words


Perl, 17 characters
Now with say:

say+8,"="x$F[2],D  Yields uptime | perl -naE 'say+8,"="x$F[2],D'


was:

print"8"."="x$F[2]."D"  Yields ]# uptime | perl -anle 'print"8"."="x$F[2]."D"'
8=========================D


(I can't "say", sadly)

## 57 characters

python -c "print'8'+'='*int(raw_input().split()[2])+'D'"


## 35 characters

awk '{printf"#%"$3"sp",p}'|tr \ \*  so, uptime 12:27μμ up 111 days, 2:36, 1 user, load averages: 0,07 0,03 0,00 uptime | awk '{printf"#%"$3"sp",p}'|tr ' ' '*'

#***************************************************************************************************************p


Edit: was

printf "#%awk '{print $3}'sp"|tr ' ' '*'  Edit 2: J B's comment (use \ instead of '') • Escape space and asterisk with a backslash instead of quoting for 2 chars. – J B Apr 1 '11 at 9:35 ## Windows PowerShell, 28 "8$('='*(-split$input)[2])D"  At least echo 23:01 up 34 days, 7:30, 5 users, load averages: 0.23 0.27 0.24|powershell -file uptime.ps1  yields the correct output, so it should be able to handle uptime's output. I cannot test, though, since GNUWin32 includes a broken uptime that tries to read from a non-existant file (Note to people porting Unix tools: Don't try to assume that Windows is a Unix and adheres to the same principles or conventions; there is no file containing the boot time on Windows). ## Common Lisp, 84 characters (defun p(s)(write 8)(loop repeat(read-from-string(subseq s 9))do(write'=))(write'D))  This takes the uptime string as input. It seems like there ought to be a shorter solution mapping #'write over a list, but if so I can't come up with it. • +1 You rarely see Common Lisp used here. – Helper Method Apr 28 '11 at 19:27 ## GolfScript (24 characters) ' '/{(;}3*(\;~'='*8\'D'  ## Haskell (73 characters) main=getLine>>=putStr.('8':).(++"D").(takerepeat '=').read.(!!2).words  ## C (131 characters) #define r(a);read(0,x,a), #define p ;putchar( x[9];main(i){for(r(1)i<3;i+=*x==32)r(9)0 p'8');for(i=atoi((int)x+2);i--p'='))p'D');}  • your Golfscript is 23 chars, not 24. Also, you can shorten it to 16, using selection by index(equals sign): ' '/3=~8\'='*'D' – Cristian Lupascu May 28 '12 at 18:59 ## PHP, 62 characters <?$d=split(" ",uptime);echo 8;while($d[3]--)echo"=";echo"D";  No input required, it shells out. ## Python (42) print('8'+int(input().split()[2])*"="+'D')  Note: Python 3 used for reducing total character count. # Python, 65 Bytes import sys print '8'+'='*int(sys.stdin.readline().split()[2])+'D'  test: echo '23:01 up 34 days, 7:30, 5 users, load averages: 0.23 0.27 0.24'|./time.py 8==================================D  ## PHP, 61 <?$n=split(' ',$argv[1]);$v=8;while($n[2]--)$v.'=';echo"$vD";  ### Common Lisp, 57 characters (excluding implementation/OS-specific shebang) #!/opt/local/bin/sbcl --script (do()((eql(read-char)#\p)(format t"8~v,,,'=<~>D"(read))))  Based on an attempt to satisfy Dr. Pain's answer's wish for a shorter way to write a repeated character. This one can be used in a pipeline as shown in the question. (The format string specifies to right-justify the empty string (between ~< and ~>), in a field of width specified by an argument, padded using the = character.) # K, 35 -1"8",(("I"$(" "\:0:0)@3)#"="),"D";


.

$uptime 17:21:47 up 242 days, 7:22, 35 users, load average: 0.33, 0.34, 0.44$ uptime | q t.k
8============================================================================ ...


## Bash 67 chars

read t u d w
echo -e '\t'|expand -t $d|sed 's/^/8/;s/ /=/g;s/$/B/;'


invocation to the letter of the assignment:

uptime | ./cg1570uptime-bar.sh


Much shorter

### just 54 chars:

with this variation:

echo -e '\t'|expand -t $3|sed 's/^/8/;s/ /=/g;s/$/B/;'


invocation, not 100% in accordance with the rules:

./cg1570uptime-bar.sh $(uptime)  output in both times: uptime && uptime | ./cg1570uptime-bar.sh 06:29:53 up 16 days, 21:03, 10 users, load average: 1.29, 1.34, 1.23 8================B  Non-everyday tricks:  read t u d w  reads 06:29:53=t, up=u, 16=d rest...=w without w, everything to the end would be put into$d.

expand is normally used to translate a tab into an amount of blanks and takes a parameter if you don't like 8.

Grabbing the 3rd parameter with $3 in echo -e '\t'|expand -t$3|sed 's/ /=/g' is even shorter, but needs an invocation, not fitting to the words of the rules.

### bash/zenity 38 short version, 68 longer version

read c o d e
zenity --scale --value=$d --max-value=497 --text=uptime  The short version ends after$d, the longer takes into account that we know a max-value and like to have helpful text:

# Gema, 24 characters

<D> d=8@repeat{$1;=}D;?=  Sample run: bash-4.4$ uptime
18:35:31 up 13 days,  7:53, 16 users,  load average: 0.31, 0.85, 1.24

bash-4.4$uptime | gema '<D> d=8@repeat{$1;=}D;?='
8=============D


# AutoHotkey, 39 bytes

d:=A_TickCount//=8.64e+7
Send 8{= %d%}D


No input. Result is sent to active window.
The built-in A_TickCount is the number of milliseconds since the computer was rebooted.