From c189ec6010c52081b94704dec649fb31a687271d Mon Sep 17 00:00:00 2001 From: m-hgn Date: Sun, 30 Apr 2023 23:24:20 +0200 Subject: [PATCH] add snail sort in odin. --- snail.odin | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 snail.odin diff --git a/snail.odin b/snail.odin new file mode 100644 index 0000000..ee58dfb --- /dev/null +++ b/snail.odin @@ -0,0 +1,51 @@ +package main +import "core:fmt" + +snail :: proc(xss: [][]int) -> [dynamic]int { + yss := [dynamic]int{} + + h := len(xss) + if h == 0 { return yss } + w := len(xss[0]) + if w == 0 { return yss } + + for b in 0..=max(h, w) { + ex := w - b - 1 + ey := h - b - 1 + + for c in b..=ex { append(&yss, xss[b][c]) } + for r in (b + 1)..=ey { append(&yss, xss[r][ex]) } + + if ex == b || ey == b { return yss } + + for c_off in b.. bool { + if len(a) != len(b) { return false } + for i in 0..