Better display of problems and solutions
This commit is contained in:
parent
7edc20f556
commit
02a1a96ed6
2 changed files with 18 additions and 30 deletions
|
@ -42,6 +42,14 @@ article .header {
|
||||||
/* background: #eee; */
|
/* background: #eee; */
|
||||||
/* } */
|
/* } */
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
display: block;
|
||||||
|
border-left: 2px solid #808080;
|
||||||
|
padding-left: 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
.definition, .proposition, .theorem {
|
.definition, .proposition, .theorem {
|
||||||
display: block;
|
display: block;
|
||||||
border-left: 2px solid #808080;
|
border-left: 2px solid #808080;
|
||||||
|
|
|
@ -23,9 +23,7 @@ integer so that its absolute value is less or equal to ~≢Y~, splits
|
||||||
and the first vector contains the remaining elements.
|
and the first vector contains the remaining elements.
|
||||||
#+end_quote
|
#+end_quote
|
||||||
|
|
||||||
#+begin_src default
|
*Solution:* ~(0>⊣)⌽((⊂↑),(⊂↓))~
|
||||||
split←(0>⊣)⌽((⊂↑),(⊂↓))
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
There are three nested trains here. The first one, ~((⊂↑),(⊂↓))~, uses
|
There are three nested trains here. The first one, ~((⊂↑),(⊂↓))~, uses
|
||||||
the two functions [[https://help.dyalog.com/18.0/index.htm#Language/Primitive%20Functions/Take.htm][Take]] (~↑~) and [[https://help.dyalog.com/18.0/index.htm#Language/Primitive%20Functions/Drop.htm][Drop]] (~↓~) to build a nested array
|
the two functions [[https://help.dyalog.com/18.0/index.htm#Language/Primitive%20Functions/Take.htm][Take]] (~↑~) and [[https://help.dyalog.com/18.0/index.htm#Language/Primitive%20Functions/Drop.htm][Drop]] (~↓~) to build a nested array
|
||||||
|
@ -73,9 +71,7 @@ character, like the result of ~'UTF-8'∘⎕UCS¨'UTF-8'∘⎕UCS~ but does not
|
||||||
use any system functions (names beginning with ~⎕~)
|
use any system functions (names beginning with ~⎕~)
|
||||||
#+end_quote
|
#+end_quote
|
||||||
|
|
||||||
#+begin_src default
|
*Solution:* ~{(~⍵∊127+⍳64)⊂⍵}~
|
||||||
characters←{(~⍵∊127+⍳64)⊂⍵}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
First, we build a binary array from the string, encoding each
|
First, we build a binary array from the string, encoding each
|
||||||
continuation character as 0, and all the others as 1. Next, we can use
|
continuation character as 0, and all the others as 1. Next, we can use
|
||||||
|
@ -95,9 +91,7 @@ scalar or non-empty vector representing a valid character Excel column
|
||||||
identifier between A and XFD, returns the corresponding column number
|
identifier between A and XFD, returns the corresponding column number
|
||||||
#+end_quote
|
#+end_quote
|
||||||
|
|
||||||
#+begin_src default
|
*Solution:* ~26⊥⎕A∘⍳~
|
||||||
columns←26⊥⎕A∘⍳
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
We use the alphabet ~⎕A~ and [[https://help.dyalog.com/latest/#Language/Primitive%20Functions/Index%20Of.htm][Index Of]] (~⍳~) to compute the index in
|
We use the alphabet ~⎕A~ and [[https://help.dyalog.com/latest/#Language/Primitive%20Functions/Index%20Of.htm][Index Of]] (~⍳~) to compute the index in
|
||||||
the alphabet of every character. As a train, this can be done by
|
the alphabet of every character. As a train, this can be done by
|
||||||
|
@ -116,9 +110,7 @@ indicates that the corresponding year is a leap year (0 otherwise).
|
||||||
A leap year algorithm can be found [[https://en.wikipedia.org/wiki/Leap_year#Algorithm][here]].
|
A leap year algorithm can be found [[https://en.wikipedia.org/wiki/Leap_year#Algorithm][here]].
|
||||||
#+end_quote
|
#+end_quote
|
||||||
|
|
||||||
#+begin_src default
|
*Solution:* ~1 3∊⍨(0+.=400 100 4∘.|⊢)~
|
||||||
leap←1 3∊⍨(0+.=400 100 4∘.|⊢)
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
According to the algorithm, a year is a leap year in two situations:
|
According to the algorithm, a year is a leap year in two situations:
|
||||||
- if it is divisible by 4, but not 100 (and therefore not 400),
|
- if it is divisible by 4, but not 100 (and therefore not 400),
|
||||||
|
@ -139,9 +131,7 @@ vector of the integers from the first element of the right argument to
|
||||||
the second, inclusively.
|
the second, inclusively.
|
||||||
#+end_quote
|
#+end_quote
|
||||||
|
|
||||||
#+begin_src default
|
*Solution:* ~{(⊃⍵)+(-×-/⍵)×0,⍳|-/⍵}~
|
||||||
stepping←{(⊃⍵)+(-×-/⍵)×0,⍳|-/⍵}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
First, we have to compute the range of the output, which is the
|
First, we have to compute the range of the output, which is the
|
||||||
absolute value of the difference between the two integers ~|-/⍵~. From
|
absolute value of the difference between the two integers ~|-/⍵~. From
|
||||||
|
@ -161,9 +151,7 @@ right argument so any elements equal to the left argument come first
|
||||||
while all other elements keep their order.
|
while all other elements keep their order.
|
||||||
#+end_quote
|
#+end_quote
|
||||||
|
|
||||||
#+begin_src default
|
*Solution:* ~{⍵[⍋⍺≠⍵]}~
|
||||||
movefront←{⍵[⍋⍺≠⍵]}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
~⍺≠⍵~ will return a binary vector marking as 0 all elements equal to
|
~⍺≠⍵~ will return a binary vector marking as 0 all elements equal to
|
||||||
the left argument. Using this index to sort in the usual way with
|
the left argument. Using this index to sort in the usual way with
|
||||||
|
@ -187,9 +175,7 @@ that you want to query, returns 1 if all of the codes in the left
|
||||||
argument are found in the right argument (0 otherwise).
|
argument are found in the right argument (0 otherwise).
|
||||||
#+end_quote
|
#+end_quote
|
||||||
|
|
||||||
#+begin_src default
|
*Solution:* ~{f←⍸∘⌽(2∘⊥⍣¯1)⋄∧/(f⍺)∊f⍵}~
|
||||||
bits←{f←⍸∘⌽(2∘⊥⍣¯1)⋄∧/(f⍺)∊f⍵}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
The difficult part is to find the set of states for an integer. We
|
The difficult part is to find the set of states for an integer. We
|
||||||
need a function that will return ~1 8 128~ (or an equivalent
|
need a function that will return ~1 8 128~ (or an equivalent
|
||||||
|
@ -215,9 +201,7 @@ Write a function that takes a single integer greater than or equal to
|
||||||
integer is a zigzag number, 0 otherwise.
|
integer is a zigzag number, 0 otherwise.
|
||||||
#+end_quote
|
#+end_quote
|
||||||
|
|
||||||
#+begin_src default
|
*Solution:* ~∧/2=∘|2-/∘×2-/(10∘⊥⍣¯1)~
|
||||||
zigzag←∧/2=∘|2-/∘×2-/(10∘⊥⍣¯1)
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
|
@ -233,9 +217,7 @@ conform to the following pattern (0 otherwise):
|
||||||
- After the apex, any remaining values decrease or remain the same
|
- After the apex, any remaining values decrease or remain the same
|
||||||
#+end_quote
|
#+end_quote
|
||||||
|
|
||||||
#+begin_src default
|
*Solution:* ~{∧/(⍳∘≢≡⍋)¨(⊂((⊢⍳⌈/)↑⊢),⍵),⊂⌽((⊢⍳⌈/)↓⊢),⍵}~
|
||||||
risefall←{∧/(⍳∘≢≡⍋)¨(⊂((⊢⍳⌈/)↑⊢),⍵),⊂⌽((⊢⍳⌈/)↓⊢),⍵}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
|
@ -250,9 +232,7 @@ displays identically to what ~{⎕←⍵}¨~ displays when applied to the
|
||||||
right argument.
|
right argument.
|
||||||
#+end_quote
|
#+end_quote
|
||||||
|
|
||||||
#+begin_src default
|
*Solution:* ~{↑⊃,/↓¨⍕¨⍵}~
|
||||||
stacking←{↑⊃,/↓¨⍕¨⍵}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue