init
test / test (push) Has been cancelled

This commit is contained in:
2026-07-18 02:54:42 +02:00
commit 4a908f4f3e
8 changed files with 193 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
import luma/definition
import gleam/list
import gleam/io
import argv
import luma/parser
import simplifile
type Information {
Information(lowesthirachy: Int,
highesthirachy: Int)
}
fn gather(instructions: List(definition.Instruction))-> Information {
let pushes =
instructions
|> list.filter_map(fn(instruction) {
case instruction {
definition.Push(pusher) -> case pusher {
definition.Hirachy(push) -> Ok(push)
_ -> Error(Nil)
}
_ -> Error(Nil)
}
})
echo pushes
let min_max =
case pushes {
[] -> Error(Nil)
[first, ..rest] ->
Ok(
list.fold(rest, #(first, first), fn(acc, n) {
let #(min, max) = acc
#(
case n < min {
True -> n
False -> min
},
case n > max {
True -> n
False -> max
},
)
})
)
}
case min_max {
Ok(#(min, max)) -> {
Information(min, max)
}
Error(_) -> {
Information(0, 0)
}
}
}
pub fn main() -> Nil {
case argv.load().arguments {
[filename] -> {
case simplifile.read(filename) {
Ok(contents) -> {
//programm goes here
let instructins = parser.handler(contents)
let result = case instructins {
definition.TextInstructions(instruction) -> gather(instruction)
_ -> Information(-124, 41234)
}
echo result
Nil
}
Error(_) -> io.println("Couldn't read file")
}
}
_ -> io.println("Usage: gleam run <file>")
}
}