Skip to main content
deleted 1 character in body
Source Link
Moris Zucca
  • 1.6k
  • 11
  • 17

APL 6766

,/'∊' ',¨{a←⌽'0.....9.86'[⎕D⍳b←⍕⍵]⋄'.'∊a:b⋄('0'=⊃a)∨⍵=⍎a:b⋄b,'.'}¨0,⍳

Explanation:

¨0,⍳           applies the function to each number 0-n
a←⌽'0.....9.86'[⎕D⍳b←⍕⍵] inverts 6s and 9s, leaving 8s and 0s, and replacing other numbers with dots. Reverses vector after substitution.
'.'∊a          if there is a dot in the number....
('0'=⊃a)       .. or if the number starts with 0...
⍵=⍎a           or if the (inverted) number is the same as original
:b             then print the original number
b,'.'          else print a dot in the end
,/'∊' ',¨        Finally to give the result in the asked format i add a single space after each result and join them all 

Try it on tryapl.org

Note that in the online interpreter the ⍎ function doesn't work so i had to substitute it with 2⊃⎕VFI which does the same in this case, executes and returns the number, given a string.

APL 67

,/' ',¨{a←⌽'0.....9.86'[⎕D⍳b←⍕⍵]⋄'.'∊a:b⋄('0'=⊃a)∨⍵=⍎a:b⋄b,'.'}¨0,⍳

Explanation:

¨0,⍳           applies the function to each number 0-n
a←⌽'0.....9.86'[⎕D⍳b←⍕⍵] inverts 6s and 9s, leaving 8s and 0s, and replacing other numbers with dots. Reverses vector after substitution.
'.'∊a          if there is a dot in the number....
('0'=⊃a)       .. or if the number starts with 0...
⍵=⍎a           or if the (inverted) number is the same as original
:b             then print the original number
b,'.'          else print a dot in the end
,/' ',¨        Finally to give the result in the asked format i add a single space after each result and join them all 

Try it on tryapl.org

Note that in the online interpreter the ⍎ function doesn't work so i had to substitute it with 2⊃⎕VFI which does the same in this case, executes and returns the number, given a string.

APL 66

∊' ',¨{a←⌽'0.....9.86'[⎕D⍳b←⍕⍵]⋄'.'∊a:b⋄('0'=⊃a)∨⍵=⍎a:b⋄b,'.'}¨0,⍳

Explanation:

¨0,⍳           applies the function to each number 0-n
a←⌽'0.....9.86'[⎕D⍳b←⍕⍵] inverts 6s and 9s, leaving 8s and 0s, and replacing other numbers with dots. Reverses vector after substitution.
'.'∊a          if there is a dot in the number....
('0'=⊃a)       .. or if the number starts with 0...
⍵=⍎a           or if the (inverted) number is the same as original
:b             then print the original number
b,'.'          else print a dot in the end
∊' ',¨        Finally to give the result in the asked format i add a single space after each result and join them all 

Try it on tryapl.org

Note that in the online interpreter the ⍎ function doesn't work so i had to substitute it with 2⊃⎕VFI which does the same in this case, executes and returns the number, given a string.

added 359 characters in body
Source Link
Moris Zucca
  • 1.6k
  • 11
  • 17

APL 45 - WRONG67

Wrong for some test cases, I'm leaving the answer here anyway while looking for a correct version.

,/b↓¨⍨¯2+' ',¨{a←⌽'0.....9.86'[⎕D⍳b←⍕⍵]⋄'.'∊a:b⋄(∧/~'123457'∊⍨↑b'0'=⊃a)∧∨/'69'∊⍨↑b←1⍕¨0∨⍵=⍎a:b⋄b,'.'}¨0,⍳

Explanation:

b←1⍕¨0¨0,⍳            applies the function to createseach vectornumber 10-n,
a←⌽'0.....9.86'[⎕D⍳b←⍕⍵] appendsinverts 06s and 9s, leaving 8s and formats0s, alland withreplacing 1other decimalnumbers point
∨/'69'∊⍨↑bwith dots. Reverses vector after substitution.
'.'∊a         checks if 6there oris 9a aredot in eachthe number....
(∧/~'123457'∊⍨↑b'0'=⊃a)     .  ..and or if 1the number starts with 0..7.
⍵=⍎a are not
b↓¨⍨¯2+         or if the (inverted) number is the same addsas -2original
:b to the binary sequence and drops the last x elements for each formattedthen print the original number
b,/'.'          else print a dot in the end
,/' ',¨        Finally to joinsgive the obtainedresult numberin sothe onlyasked format i add a single space isafter lefteach betweenresult and join them all 

Try it on tryapl.orgtryapl.org

Note that in the online interpreter the ⍎ function doesn't work so i had to substitute it with 2⊃⎕VFI which does the same in this case, executes and returns the number, given a string.

APL 45 - WRONG

Wrong for some test cases, I'm leaving the answer here anyway while looking for a correct version.

,/b↓¨⍨¯2+(∧/~'123457'∊⍨↑b)∧∨/'69'∊⍨↑b←1⍕¨0,⍳

Explanation:

b←1⍕¨0,⍳                creates vector 1-n, appends 0, and formats all with 1 decimal point
∨/'69'∊⍨↑b             checks if 6 or 9 are in each number...
(∧/~'123457'∊⍨↑b)     ...and if 1..7 are not
b↓¨⍨¯2+                 adds -2 to the binary sequence and drops the last x elements for each formatted number
,/                     joins the obtained number so only a space is left between them

Try it on tryapl.org

APL 67

,/' ',¨{a←⌽'0.....9.86'[⎕D⍳b←⍕⍵]⋄'.'∊a:b⋄('0'=⊃a)∨⍵=⍎a:b⋄b,'.'}¨0,⍳

Explanation:

¨0,⍳           applies the function to each number 0-n
a←⌽'0.....9.86'[⎕D⍳b←⍕⍵] inverts 6s and 9s, leaving 8s and 0s, and replacing other numbers with dots. Reverses vector after substitution.
'.'∊a          if there is a dot in the number....
('0'=⊃a)       .. or if the number starts with 0...
⍵=⍎a           or if the (inverted) number is the same as original
:b             then print the original number
b,'.'          else print a dot in the end
,/' ',¨        Finally to give the result in the asked format i add a single space after each result and join them all 

Try it on tryapl.org

Note that in the online interpreter the ⍎ function doesn't work so i had to substitute it with 2⊃⎕VFI which does the same in this case, executes and returns the number, given a string.

added 110 characters in body
Source Link
Moris Zucca
  • 1.6k
  • 11
  • 17

APL 45 - WRONG

Wrong for some test cases, I'm leaving the answer here anyway while looking for a correct version.

⊃,/b↓¨⍨¯2+(∧/~'123457'∊⍨↑b)∧∨/'69'∊⍨↑b←1⍕¨0,⍳

Explanation:

b←1⍕¨0,⍳                creates vector 1-n, appends 0, and formats all with 1 decimal point
∨/'69'∊⍨↑b             checks if 6 or 9 are in each number...
(∧/~'123457'∊⍨↑b)∧     ...and if 1..7 are not
b↓¨⍨¯2+                 adds -2 to the binary sequence and drops the last x elements for each formatted number
⊃,/                     joins the obtained number so only a space is left between them

Try it on tryapl.org

APL 45

⊃,/b↓¨⍨¯2+(∧/~'123457'∊⍨↑b)∧∨/'69'∊⍨↑b←1⍕¨0,⍳

Explanation:

b←1⍕¨0,⍳                creates vector 1-n, appends 0, and formats all with 1 decimal point
∨/'69'∊⍨↑b             checks if 6 or 9 are in each number...
(∧/~'123457'∊⍨↑b)∧     ...and if 1..7 are not
b↓¨⍨¯2+                 adds -2 to the binary sequence and drops the last x elements for each formatted number
⊃,/                     joins the obtained number so only a space is left between them

Try it on tryapl.org

APL 45 - WRONG

Wrong for some test cases, I'm leaving the answer here anyway while looking for a correct version.

⊃,/b↓¨⍨¯2+(∧/~'123457'∊⍨↑b)∧∨/'69'∊⍨↑b←1⍕¨0,⍳

Explanation:

b←1⍕¨0,⍳                creates vector 1-n, appends 0, and formats all with 1 decimal point
∨/'69'∊⍨↑b             checks if 6 or 9 are in each number...
(∧/~'123457'∊⍨↑b)∧     ...and if 1..7 are not
b↓¨⍨¯2+                 adds -2 to the binary sequence and drops the last x elements for each formatted number
⊃,/                     joins the obtained number so only a space is left between them

Try it on tryapl.org

Source Link
Moris Zucca
  • 1.6k
  • 11
  • 17
Loading