commit 90a915fcf0a4c28ca7f7d6cb8078509729cc3469 Author: Kenryu Shibata Date: Mon Oct 12 12:01:52 2026 +0900 initial commit / finished report diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..613cd88 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.intermediates/ diff --git a/.latexmkrc b/.latexmkrc new file mode 100644 index 0000000..03fd9b7 --- /dev/null +++ b/.latexmkrc @@ -0,0 +1,6 @@ +$out_dir = "./out"; +$emulate_aux = 1; +$aux_dir = ".intermediates"; + +$pdf_mode = 5; +$xelatex = "xelatex -synctex=1 -file-line-error -interaction-nonstopmode %O %S"; diff --git a/README.md b/README.md new file mode 100644 index 0000000..6bb0232 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Info proc Q3 1st assignment + diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c9fa1c1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,147 @@ +{ + "nodes": { + "eskk-vim": { + "flake": false, + "locked": { + "lastModified": 1778495889, + "narHash": "sha256-1R/ChmsdtSXMEMMtKuyXgX7oe7ZE0a8gdx3sC9s6wp0=", + "owner": "vim-skk", + "repo": "eskk.vim", + "rev": "131a290d5305b9bf06426cfe32065f97e23d471c", + "type": "github" + }, + "original": { + "owner": "vim-skk", + "repo": "eskk.vim", + "type": "github" + } + }, + "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" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "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": 1791048980, + "narHash": "sha256-KgItSKML8Xvte0B7/uGnBDsYzSnnKHcOaiUbgWBXLXw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a7868a727837f3c09cee2ce0ca671c76b1589fed", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1791048980, + "narHash": "sha256-KgItSKML8Xvte0B7/uGnBDsYzSnnKHcOaiUbgWBXLXw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a7868a727837f3c09cee2ce0ca671c76b1589fed", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "report-temp": { + "inputs": { + "eskk-vim": "eskk-vim", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1791173037, + "narHash": "sha256-FNA6OiLdj0Gb1755NWjEnWeNfsRZd1QGorhwl6BtgMo=", + "owner": "kenryuS", + "repo": "report-temp", + "rev": "5275b93bc3f6fade70a1ec11689f45bdf2a77169", + "type": "github" + }, + "original": { + "owner": "kenryuS", + "repo": "report-temp", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "report-temp": "report-temp" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "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..f7a5fb0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + description = "Template for LaTeX"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + report-temp.url = "github:kenryuS/report-temp"; + }; + + outputs = { self, nixpkgs, flake-utils, report-temp }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + config = {}; + overlays = []; + }; + in + { + devShells.default = report-temp.devShells.${system}.latex; + } + ); +} diff --git a/out/report-info_proc_2-q3-1.pdf b/out/report-info_proc_2-q3-1.pdf new file mode 100644 index 0000000..cb27666 Binary files /dev/null and b/out/report-info_proc_2-q3-1.pdf differ diff --git a/out/report-info_proc_2-q3-1.synctex.gz b/out/report-info_proc_2-q3-1.synctex.gz new file mode 100644 index 0000000..4b6416f Binary files /dev/null and b/out/report-info_proc_2-q3-1.synctex.gz differ diff --git a/prog/Makefile b/prog/Makefile new file mode 100644 index 0000000..4f18a76 --- /dev/null +++ b/prog/Makefile @@ -0,0 +1,11 @@ +CC:=gcc +CFLAGS:=-g -O2 -Wall -Wpedantic -lm + +SRCS:= \ + a1.c +EXECS:=$(patsubst %.c,%,${SRCS}) + +all: ${EXECS} + +%: %.c + ${CC} ${CFLAGS} $^ -o $@ diff --git a/prog/a1 b/prog/a1 new file mode 100755 index 0000000..9e24697 Binary files /dev/null and b/prog/a1 differ diff --git a/prog/a1.c b/prog/a1.c new file mode 100644 index 0000000..d077d3c --- /dev/null +++ b/prog/a1.c @@ -0,0 +1,85 @@ +#include +#include +#include + +typedef enum { + ABSOLUTE, + DELTA, + NUM_INPUT_TYPE +} InputType; + +typedef struct { + double x; + double y; +} Point; + +typedef struct { + Point pt; + double fuel; +} Car; + +double calc_dist(Point *p1, Point *p2) { + double x2 = (p1->x - p2->x) * (p1->x - p2->x); + double y2 = (p1->y - p2->y) * (p1->y - p2->y); + return sqrt(x2 + y2); +} + +void get_info(Car *c) { + printf("Current Position: (%.2f, %.2f)\nFuel Available: %.2f Liter\n", + c->pt.x, + c->pt.y, + c->fuel + ); +} + +int move(Car *c, Point *dest) { + double d = calc_dist(&c->pt, dest); + if (d > c->fuel) return 0; + + c->pt = *dest; + c->fuel -= d; + return 1; +} + +int main(void) { + + Car myCar = {{0.0,0.0}, 90.0}; + Point pt = {0}; + + while(1) { + get_info(&myCar); + char c; + printf("Continue? [y/n]: "); + scanf("%1[a-zA-Z]", &c); + if (c == 'n') break; + InputType t; + bool isValidInput = false; + while (!isValidInput) { + printf("Select mode [0 = Absolute Position / 1 = Relative Position]: "); + scanf("%u", (unsigned int*)&t); + if (t < NUM_INPUT_TYPE) isValidInput = true; + else puts("Invalid mode!"); + } + printf("Input x coordinate: "); + scanf("%lf", &pt.x); + printf("Input y coordinate: "); + scanf("%lf", &pt.y); + switch (t) { + case ABSOLUTE: + break; + case DELTA: + pt.x += myCar.pt.x; + pt.y += myCar.pt.y; + break; + default: + break; + } + int res = move(&myCar, &pt); + if (res == 0) { + puts("Low Fuel!"); + } + getchar(); // environment specific fix + } + + return 0; +} diff --git a/prog/res.png b/prog/res.png new file mode 100644 index 0000000..3e9fa20 Binary files /dev/null and b/prog/res.png differ diff --git a/report-info_proc_2-q3-1.tex b/report-info_proc_2-q3-1.tex new file mode 100644 index 0000000..176517c --- /dev/null +++ b/report-info_proc_2-q3-1.tex @@ -0,0 +1,43 @@ +\documentclass[xelatex,a4paper,11pt,ja=standard]{bxjsarticle} + +\usepackage{preamble} +\usepackage{simple-title} + +\reportauthor{柴田 健琉} +\reporttitle{情報処理2 - 後期第1回課題} +\reportdate{2026年}{10月}{05日} +\turnindate{2026年}{10月}{12日} + +\begin{document} + \simpletitle + + \section{はじめに} + + この課題のプログラムは以下の環境での動作が確認されている: + + \begin{itemize} + \item{OS: NixOS 26.05 Yarara, Linux 7.2.8 x86\_64} + \item{CC: GCC 16.2.0} + \item{CFLAGS: \texttt{-g -O2 -Wall -Wpedantic -lm}} + \end{itemize} + + \section{課題} + + 教科書のList 12-9を書き換え, 目標地点の絶対座標を指定する方法と目標地点までの相対距離を指定する方法を選択できるようにしたプログラム. + + \lstinputlisting[language=C, caption={Modifiled List 12-9}]{./prog/a1.c} + + \subsection{実行結果} + + \begin{figure}[H] + \includegraphics[width=12cm]{./prog/res.png} + \end{figure} + + \subsection{おおまかな変更点} + + \begin{itemize} + \item{列挙体と\texttt{switch}文を用いた距離の指定方法の変更} + \item{実行環境による\texttt{scanf}関数の誤動作を抑制する\texttt{getchar}関数の追加} + \end{itemize} +\end{document} +