Skip to content

timastras9/java-sorting-darpa-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DARPA Drone Battery Sort — Selection Sort + Insertion Sort with AI Tactical Layer

A Java program that illustrates the execution of Selection Sort and Insertion Sort step-by-step on a real-world scenario: a DARPA drone swarm returning from a mission needs to be recalled in order of lowest battery first to prevent crashes. After the sorts complete, xAI's Grok analyzes the sorted result and produces a concise tactical recall plan — adding the operational layer (action window + risk level per drone) that pure sorting cannot provide.

Originally a CSC263 (Data Structures) class assignment, expanded into a portfolio piece.


What it shows

  • Two classic sorting algorithms, each printed step-by-step:
    • Selection Sort — find the minimum in the unsorted suffix, swap into the boundary, repeat
    • Insertion Sort — take the next element, shift larger elements right, insert into the sorted prefix
  • Two views per algorithm:
    • Full step-by-step trace (every comparison, every swap or shift)
    • High-level pass-by-pass summary (textbook table style)
  • ASCII bar chart of every drone's battery, color-coded by sorted/unsorted region
  • Running counters for comparisons, swaps, and shifts
  • Correctness verification — confirms both algorithms produce the same final order
  • Agentic AI layer — Grok reads the sorted result and returns a structured tactical plan in a strict line format (CRITICAL_COUNT, PLAN, SUMMARY); the program parses and renders it as a compact # / callsign / battery / action / risk table

Quick start

macOS / Linux

git clone https://github.com/timastras9/java-sorting-darpa-demo.git
cd java-sorting-darpa-demo
cp .env.example .env        # paste your xAI key inside
./run.sh

Windows

git clone https://github.com/timastras9/java-sorting-darpa-demo.git
cd java-sorting-darpa-demo
copy .env.example .env
notepad .env                :: paste your xAI key, save
run.bat

Manual

javac SortIllustration/*.java
java -cp . SortIllustration.DroneBatterySort

A pre-captured run of the program is included in SortIllustration/run-output.txt so you can see exactly what the program produces without running it yourself.

Without a Grok key the program runs end-to-end normally; the tactical layer prints (Grok offline) and is skipped.


Requirements

  • Java 11 or newer (developed and tested on Java 25; only uses the JDK standard library — no Maven, no Gradle, no external dependencies).
  • An xAI API key (optional, for the Grok tactical layer). Get one at https://console.x.ai/

Architecture

SortIllustration/
├── DroneBatterySort.java   # Selection Sort + Insertion Sort + tactical layer + main
├── GrokClient.java         # tiny xAI Grok REST wrapper (no SDK, java.net.http only)
└── run-output.txt          # pre-captured plain-text dump of a full run

Two source files, no build system. About 500 lines of commented Java that read top to bottom.

Algorithms

Method Strategy Best Avg Worst
selectionSort Find min in unsorted suffix, swap to boundary O(n²) O(n²) O(n²)
insertionSort Shift larger elements right, drop key into the gap O(n) O(n²) O(n²)
selectionSortHighLevel Same algorithm, prints one line per pass (textbook view)
insertionSortHighLevel Same algorithm, prints one line per pass (textbook view)

Agentic decision flow

  1. Insertion Sort produces the sorted array + matching callsigns.
  2. Both arrays are sent to Grok with a strict response schema:
    CRITICAL_COUNT: <number>
    PLAN:
    - <callsign> | <action> | <CRITICAL|HIGH|MEDIUM|LOW>
    ...
    SUMMARY: <one short sentence>
    
  3. The program parses each line, validates risk levels, and renders a compact color-coded table — the kind of output a mission commander would actually act on.

Tech stack

  • Java 11+ (JDK standard library only)
  • xAI Grok API (grok-4.3) via java.net.http.HttpClient
  • ANSI escape codes for color
  • .env file loader built from scratch (no dotenv library needed)

License

MIT — do whatever you want with it.


Author

Timothy Astras · github.com/timastras9


AI assistance disclosure

All original ideas for this program — the topic, the side-by-side illustration of Selection Sort and Insertion Sort, the ASCII bar chart rendering, the agentic tactical AI layer — are my own. Claude Code (Anthropic) was used as a coding assistant to help implement those ideas in Java. I directed every step, reviewed every line, ran the program, and verified the output.

About

Selection Sort + Insertion Sort step-by-step illustration with AI-driven tactical recall plan. Java + xAI Grok. CSC263 / portfolio.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors