diff options
| author | Cody <cody@codyq.dev> | 2023-03-27 04:47:00 -0500 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2023-03-27 04:47:00 -0500 |
| commit | bb95375f8b24141bf7dfe5a8b1bba5c995f61253 (patch) | |
| tree | 10eb423cf881afaba7d854f8150a8f5d55d6d1db /examples/features.sloth | |
| parent | ff2d00dec2317df8de0afaf56beb35e2edb70cd7 (diff) | |
| download | sloth-bb95375f8b24141bf7dfe5a8b1bba5c995f61253.tar.gz | |
hm
Diffstat (limited to 'examples/features.sloth')
| -rw-r--r-- | examples/features.sloth | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/features.sloth b/examples/features.sloth new file mode 100644 index 0000000..26be73c --- /dev/null +++ b/examples/features.sloth @@ -0,0 +1,42 @@ +fn calories(input) { + var elves = [] + var current = 0 + + for line in input.lines() { + if line.empty() { + elves.append(current) + current = 0 + continue + } + + current += line as!! int + } + + elves.sort() + elves.reverse() + + return elves[0..3].sum() +} + +fn fib(x: int) { + if x < 2 { + return x + } + + return fib(x - 1) + fib (x - 2) +} + +fn codes(input: String): List<String> { + val chars = input.chars() + .windowed(4) + .map(it -> it as Set) + .filter(-> $0.len() == 4) + .map(it -> it.join()) + return chars +} + +## Will convert celsius to fahrenheit +fn fahrenheit(celsius) { + return 32.0 + celsius * 1.8 +} + |
