Now we can both wait for a virtuoso. Here's my first try which can probably
be simplified a lot.

  
     <"1 (":,.(>:i.12),>:i.12),.(12 2$'am'),12 2$'pm'
-----T----T----T----T----T----T----T----T----T----T----T----T----T----T----T
----T----T----T----T----T----T----T----T----┐
│ 1am│ 2am│ 3am│ 4am│ 5am│ 6am│ 7am│ 8am│ 9am│10am│11am│12am│ 1pm│ 2pm│ 3pm│
4pm│ 5pm│ 6pm│ 7pm│ 8pm│ 9pm│10pm│11pm│12pm│
L----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
----+----+----+----+----+----+----+----+-----
   
Now we can both wait for a virtuoso.  

Linda

-----Original Message-----
From: programming-boun...@forums.jsoftware.com
[mailto:programming-boun...@forums.jsoftware.com] On Behalf Of glts
Sent: Wednesday, April 02, 2014 8:12 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Pretty print hours of the 12-hour clock

On Wed, Apr 2, 2014 at 12:59 PM, chris burke <cbu...@jsoftware.com> wrote:
> The argument i.24 to fmthours may be unnecessary.
>
>
> In any case, you can generate all hours as:
>
>
> allhours=: , (;:'am pm') (,~":) each/ _1|.1+i.12
>
>
> Then fmthours is:
>
>
> fmthours=: {&allhours
>
>
> For example;
>
>
>    fmthours 4
>
> +---+
>
> |4am|
>
> +---+
>
>    fmthours i.24
>
> +----+---+---+---+...
>
> |12am|1am|2am|3am|...
>
> +----+---+---+---+...

Very nice and very instructive. It hadn't occurred to me to use 'each'
on an unboxed argument, this will be useful in the future.

And I had used this thing to obtain the hours:

   hours=: 12&(|`[@.(0=|))"0
   hours i.24
12 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11

Incrementing and shifting is simpler and more elegant. Thanks!


-- 
David
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to