DEV Community

o2sh
o2sh

Posted on

1 1

New sorting algorithm: mkdir sort

A little sorting algorithm I made just for fun.

#!/bin/bash
function f() {
    echo $(eval printf 'g/%.0s' {1.."$1"})"$1" | xargs mkdir -p
}

while [ -n "$1" ]
do
    f "$1"
    shift
done

find . -type d | sed 's#.*/##' | grep -v g

#./mkdirsort.sh 9 2 7 4 6
Enter fullscreen mode Exit fullscreen mode

It's like a "b-tree sort" using the FS

GitHub logo o2sh / mkdir-sort

sorting algorithm using mkdir

mkdir-sort

sorting algorithm using mkdir

Example

$ mkdir wkdir
$ cd wkdir
$ ./mkdirsort.sh 9 2 7 4 6
$ rm -rf g/
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay