Skip to content

Commit

Permalink
Use mapcat FTW!
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Sep 20, 2024
1 parent 079062b commit f731bf2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
11 changes: 2 additions & 9 deletions exercises/practice/raindrops/.meta/raindrops.ys
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,5 @@
dict =:: { 3: Pling, 5: Plang, 7: Plong }

defn convert(number):
words =:
reduce _ [] [3 5 7]:
fn(acc num):
concat acc:
when (number % num).!: -[dict.$num]

if words.?:
str: words*
str: number
words =: mapcat(\((number % _).! &&& dict.get(_)) [3 5 7])
if words.?: str(words*) str(number)
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
!yamlscript/v0

defn sum(factors limit):
std/sum:
reduce _ [] factors:
fn(nums num):
when(num.? range(num limit num)):
.concat(nums).distinct()
factors.mapcat(\(when(_.? range(_ limit _))) _).distinct().std/sum()

0 comments on commit f731bf2

Please sign in to comment.