-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Kjarrigan/add-first-real-code-sample
Add the first real working script
- Loading branch information
Showing
2 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
[![](http://github-actions.40ants.com/Flipez/rocket-lang/matrix.svg)](https://github.com/Flipez/rocket-lang) | ||
[![Test](https://github.com/Flipez/rocket-lang/actions/workflows/go-test.yml/badge.svg)](https://github.com/Flipez/rocket-lang/actions/workflows/go-test.yml) | ||
[![Test](https://github.com/Flipez/rocket-lang/actions/workflows/go-test.yml/badge.svg)](https://github.com/Flipez/rocket-lang/actions/workflows/go-test.yml) | ||
|
||
# General | ||
|
||
RocketLang as of version 0.9.5 is the _full_ (as in the book was worked through) version of [MonkeyLang](https://monkeylang.org/) | ||
|
||
## How To? | ||
|
||
* Download & Install a Version from the Release-Page | ||
* `rocket-lang` without any arguments will start an interactive shell | ||
* `rocket-lang FILE` will run the code in that file (no file extension check yet) | ||
* Use _Javascript_ Highlighting in your editor for some convenience | ||
* Checkout Code [Samples](examples/) for what is currently possible (and what not) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"// A solution for part 1 of https://adventofcode.com/2015/day/1" | ||
"// Last Updated: 2021.09.28" | ||
"// RocketLang Version: 0.9.6-rc1" | ||
"------------------------------------" | ||
|
||
let part_one = fn(input) { | ||
let floor = 0 | ||
let idx = len(input) | ||
|
||
"// There are no loops at the moment so use recursion instead" | ||
calc(input, idx, floor) | ||
} | ||
|
||
let calc = fn(input,idx,floor) { | ||
let char_to_value = { | ||
"(": 1, | ||
")": -1 | ||
} | ||
|
||
if (idx == 0) { | ||
return floor | ||
} | ||
|
||
let new_idx = idx - 1 | ||
let delta = char_to_value[input[new_idx]] | ||
|
||
calc(input, new_idx, floor + delta) | ||
} | ||
|
||
"// Test some inputs to check that our code is correct..." | ||
if (part_one(["(", "(", ")", ")"]) != 0) { | ||
puts("Assertion ((( => 0 failed") | ||
} | ||
|
||
"// ... for multiple known results." | ||
if (part_one([")","(",")",")","(",")",")"]) != -3) { | ||
puts("Assertion )())()) => -3 failed") | ||
} | ||
|
||
"// There aren't any usefull string operations in RocketLang yet so you have to prepare" | ||
"// the input code a bit - in this case as an array of strings, like this:" | ||
let real_input = [ | ||
"(",")","(",")","(","(",")","(",")","(",")","(","(",")","(",")","(","(","(",")","(","(","(",")",")", | ||
")","(","(","(",")","(","(","(","(","(",")","(",")","(","(","(","(","(",")",")",")","(",")","(","(", | ||
"(","(","(",")",")","(","(","(","(","(","(","(","(",")","(","(","(","(","(","(","(","(","(","(",")", | ||
"(","(","(","(",")",")","(","(",")","(",")","(","(",")","(","(","(",")","(",")","(","(",")","(","(", | ||
")",")","(","(",")","(","(","(","(","(",")","(","(","(",")","(",")","(",")","(","(","(","(","(",")", | ||
")","(","(","(","(","(","(","(",")","(","(",")","(","(","(","(",")","(",")",")","(","(",")","(","(", | ||
"(","(","(",")",")",")","(",")",")","(","(",")",")","(","(",")","(","(",")","(",")",")",")",")",")", | ||
")",")",")",")","(","(","(","(","(","(","(","(","(","(","(","(","(",")","(",")",")","(",")","(",")", | ||
")","(",")",")","(","(",")",")",")",")","(","(","(","(",")","(",")","(",")","(","(","(","(","(",")", | ||
"(","(","(","(",")","(","(",")","(","(",")","(",")","(","(",")","(","(",")","(",")","(","(",")","(", | ||
"(","(","(","(","(","(","(",")",")","(","(",")",")","(","(",")",")","(",")",")",")",")","(","(","(", | ||
")","(",")",")","(",")","(","(","(","(","(",")","(",")","(","(","(",")",")",")","(","(","(","(",")", | ||
"(",")","(",")","(",")",")",")",")","(","(",")",")",")",")","(","(","(","(","(",")",")","(","(","(", | ||
"(",")","(",")",")","(","(",")",")","(","(",")",")",")","(","(",")","(","(","(","(","(",")","(",")", | ||
")",")",")","(",")",")","(","(","(",")","(","(",")",")","(","(","(","(",")","(","(","(","(","(",")", | ||
"(","(","(",")","(","(",")",")","(",")",")",")",")","(","(","(",")",")",")","(",")","(",")","(","(", | ||
")","(","(",")",")",")",")",")","(","(","(","(","(","(","(","(","(",")","(",")",")","(","(","(","(", | ||
"(",")","(",")","(","(","(","(","(",")","(","(",")","(",")",")","(","(","(","(","(","(",")","(","(", | ||
")","(",")",")","(",")",")",")","(",")",")","(","(","(","(",")",")",")","(",")","(","(",")","(","(", | ||
")","(","(",")","(","(","(","(","(",")","(","(",")",")","(","(",")",")",")","(","(","(","(","(","(", | ||
")","(",")","(","(",")","(",")","(",")","(","(",")","(","(","(","(",")",")","(",")",")","(","(","(" | ||
] | ||
|
||
puts("Solution Day 1 Part 1: ") | ||
puts(part_one(real_input)) |