remembered to update
This commit is contained in:
parent
2b9b002e1c
commit
aac01b3ce3
12 changed files with 310 additions and 0 deletions
42
201/week2/dfs.hoon
Normal file
42
201/week2/dfs.hoon
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
:: Hoon 201 - Week 2
|
||||
:: ~bannum-magtus || s@p7.co.nz
|
||||
::
|
||||
:: i could not figure out how to
|
||||
:: cast the output of a wet gate
|
||||
:: to a list of the same type :(
|
||||
::
|
||||
:- %say
|
||||
|= [* [t=(tree @) x=@ ~] *]
|
||||
:- %noun
|
||||
^- [? (list @)]
|
||||
=<
|
||||
:- (dfs-search t x) (dfs t)
|
||||
|%
|
||||
++ dfs
|
||||
|= t=(tree @)
|
||||
^- (list @)
|
||||
?~ t
|
||||
~
|
||||
%+ weld
|
||||
(dfs l.t)
|
||||
%+ weld
|
||||
(dfs r.t)
|
||||
[n.t ~]
|
||||
++ dfs-search
|
||||
|= [t=(tree @) x=@]
|
||||
^- ?
|
||||
?~ t
|
||||
%.n
|
||||
?| (dfs-search l.t x)
|
||||
(dfs-search r.t x)
|
||||
=(n.t x)
|
||||
==
|
||||
:: i assume ?| will stop as
|
||||
:: soon as it sees a true,
|
||||
:: otherwise below is better
|
||||
::
|
||||
::?: (dfs-search l.t x) %.y
|
||||
::?: (dfs-search r.t x) %.y
|
||||
::=(x n.t)
|
||||
--
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue