From 2b9b002e1c74e506a939e0ed48d52893ac718edf Mon Sep 17 00:00:00 2001 From: techieAgnostic Date: Mon, 19 Aug 2019 21:56:34 +1200 Subject: [PATCH] done --- README.md | 16 +++++++++++++++ week6/cards.hoon | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 week6/cards.hoon diff --git a/README.md b/README.md index cc83841..b6b9ec8 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,19 @@ My assignments for each week of Hoon 101. ## Week 2 > Build a naked generator that takes a noun and checks if that noun is a cell or an atom. If that input noun is an atom, check if it’s even or odd. The output should be of the tape type. + +## Week 3 + +> Build a naked generator that returns the third item of a list, without using standard library functions (in the core logic, could use (list) as the input) + +## Week 4 + +> Find the sum of all numbers that are a multiple of 3 or 5, [1..n] + +## Week 5 + +> morse code converter + +## Week 6 + +> Produce x hands of y cards from a deck of 52 distinct cards diff --git a/week6/cards.hoon b/week6/cards.hoon new file mode 100644 index 0000000..4e278b7 --- /dev/null +++ b/week6/cards.hoon @@ -0,0 +1,61 @@ +:: Hoon 101 - Week 6 +:: ~bannum-magtus || s@p7.co.nz +:: +:- %say +|= [[* eny=@uvJ *] [x=@ y=@ ~] ~] +:- %noun +?: (gth (mul x y) 52) + !! +=< +:: Im so sorry +(take-hands x y new-deck) +|% +++ take-hands + |= [x=@ y=@ d=(list tape)] + ^- (list (list tape)) + =/ hands=(list (list tape)) ~ + |- + ?: =(x 0) + hands + %= $ + hands :-((scag y d) hands) + d (slag y d) + x (dec x) + == +++ suit-store + ^- (list tape) + ["H" "D" "C" "S" ~] +++ suit-donnees + ^- (list tape) + ["A" "2" "3" "4" "5" "6" "7" "8" "9" "10" "J" "Q" "K" ~] +++ new-deck + =/ nd=(list tape) ~ + =/ s 0 + |- + ?: (gte s 4) + (shuffle-deck nd eny) + =/ v 0 + |- + ?. (lth v 13) + ^$(s +(s)) + %= $ + v +(v) + nd :-((weld (snag v suit-donnees) (snag s suit-store)) nd) + == +++ shuffle-deck + |= [unshuffled=(list tape) entropy=@] + ^- (list tape) + =| shuffled=(list tape) + =/ random ~(. og entropy) + =/ remaining (lent unshuffled) + |- + ?: =(remaining 1) + :_ shuffled + (snag 0 unshuffled) + =^ index random (rads:random remaining) + %= $ + shuffled (snag index unshuffled)^shuffled + remaining (dec remaining) + unshuffled (oust [index 1] unshuffled) + == +--