\documentclass[12pt,letterpaper]{article}

% ---- Standard packages only ----
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{enumitem}
\setlist[itemize]{itemsep=1pt,topsep=2pt,parsep=1pt,partopsep=0pt}
\usepackage{xcolor}
\usepackage{listings}
\usepackage[colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue]{hyperref}

% ---- Page layout ----
\geometry{margin=2.5cm,headheight=14pt,headsep=8pt}
\setlength{\parindent}{0pt}
\setlength{\parskip}{3pt plus 1pt}

% ---- Header / footer ----
\pagestyle{fancy}
\fancyhf{}
\rhead{\small\coursecode\ --- \studentname}
\lhead{\small Homework \hwnumber}
\rfoot{Page \thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

% ---- Metadata (edit these) ----
\newcommand{\coursecode}{Phys 256}
\newcommand{\hwnumber}{6}
\newcommand{\studentname}{Student Name}

% ---- Python listings style ----
\definecolor{codebg}{rgb}{0.97,0.97,0.95}
\definecolor{codekey}{rgb}{0.20,0.40,0.70}
\definecolor{codecom}{rgb}{0.40,0.40,0.40}
\definecolor{codestr}{rgb}{0.60,0.10,0.10}

\lstdefinestyle{pythonstyle}{
  language=Python,
  backgroundcolor=\color{codebg},
  basicstyle=\ttfamily\small,
  keywordstyle=\color{codekey}\bfseries,
  commentstyle=\color{codecom}\itshape,
  stringstyle=\color{codestr},
  showstringspaces=false,
  breaklines=true,
  frame=single,
  rulecolor=\color{codecom},
  numbers=left,
  numberstyle=\tiny\color{codecom},
  stepnumber=1,
  numbersep=8pt,
  tabsize=4,
  captionpos=b
}
\lstset{style=pythonstyle}

% ---- \problem and \solution commands ----
\newcounter{problem}
\makeatletter
\newcommand{\problem}[1]{%
  \refstepcounter{problem}%
  \vspace{6pt}\noindent{\fontsize{14pt}{16pt}\bfseries Problem \theproblem: #1}%
  \par\nobreak\vspace{3pt}}
\newcommand{\solution}{%
  \vspace{-2pt}%
  {\fontsize{14pt}{16pt}\bfseries\noindent Solution\par\nobreak\vspace{2pt}}}
\makeatother

% ---- Custom compact title (redefines \maketitle) ----
\makeatletter
\renewcommand{\maketitle}{%
  \thispagestyle{empty}%
  \noindent{\Large\bfseries \coursecode\ --- Homework \hwnumber}%
  \par\vspace{2pt}%
  \noindent{\studentname}%
  \par\vspace{8pt}%
  \hrule\vspace{10pt}}
\makeatother

\begin{document}
\maketitle
%---------------------------------------------------------------
\section*{Instructions}
\begin{itemize}
  \item You may use AI assistants to help write, test, and debug code, but you must understand your implementation and use your own scientific judgment to assess its validity. \textbf{Do not use AI to write the report.}
  \item Submit a PDF report containing in-line code snippets, plots, numerical results, explanations, and descriptions of relevant test cases. Submit your Python code separately.
  \item In your report, we are looking for you to \textbf{exercise and demonstrate your independent scientific judgment.} Thoughtful reports with careful, critical discussion of the results will receive a higher grade than those that simply run the AI-generated code and paste in the results.
  \item Submit each coded problem in a separate file named \lstinline{p1.py}, \lstinline{p2.py}, etc. You may import functions from previous problems. Include all necessary files in one ZIP archive.
  \item Use NumPy, SciPy, and Matplotlib where appropriate. Fix random seeds or specify them so that stochastic results can be reproduced. Label all plot axes.
\end{itemize}

\vspace{0.25in}

\problem{15 queens puzzle (10 points)}

This is variation of
\href{https://en.wikipedia.org/wiki/Eight_queens_puzzle}{the eight queens
puzzle}\footnote{\url{https://en.wikipedia.org/wiki/Eight_queens_puzzle}}
but you need to place 15 queens on a 15x15 chess board so none of the queens
share the same row, column, or diagonal.

You can encode the queens positions as 15 dimension vector $\vec{x} = [x_0, x_1, x_2, x_3, ..., x_{14}]$
with $x_i = 0,1,2, \cdots, 14$ in each components representing in
which row the $i_{th}$ queen stands.
For the cost function count how many queens share the same row, column, or diagonal.
During $\vec{x}$ update displace a random queen by 1 row (or use any
other ways which you find suitable). {\bf Make cost function responsible
for keeping queens on the board}, do not worry about it during new
$\vec{x}$ generation.

Display listings of the cost function and generation of new $\vec{x}$ in
your report. Discuss your strategies.

Use algorithm of your choosing which uses the above cost function and new
$\vec{x}$ generation and find a queen's arrangement which
satisfies the problem. Display this arrangement as a figure with 15x15
grid and  markers showing queen's locations. You do not need to be fancy,
any marker will do. Display this arrangement in your report.


\problem{Projectile motion with drag (10 points)}

During 4th of July celebration someone fired a rifle straight up. Find the
height of the bullet vs time of flight, assume that the rifle was fired
straight up and the bullet initial speed $v_0=715$~m/s. 
Recall that the projectile motion is governed by the following
equation

\begin{equation*}
	a_y = -g -\frac{v_y}{|v_y|} \frac{1}{2 m} \rho c_d A v_y^2
\end{equation*}
where $g$ acceleration due to gravity, $a_y$ and $v_y$ are acceleration and velocity along $y$ coordinate, 
$\rho = 1.2$~kg/m${}^3$ is the density of air, $c_d=0.09$ is the drag
coefficient, $m=0.008$~kg is the mass of the projectile, $A=4.6\times
10^{-5}$~m${}^2$ area of the bullet. 

For your report convert the above equation into a set of 1st order ODEs
in canonical form using $x, y_1, y_2, \cdots$ and $\vec{f}$.

Display the listing which is able to calculate $y$ and $v_y$ vs time.
Keep you algorithm general, i.e. do not hardcore physical variable until
the very end.

Plot $y$ and $v_y$ vs time for any $y>0$.

What is the speed of the bullet when it is impacting the ground.

Does the bullet reach the terminal velocity?


\end{document}
