commit d48f454dcebb744a076ba91355247f5c3f7ecf19 Author: Awen Lelu Date: Tue Jan 6 12:32:35 2026 +0100 init diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ec2509 --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +chatgpt-*.tar + +# Temporary files, for example, from tests. +/tmp/ diff --git a/chatgpt.exs b/chatgpt.exs new file mode 100644 index 0000000..0ea9ff0 --- /dev/null +++ b/chatgpt.exs @@ -0,0 +1,88 @@ +# Installer Jason pour JSON si besoin +Mix.install([ + {:jason, "~> 1.4"} +]) + +defmodule ZombieApocalypse do + @state_file "states.json" + @final_file "states_final.json" + + # Démarrage de la simulation + def start(humans \\ 10, zombies \\ 3, max_hours \\ 200) do + # Vider le fichier temporaire + File.write!(@state_file, "") + + IO.puts("🧟 Lancement de la simulation Zombie Apocalypse !") + + # Ouvrir le fichier en continu pour append rapide + {:ok, file} = File.open(@state_file, [:write, :utf8]) + + # Boucle principale + loop(0, humans, zombies, max_hours, file) + + # Fermer le fichier + File.close(file) + + # Générer JSON final + finalize_json() + end + + # Boucle principale + defp loop(hour, humans, zombies, max_hours, file) when hour < max_hours do + state = %{ + hour: hour, + humans: humans, + zombies: zombies, + timestamp: DateTime.utc_now() + } + + # Append rapide + IO.write(file, Jason.encode!(state) <> "\n") + + # Afficher seulement toutes les 10 heures + if rem(hour, 10) == 0 do + IO.puts("Heure #{hour} | Humains: #{humans} | Zombies: #{zombies}") + end + + cond do + humans <= 0 -> + IO.puts("💀 Tous les humains ont été infectés.") + + zombies <= 0 -> + IO.puts("🎉 Tous les zombies ont été éliminés.") + + true -> + {new_humans, new_zombies} = simulate_hour(humans, zombies) + loop(hour + 1, new_humans, new_zombies, max_hours, file) + end + end + + defp loop(_hour, _humans, _zombies, _max_hours, _file), do: :ok + + # Simulation d'une heure (calcul probabiliste) + defp simulate_hour(humans, zombies) do + attacks = zombies + # Humains infectés : chaque attaque a 40% de chance + humans_lost = Enum.count(1..attacks, fn _ -> :rand.uniform(100) <= 40 end) + # Zombies tués : chaque attaque a 15% de chance + zombies_lost = Enum.count(1..attacks, fn _ -> :rand.uniform(100) <= 15 end) + + humans = max(humans - humans_lost, 0) + zombies = max(zombies - zombies_lost + humans_lost, 0) # infections + {humans, zombies} + end + + # Générer le JSON final complet + defp finalize_json do + states = + File.stream!(@state_file) + |> Stream.map(&Jason.decode!/1) + |> Enum.to_list() + + File.write!(@final_file, Jason.encode!(states, pretty: true)) + IO.puts("✅ JSON final créé : #{@final_file}") + end +end + +# Lancer la simulation +ZombieApocalypse.start(7000000000, 3, 200) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5fd6f52 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1767379071, + "narHash": "sha256-EgE0pxsrW9jp9YFMkHL9JMXxcqi/OoumPJYwf+Okucw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "fb7944c166a3b630f177938e478f0378e64ce108", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..350b28e --- /dev/null +++ b/flake.nix @@ -0,0 +1,37 @@ +{ + description = "Environnement de développement Elixir pour la simulation d'apocalypse zombie"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + devShells.default = pkgs.mkShell { + name = "elixir-zombie-dev"; + + packages = with pkgs; [ + elixir + erlang + elixir-ls + ]; + + shellHook = '' + echo "🧟 Environnement Elixir prêt" + echo "➡️ Lance : iex zombie_apocalypse.ex" + ''; + }; + } + ); +} diff --git a/states.json b/states.json new file mode 100644 index 0000000..d86e508 --- /dev/null +++ b/states.json @@ -0,0 +1,82 @@ +{"timestamp":"2026-01-06T11:29:46.889794Z","hour":0,"humans":7000000000,"zombies":3} +{"timestamp":"2026-01-06T11:29:46.901248Z","hour":1,"humans":7000000000,"zombies":3} +{"timestamp":"2026-01-06T11:29:46.901292Z","hour":2,"humans":7000000000,"zombies":2} +{"timestamp":"2026-01-06T11:29:46.901310Z","hour":3,"humans":6999999998,"zombies":4} +{"timestamp":"2026-01-06T11:29:46.901324Z","hour":4,"humans":6999999997,"zombies":5} +{"timestamp":"2026-01-06T11:29:46.901343Z","hour":5,"humans":6999999995,"zombies":7} +{"timestamp":"2026-01-06T11:29:46.901356Z","hour":6,"humans":6999999992,"zombies":9} +{"timestamp":"2026-01-06T11:29:46.901376Z","hour":7,"humans":6999999987,"zombies":13} +{"timestamp":"2026-01-06T11:29:46.901403Z","hour":8,"humans":6999999984,"zombies":15} +{"timestamp":"2026-01-06T11:29:46.901420Z","hour":9,"humans":6999999981,"zombies":16} +{"timestamp":"2026-01-06T11:29:46.901434Z","hour":10,"humans":6999999969,"zombies":24} +{"timestamp":"2026-01-06T11:29:46.901477Z","hour":11,"humans":6999999961,"zombies":31} +{"timestamp":"2026-01-06T11:29:46.901499Z","hour":12,"humans":6999999950,"zombies":36} +{"timestamp":"2026-01-06T11:29:46.901515Z","hour":13,"humans":6999999939,"zombies":43} +{"timestamp":"2026-01-06T11:29:46.901536Z","hour":14,"humans":6999999915,"zombies":61} +{"timestamp":"2026-01-06T11:29:46.901570Z","hour":15,"humans":6999999889,"zombies":80} +{"timestamp":"2026-01-06T11:29:46.901595Z","hour":16,"humans":6999999859,"zombies":95} +{"timestamp":"2026-01-06T11:29:46.901627Z","hour":17,"humans":6999999823,"zombies":112} +{"timestamp":"2026-01-06T11:29:46.901664Z","hour":18,"humans":6999999779,"zombies":138} +{"timestamp":"2026-01-06T11:29:46.901705Z","hour":19,"humans":6999999727,"zombies":168} +{"timestamp":"2026-01-06T11:29:46.901754Z","hour":20,"humans":6999999658,"zombies":212} +{"timestamp":"2026-01-06T11:29:46.901825Z","hour":21,"humans":6999999571,"zombies":260} +{"timestamp":"2026-01-06T11:29:46.901867Z","hour":22,"humans":6999999467,"zombies":327} +{"timestamp":"2026-01-06T11:29:46.901910Z","hour":23,"humans":6999999352,"zombies":391} +{"timestamp":"2026-01-06T11:29:46.901961Z","hour":24,"humans":6999999192,"zombies":497} +{"timestamp":"2026-01-06T11:29:46.902029Z","hour":25,"humans":6999998996,"zombies":619} +{"timestamp":"2026-01-06T11:29:46.902104Z","hour":26,"humans":6999998751,"zombies":777} +{"timestamp":"2026-01-06T11:29:46.902193Z","hour":27,"humans":6999998435,"zombies":973} +{"timestamp":"2026-01-06T11:29:46.902304Z","hour":28,"humans":6999998031,"zombies":1227} +{"timestamp":"2026-01-06T11:29:46.902441Z","hour":29,"humans":6999997529,"zombies":1553} +{"timestamp":"2026-01-06T11:29:46.902610Z","hour":30,"humans":6999996944,"zombies":1902} +{"timestamp":"2026-01-06T11:29:46.902834Z","hour":31,"humans":6999996184,"zombies":2376} +{"timestamp":"2026-01-06T11:29:46.903219Z","hour":32,"humans":6999995235,"zombies":3003} +{"timestamp":"2026-01-06T11:29:46.903663Z","hour":33,"humans":6999994085,"zombies":3718} +{"timestamp":"2026-01-06T11:29:46.904074Z","hour":34,"humans":6999992596,"zombies":4620} +{"timestamp":"2026-01-06T11:29:46.904587Z","hour":35,"humans":6999990784,"zombies":5719} +{"timestamp":"2026-01-06T11:29:46.905224Z","hour":36,"humans":6999988428,"zombies":7241} +{"timestamp":"2026-01-06T11:29:46.906018Z","hour":37,"humans":6999985488,"zombies":9119} +{"timestamp":"2026-01-06T11:29:46.906996Z","hour":38,"humans":6999981796,"zombies":11446} +{"timestamp":"2026-01-06T11:29:46.908244Z","hour":39,"humans":6999977121,"zombies":14319} +{"timestamp":"2026-01-06T11:29:46.910018Z","hour":40,"humans":6999971342,"zombies":17920} +{"timestamp":"2026-01-06T11:29:46.912171Z","hour":41,"humans":6999964088,"zombies":22450} +{"timestamp":"2026-01-06T11:29:46.914781Z","hour":42,"humans":6999955200,"zombies":27995} +{"timestamp":"2026-01-06T11:29:46.917810Z","hour":43,"humans":6999944041,"zombies":35046} +{"timestamp":"2026-01-06T11:29:46.921504Z","hour":44,"humans":6999930025,"zombies":43836} +{"timestamp":"2026-01-06T11:29:46.926716Z","hour":45,"humans":6999912528,"zombies":54693} +{"timestamp":"2026-01-06T11:29:46.932908Z","hour":46,"humans":6999890756,"zombies":68219} +{"timestamp":"2026-01-06T11:29:46.940147Z","hour":47,"humans":6999863569,"zombies":85278} +{"timestamp":"2026-01-06T11:29:46.949767Z","hour":48,"humans":6999829576,"zombies":106415} +{"timestamp":"2026-01-06T11:29:46.961107Z","hour":49,"humans":6999787106,"zombies":133008} +{"timestamp":"2026-01-06T11:29:46.975045Z","hour":50,"humans":6999733922,"zombies":166182} +{"timestamp":"2026-01-06T11:29:46.994705Z","hour":51,"humans":6999667271,"zombies":207833} +{"timestamp":"2026-01-06T11:29:47.017118Z","hour":52,"humans":6999583990,"zombies":259742} +{"timestamp":"2026-01-06T11:29:47.044484Z","hour":53,"humans":6999480643,"zombies":324071} +{"timestamp":"2026-01-06T11:29:47.078126Z","hour":54,"humans":6999351277,"zombies":404594} +{"timestamp":"2026-01-06T11:29:47.121004Z","hour":55,"humans":6999188952,"zombies":506411} +{"timestamp":"2026-01-06T11:29:47.173710Z","hour":56,"humans":6998986235,"zombies":633223} +{"timestamp":"2026-01-06T11:29:47.240462Z","hour":57,"humans":6998733592,"zombies":789969} +{"timestamp":"2026-01-06T11:29:47.325410Z","hour":58,"humans":6998418010,"zombies":986673} +{"timestamp":"2026-01-06T11:29:47.430391Z","hour":59,"humans":6998024162,"zombies":1232640} +{"timestamp":"2026-01-06T11:29:47.567925Z","hour":60,"humans":6997531014,"zombies":1541167} +{"timestamp":"2026-01-06T11:29:47.739372Z","hour":61,"humans":6996915048,"zombies":1925949} +{"timestamp":"2026-01-06T11:29:47.949584Z","hour":62,"humans":6996144532,"zombies":2407419} +{"timestamp":"2026-01-06T11:29:48.216272Z","hour":63,"humans":6995182394,"zombies":3007606} +{"timestamp":"2026-01-06T11:29:48.548760Z","hour":64,"humans":6993978917,"zombies":3760074} +{"timestamp":"2026-01-06T11:29:48.982127Z","hour":65,"humans":6992474175,"zombies":4700526} +{"timestamp":"2026-01-06T11:29:49.549035Z","hour":66,"humans":6990594503,"zombies":5874136} +{"timestamp":"2026-01-06T11:29:50.265775Z","hour":67,"humans":6988246428,"zombies":7340299} +{"timestamp":"2026-01-06T11:29:51.190449Z","hour":68,"humans":6985307033,"zombies":9179224} +{"timestamp":"2026-01-06T11:29:52.377333Z","hour":69,"humans":6981636351,"zombies":11471462} +{"timestamp":"2026-01-06T11:29:53.770680Z","hour":70,"humans":6977048363,"zombies":14337618} +{"timestamp":"2026-01-06T11:29:55.459667Z","hour":71,"humans":6971310897,"zombies":17922085} +{"timestamp":"2026-01-06T11:29:57.552975Z","hour":72,"humans":6964144087,"zombies":22402087} +{"timestamp":"2026-01-06T11:30:00.170113Z","hour":73,"humans":6955182481,"zombies":28001066} +{"timestamp":"2026-01-06T11:30:03.456462Z","hour":74,"humans":6943981810,"zombies":34999886} +{"timestamp":"2026-01-06T11:30:07.702079Z","hour":75,"humans":6929981054,"zombies":43752405} +{"timestamp":"2026-01-06T11:30:13.882518Z","hour":76,"humans":6912478647,"zombies":54689218} +{"timestamp":"2026-01-06T11:30:22.015179Z","hour":77,"humans":6890596914,"zombies":68366905} +{"timestamp":"2026-01-06T11:30:31.272590Z","hour":78,"humans":6863257782,"zombies":85453176} +{"timestamp":"2026-01-06T11:30:42.321339Z","hour":79,"humans":6829079144,"zombies":106814388} +{"timestamp":"2026-01-06T11:30:56.415154Z","hour":80,"humans":6786359866,"zombies":133517289} +{"timestamp":"2026-01-06T11:31:14.102785Z","hour":81,"humans":6732956038,"zombies":166893424} diff --git a/states_final.json b/states_final.json new file mode 100644 index 0000000..6ca9963 --- /dev/null +++ b/states_final.json @@ -0,0 +1,38 @@ +[ + { + "hour": 0, + "humans": 10, + "timestamp": "2026-01-06T11:18:27.762962Z", + "zombies": 3 + }, + { + "hour": 1, + "humans": 10, + "timestamp": "2026-01-06T11:18:27.823728Z", + "zombies": 3 + }, + { + "hour": 2, + "humans": 8, + "timestamp": "2026-01-06T11:18:27.874694Z", + "zombies": 5 + }, + { + "hour": 3, + "humans": 6, + "timestamp": "2026-01-06T11:18:27.925686Z", + "zombies": 7 + }, + { + "hour": 4, + "humans": 3, + "timestamp": "2026-01-06T11:18:27.976690Z", + "zombies": 10 + }, + { + "hour": 5, + "humans": -3, + "timestamp": "2026-01-06T11:18:28.027762Z", + "zombies": 15 + } +] \ No newline at end of file