updated to week 6 minus week 5 oops

This commit is contained in:
Thorn Avery 2019-10-31 22:03:29 +13:00
parent f116fd9bab
commit 5e8d2432b3
3 changed files with 92 additions and 0 deletions

24
201/week6/lib/dfs.hoon Normal file
View 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)
==
--

View 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)
==
--

View File

@ -35,3 +35,27 @@ deal two poker hands and rank them
## Week 2 ## Week 2
Depth first search a tree 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