Front page | perl.golf | Postings from July 2002

## Re: potential Golf task - seconds -> years, days ...

Thread Next
From:
Steffen Mueller
Date:
July 21, 2002 03:45
Subject:
Re: potential Golf task - seconds -> years, days ...
Message ID:
006701c230a4\$38156050\$7e00a8c0@C850
```[cc'ed to golf@perl.org]

"Eli Bendersky" <just.answer@in.the.newsgroup> schrieb...
>     Hi all,
>
> Inspired by a computability discussion in a math group (you know, of
> the type "if every particle could calculate 1e50 ops/second, it would
> take N galaxies...") I started wondering how short can a program
> partitioning an amount of seconds to years, days, hours, minutes
> and seconds be made.
>
> For example:
>
> 30844803 seconds is:
>
> 1 year, 1 day, 0 hours, 0 minutes, 1 second
>
> The assumptions are simplistic, eg:
>
> minute = 60 seconds
> hour = 60 minutes
> day = 24 hours
> year = 365 days
>
>
> Perl is a language in which thinking of shortest programs to do
> something
> is the most fun, so this looks like a good place to post it.

The Perl Golf mailing list would probably be an even better place to post
this. Anyway, to get the guys on that list started, I cooked up a quick,
simple-minded solution that can still be improved a lot.

#!perl -l
\$b=\$ARGV[0];@a=(1,60,60,24,365);while(\$a=pop@a){\$a*=\$_ for@a;print
int\$b/\$a;\$b=\$b%\$a}

As always, I haven't spent a significant amount of time on this, so I expect
some golf@perl.org residents to cut this thing in half and make it work
nonetheless.

Steffen
--
@n=(544290696690,305106661574,116357),\$b=16,@c=' ,JPacehklnorstu'=~
/./g;for\$n(@n){map{\$h=int\$n/\$b**\$_;\$n-=\$b**\$_*\$h;\$c[@c]=\$h}c(0..9);
push@p,map{\$c[\$_]}@c[c(\$b..\$#c)];\$#c=\$b-1}print@p;sub'c{reverse @_}

```
Thread Next

nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About