updated to week 6 minus week 5 oops
This commit is contained in:
parent
f116fd9bab
commit
5e8d2432b3
24
201/week6/lib/dfs.hoon
Normal file
24
201/week6/lib/dfs.hoon
Normal file
@ -0,0 +1,24 @@
|
||||
:: depth first library
|
||||
::
|
||||
|%
|
||||
++ traverse
|
||||
|= t=(tree @)
|
||||
^- (list @)
|
||||
?~ t
|
||||
~
|
||||
%+ weld
|
||||
(traverse l.t)
|
||||
%+ weld
|
||||
(traverse r.t)
|
||||
[n.t ~]
|
||||
++ search
|
||||
|= [t=(tree @) x=@]
|
||||
^- ?
|
||||
?~ t
|
||||
%.n
|
||||
?| (search l.t x)
|
||||
(search r.t x)
|
||||
=(n.t x)
|
||||
==
|
||||
--
|
||||
|
44
201/week6/tests/lib/dfs.hoon
Normal file
44
201/week6/tests/lib/dfs.hoon
Normal file
@ -0,0 +1,44 @@
|
||||
:: Hoon 201 - Week 6
|
||||
:: ~bannum-magtus | s@p7.co.nz
|
||||
::
|
||||
/+ *test, dfs
|
||||
::
|
||||
|%
|
||||
++ test-dfs-search ^- tang
|
||||
=/ null-tree=(tree @) *(tree @)
|
||||
=/ fill-tree=(tree @) [12 [8 [4 ~ ~] ~] [14 ~ [16 ~ ~]]]
|
||||
;: weld
|
||||
:: cant find something in an empty tree
|
||||
%+ expect-eq
|
||||
!> %.n
|
||||
!> (search:dfs null-tree 42)
|
||||
:: cant find something thats not in a tree
|
||||
%+ expect-eq
|
||||
!> %.n
|
||||
!> (search:dfs fill-tree 42)
|
||||
:: can find something that is in a tree
|
||||
%+ expect-eq
|
||||
!> %.y
|
||||
!> (search:dfs fill-tree 12)
|
||||
==
|
||||
++ test-dfs-traverse ^- tang
|
||||
=/ null-tree=(tree @) *(tree @)
|
||||
=/ a-tree=(tree @) [12 [8 [4 ~ ~] ~] [14 ~ [16 ~ ~]]]
|
||||
=/ b-tree=(tree @) [8 [4 [12 ~ ~] ~] [16 ~ [14 ~ ~]]]
|
||||
=/ a-list=(list @) [4 8 16 14 12 ~]
|
||||
=/ b-list=(list @) [12 4 14 16 8 ~]
|
||||
;: weld
|
||||
:: null tree has empty traversal
|
||||
%+ expect-eq
|
||||
!> ~
|
||||
!> (traverse:dfs null-tree)
|
||||
:: tree a has traversal a
|
||||
%+ expect-eq
|
||||
!> a-list
|
||||
!> (traverse:dfs a-tree)
|
||||
:: tree b has traversal b
|
||||
%+ expect-eq
|
||||
!> b-list
|
||||
!> (traverse:dfs b-tree)
|
||||
==
|
||||
--
|
24
README.md
24
README.md
@ -35,3 +35,27 @@ deal two poker hands and rank them
|
||||
## Week 2
|
||||
|
||||
Depth first search a tree
|
||||
|
||||
## Week 3
|
||||
|
||||
Write +turn without stdlib
|
||||
|
||||
## Week 4
|
||||
|
||||
Rewrite Egg-Timer (Gall App) to take an absolute date
|
||||
|
||||
## Week 5
|
||||
|
||||
Write a Gall App that queries an api
|
||||
|
||||
## Week 6
|
||||
|
||||
Write a test suite for a library
|
||||
|
||||
## Week 7
|
||||
|
||||
Write a Modulo Tile for a simple Todo List
|
||||
|
||||
## Week 8
|
||||
|
||||
Create something hopefully impressive
|
||||
|
Loading…
Reference in New Issue
Block a user