Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,23 @@
defmodule Box do
defp head do
Enum.chunk(~w(north east south west north), 2, 1)
|> Enum.flat_map(fn [a,b] ->
c = if a=="north" or a=="south", do: "#{a}#{b}", else: "#{b}#{a}"
[ a, "#{a} by #{b}", "#{a}-#{c}", "#{c} by #{a}",
c, "#{c} by #{b}", "#{b}-#{c}", "#{b} by #{a}" ]
end)
|> Enum.with_index
|> Enum.map(fn {s, i} -> {i+1, String.capitalize(s)} end)
end
def compass do
header = Enum.into(head, Map.new)
angles = Enum.map(0..32, fn i -> i * 11.25 + elem({0, 5.62, -5.62}, rem(i, 3)) end)
Enum.each(angles, fn degrees ->
index = rem(round(32 * degrees / 360), 32) + 1
:io.format "~2w ~-20s ~6.2f~n", [index, header[index], degrees]
end)
end
end
Box.compass

View file

@ -1,32 +1,29 @@
/*REXX program boxes the compass (from º headings ───> 32 point set). */
/*REXX program "boxes the compass" (from º headings ───► a 32 point set).*/
parse arg # /*allow a º heading to be specified.*/
if #='' then #= 0 16.87 16.88 33.75 50.62 50.63 67.5 84.37 84.38 101.25 118.12,
118.13 135 151.87 151.88 168.75 185.62 185.63 202.5 219.37,
219.38 236.25 253.12 253.13 270 286.87 286.88 303.75 320.62,
320.63 337.5 354.37 354.38 /* [↑] use default in degrees.*/
headings=0 16.87 16.88 33.75 50.62 50.63 67.5 84.37 84.38 101.25 118.12,
118.13 135 151.87 151.88 168.75 185.62 185.63 202.5 219.37,
219.38 236.25 253.12 253.13 270 286.87 286.88 303.75 320.62,
320.63 337.5 354.37 354.38 /*some sample compass headings. */
points= 'n nbe n-ne nebn ne nebe e-ne ebn e ebs e-se sebe se sebs s-se sbe',
's sbw s-sw swbs sw swbw w-sw wbs w wbn w-nw nwbw nw nwbn n-nw nbw'
points='n nbe n-ne nebn ne nebe e-ne ebn e ebs e-se sebe se sebs s-se sbe',
's sbw s-sw swbs sw swbw w-sw wbs w wbn w-nw nwbw nw nwbn n-nw nbw'
dirs= 'north south east west' /*define cardinal compass directions.*/
/* [↓] choose a degree (°) glyph. */
if 4=='f4'x then degSym='a1'x /*is this system an EBCDIC system? */
else degSym='f8'x /*although 'a7'x looks better: ° vs º*/
/*─────────────────────────── f8 a7*/
say right(degSym'heading',30) center('compass heading',20)
say right( '',30) copies('' ,20)
dirs='north south east west'
@ebcdic= 1=='f1'x
if @ebcdic then degSym='a1'x
else degSym='f8'x /*although, 'a7'x looks better, */
/*see line 1 (above).*/
say right(degSym'heading',30) center('compass heading',20)
say right( '',30) copies('' ,20)
do j=1 for words(headings)
x=word(headings,j)
say right(format(x,,2)degSym,30-1) ' ' boxHeading(x)
do j=1 for words(#); x=word(#,j) /*get one of the degree headings*/
say right(format(x,,2)degSym,30-1) ' ' boxHeading(x)
end /*j*/
exit
/*─────────────────────────────────────BOXHEADING subroutine────────────*/
boxHeading: _=arg(1)//360; if _<0 then _=360-_ /*normalize the heading.*/
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
boxHeading: _=arg(1)//360; if _<0 then _=360-_ /*normalize the heading.*/
_=word(points,trunc(max(1,(_/11.25+1.5)//33)))
do k=1 for words(dirs); d=word(dirs,k)
_=changestr(left(d,1),_,d)
end /*k*/
return changestr('b',_," by ")
/*next statement is ignored. */
return upper(changestr('b',_," by "),1) /*capitalizes the 1st letter.*/
do k=1 for words(dirs); d=word(dirs,k)
_=changestr(left(d,1), _, d)
end /*k*/
return changestr('b', _, " by ") /*expand "b" ──► "by"*/