NB. Linda's Challenge 6
oit rt 'abcdef'
f
a f
e a f
f a d e
f a e d c
f e a b d c
oit rt 1 2 3 4 5 6
6
1 6
1 4 6
1 2 4 6
4 1 6 2 3
6 5 4 2 3 1
NB. Details follow, restrictions noted at end
sh =: ?&#~ { ] NB. shuffle
rt =: [: |. [: sh&> i.@# <@}."0 _ [: sh <"_1 NB. right triangle
]a =: 'abcdef'
abcdef
]art =: rt a
+-+-+-+-+-+-+
|b| | | | | |
+-+-+-+-+-+-+
|c|b| | | | |
+-+-+-+-+-+-+
|c|b|a| | | |
+-+-+-+-+-+-+
|c|e|b|a| | |
+-+-+-+-+-+-+
|c|e|a|d|b| |
+-+-+-+-+-+-+
|f|c|a|b|d|e|
+-+-+-+-+-+-+
]b =: 1 2 3 4 5 6
1 2 3 4 5 6
]brt =: rt b
+-+-+-+-+-+-+
|5| | | | | |
+-+-+-+-+-+-+
|2|5| | | | |
+-+-+-+-+-+-+
|2|6|5| | | |
+-+-+-+-+-+-+
|6|4|2|5| | |
+-+-+-+-+-+-+
|4|5|1|2|6| |
+-+-+-+-+-+-+
|3|1|4|5|6|2|
+-+-+-+-+-+-+
ia =: ([ , a: , ])/ NB. insert a:
it =: 3 : 0 " 1 NB. isosceles triangle from right triangle
xx =. y i. a:
((-xx-#y) # a:), ia xx {. y
)
it art
+-+-+-+-+-+-+-+-+-+-+-+
| | | | | |b| | | | | |
+-+-+-+-+-+-+-+-+-+-+-+
| | | | |c| |b| | | | |
+-+-+-+-+-+-+-+-+-+-+-+
| | | |c| |b| |a| | | |
+-+-+-+-+-+-+-+-+-+-+-+
| | |c| |e| |b| |a| | |
+-+-+-+-+-+-+-+-+-+-+-+
| |c| |e| |a| |d| |b| |
+-+-+-+-+-+-+-+-+-+-+-+
|f| |c| |a| |b| |d| |e|
+-+-+-+-+-+-+-+-+-+-+-+
it brt
+-+-+-+-+-+-+-+-+-+-+-+
| | | | | |5| | | | | |
+-+-+-+-+-+-+-+-+-+-+-+
| | | | |2| |5| | | | |
+-+-+-+-+-+-+-+-+-+-+-+
| | | |2| |6| |5| | | |
+-+-+-+-+-+-+-+-+-+-+-+
| | |6| |4| |2| |5| | |
+-+-+-+-+-+-+-+-+-+-+-+
| |4| |5| |1| |2| |6| |
+-+-+-+-+-+-+-+-+-+-+-+
|3| |1| |4| |5| |6| |2|
+-+-+-+-+-+-+-+-+-+-+-+
vertchars =: 25 124 { a.
oit =: 3 : 0
NB. produces open isosceles triangle from boxed right triangle y
rc =. 1:`{.@.(2=#) $ y NB. row count
dhr =. <: {. $ ": 0 { y NB. decrement height of row display
mhb =. (>: rc * dhr) $ 0 , (<: dhr) # 1 NB. mask for horz boundaries
NB. now remove horz then vert boundaries from display of (it y)
vertchars -."1~ mhb # ": it y
)
oit art
b
c b
c b a
c e b a
c e a d b
f c a b d e
oit brt
5
2 5
2 6 5
6 4 2 5
4 5 1 2 6
3 1 4 5 6 2
]c =: 6 4 $ 'Now is the timefor all '
Now
is
the
time
for
all
]crt =: rt c
+----+----+----+----+----+----+
|Now | | | | | |
+----+----+----+----+----+----+
|Now |for | | | | |
+----+----+----+----+----+----+
|is |for |Now | | | |
+----+----+----+----+----+----+
|the |Now |is |for | | |
+----+----+----+----+----+----+
|is |Now |for |all |the | |
+----+----+----+----+----+----+
|all |time|the |Now |for |is |
+----+----+----+----+----+----+
oit crt
Now
Now for
is for Now
the Now is for
is Now for all the
all time the Now for is
]d =: 3 2 4 $ 'Now is the timefor all '
Now
is
the
time
for
all
]drt =: rt d
+----+----+----+
|the | | |
|time| | |
+----+----+----+
|Now |the | |
|is |time| |
+----+----+----+
|the |for |Now |
|time|all |is |
+----+----+----+
oit drt
the
time
Now the
is time
the for Now
time all is
NB. For verb oit to work, arguments to verb rt need to be open and
NB. free of vertchars. I leave it as an exercise to remove these
NB. requirements!
Kip Murray
On 2/14/2012 3:54 AM, Linda Alvord wrote:
> Challenge 6 Many Many Cherry Trees PLEASE DO NOT RESPOND UNTIL 2/22/2012
> 12 am EST
>
>
>
>
>
> If necessary, ask questions, but try not to give away your strategy for
> solving the challenge.
>
>
>
> Design a function with no restrictions on style or specific functions.
>
> It should produce a triangle similar to the ones shown below. Each row is a
> successive scramble of the character string above it with one added symbol.
> The final line is a scramble of the entire list.
>
>
>
> gw 'many'
>
> a
> a n
> a y n
> a m y n
>
>
>
> gw 'many'
>
> m
> y m
> y a m
> n a m y
>
>
>
> gw 'cherrytrees'
>
> s
> r s
> h s r
> h r s y
> y s r e h
> e h r s r y
> y r e s h e r
> s e r r e y e h
> e s t e r e y h r
> r e r s t r y e e h
> e r c r h y r e t s e
>
> a=:gw '%%%####'
>
> a,.a,.a,.a
>
> % % % %
> % # % # % # % #
> % # % % # % % # % % # %
> % # # % % # # % % # # % % # # %
> # % # % # # % # % # # % # % # # % # % #
> # % # % % # # % # % % # # % # % % # # % # % % #
> # % # # # % % # % # # # % % # % # # # % % # % # # # % %
>
>
>
> Linda
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm