Skip to content

Instantly share code, notes, and snippets.

@scottfoster
scottfoster / battleship.php
Created September 1, 2025 09:27
Imagine a simplified version of the game Battleship played on a 2D grid. The grid represents the sea, and each cell can either be empty (.) or contain a part of a ship (X). Ships are placed horizontally or vertically, and there are no adjacent ships. Given a grid, count the number of battleships in it. Extra credit: can you make a layout generat…
<?php
function numberOfShips(array $ships): int
{
$totalShips = 0;
$rows = count($ships);
$cols = count($ships[0]);
for ($r = 0; $r < $rows; $r++)
servers() {
aws ec2 describe-instances --profile munzee --region us-east-1 --filters "Name=instance-state-name,Values=running" --query 'Reservations[].Instances[].[ [Tags[?Key==`Name`].Value][0][0],PrivateIpAddress ]' --output table | sort -n -k 2
}