{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Taxi\n", "\n", "## Helpers" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import os\n", "import pandas as pd\n", "import requests\n", "from dotenv import load_dotenv\n", "\n", "load_dotenv()\n", "API_KEY = os.environ[\"API_KEY\"]\n", "URL_QUERY = \"https://%s.crucible.dreadnode.io/score\"\n", "URL_FLAG = \"https://crucible.dreadnode.io/api/challenges/%s/submit-flag\"\n", "CHALLENGE = \"taxi\"\n", "\n", "def query(flag):\n", " response = requests.post(\n", " URL_QUERY % CHALLENGE,\n", " headers={ \"X-API-Key\": API_KEY },\n", " json={ \"data\": flag }\n", " )\n", " return response.json()\n", "\n", "def submit(flag):\n", " response = requests.post(\n", " URL_FLAG % CHALLENGE,\n", " headers={ \"X-API-Key\": API_KEY },\n", " json={ \"challenge\": CHALLENGE, \"flag\": flag }\n", " )\n", " return False if response.status_code != 200 else response.json().get(\"correct\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Solution\n", "\n", "If we examine the different columns in the Parquet file we can see that the distribution of values for the `pickup_location` column is quite interesting." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "pickup_location\n", "Financial District 298\n", "Industrial Park 286\n", "Train Station 274\n", "Beach Front 272\n", "University 272\n", "Shopping Mall 259\n", "Business District 256\n", "Airport 252\n", "Historic Center 250\n", "Convention Center 250\n", "Entertainment Zone 245\n", "Sports Complex 243\n", "Downtown 242\n", "Theater District 237\n", "Hotel Zone 234\n", "Restaurant Row 232\n", "Arts District 231\n", "Residential Area 225\n", "Tech Hub 221\n", "Hospital 215\n", "Grand Central 1\n", "Railway Station 1\n", "Library 1\n", "North Station 1\n", "0mega Mall 1\n", "0pera House 1\n", "Name: count, dtype: int64" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_parquet(\"./data/taxi.parquet\")\n", "df[\"pickup_location\"].value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Looking at the rows for those pickup locations we can see that they all have identical `signal_north` and `signal_south` values: 85.0 and 15.0, respectively." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ride_idpickup_timepickup_locationdropoff_locationdriver_idpassenger_countfare_amounttip_amountpayment_typeratingride_duration_minutesdropoff_timesignal_northsignal_south
012024-01-01 00:00:00LibraryTech Hub63317.79012.52Cash1802024-01-01 01:20:0085.015.0
6006012024-01-03 02:00:000mega MallRestaurant Row58399.03019.16Cash4192024-01-03 02:19:0085.015.0
120012012024-01-05 04:00:00North StationTheater District49473.27514.76Cash5682024-01-05 04:30:0085.015.0
180018012024-01-07 06:00:00Grand CentralEntertainment Zone43456.35013.61Credit Card51052024-01-07 07:45:0085.015.0
240024012024-01-09 08:00:00Railway StationTech Hub51252.8609.15Cash552024-01-09 08:05:0085.015.0
300030012024-01-11 10:00:000pera HouseTech Hub24457.46019.95Mobile Payment4802024-01-11 11:20:0085.015.0
\n", "
" ], "text/plain": [ " ride_id pickup_time pickup_location dropoff_location \\\n", "0 1 2024-01-01 00:00:00 Library Tech Hub \n", "600 601 2024-01-03 02:00:00 0mega Mall Restaurant Row \n", "1200 1201 2024-01-05 04:00:00 North Station Theater District \n", "1800 1801 2024-01-07 06:00:00 Grand Central Entertainment Zone \n", "2400 2401 2024-01-09 08:00:00 Railway Station Tech Hub \n", "3000 3001 2024-01-11 10:00:00 0pera House Tech Hub \n", "\n", " driver_id passenger_count fare_amount tip_amount payment_type \\\n", "0 63 3 17.790 12.52 Cash \n", "600 58 3 99.030 19.16 Cash \n", "1200 49 4 73.275 14.76 Cash \n", "1800 43 4 56.350 13.61 Credit Card \n", "2400 51 2 52.860 9.15 Cash \n", "3000 24 4 57.460 19.95 Mobile Payment \n", "\n", " rating ride_duration_minutes dropoff_time signal_north \\\n", "0 1 80 2024-01-01 01:20:00 85.0 \n", "600 4 19 2024-01-03 02:19:00 85.0 \n", "1200 5 68 2024-01-05 04:30:00 85.0 \n", "1800 5 105 2024-01-07 07:45:00 85.0 \n", "2400 5 5 2024-01-09 08:05:00 85.0 \n", "3000 4 80 2024-01-11 11:20:00 85.0 \n", "\n", " signal_south \n", "0 15.0 \n", "600 15.0 \n", "1200 15.0 \n", "1800 15.0 \n", "2400 15.0 \n", "3000 15.0 " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "col_pickup = \"pickup_location\"\n", "\n", "df[df[col_pickup].isin(df[col_pickup].value_counts().nsmallest(6).index.values)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we filter for all rows with these signal values and join the first letters of the `pickup_location` column we get the flag." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "L0NGR0AD\n", "Flag accepted: True\n" ] } ], "source": [ "col_snorth = \"signal_north\"\n", "col_ssouth = \"signal_south\"\n", "\n", "flag = \"\".join(map(\n", " lambda s: s[0],\n", " df[(df[col_snorth] == 85.0) & (df[col_ssouth] == 15.0)][col_pickup].values\n", "))\n", "\n", "print(flag)\n", "print(\"Flag accepted:\", submit(query(flag)[\"flag\"]))" ] } ], "metadata": { "kernelspec": { "display_name": "venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 2 }