Skip to content

Instantly share code, notes, and snippets.

@jellea
Last active December 1, 2019 12:09
Show Gist options
  • Select an option

  • Save jellea/4d62380f587fbc2c3de4ce23fc0f2909 to your computer and use it in GitHub Desktop.

Select an option

Save jellea/4d62380f587fbc2c3de4ce23fc0f2909 to your computer and use it in GitHub Desktop.

Revisions

  1. jellea revised this gist Dec 1, 2019. No changes.
  2. jellea revised this gist Dec 1, 2019. No changes.
  3. jellea revised this gist Dec 1, 2019. No changes.
  4. jellea revised this gist Dec 1, 2019. No changes.
  5. jellea revised this gist Dec 1, 2019. No changes.
  6. jellea created this gist Dec 1, 2019.
    17 changes: 17 additions & 0 deletions advent2019-1.fnl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    (fn mass->fuel [mass]
    (-> (tonumber mass) (/ 3) (math.floor) (- 2)))

    (let [file (io.open "1.data" "r")
    file-contents (file:read "*a")
    mods (string.gmatch file-contents "%d+")]
    (var total-fuel 0)
    (each [mass mods]
    (let [fuel (mass->fuel mass)]
    (set total-fuel (+ total-fuel fuel))
    (var rest-fuel fuel)
    (while (> rest-fuel 0)
    (do
    (set rest-fuel (mass->fuel rest-fuel))
    (if (> rest-fuel 0)
    (set total-fuel (+ total-fuel rest-fuel)))))))
    (print total-fuel))