Created
December 2, 2024 23:45
-
-
Save bschneidr/3d6499791c8d46b71f717f158ef5fb52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import polars as pl | |
import pandas as pd | |
# Read input data as a data frame with two columns | |
input = pl.from_pandas( | |
pd.read_table("day-1/input", sep = " ", header = None, | |
names = ["list_1", "list_2"]) | |
) | |
# Sort each column separately, | |
# then compute difference between each column's respective entries, | |
# and sum up the differences | |
input.with_columns( | |
pl.col(nm).sort() for nm in input.columns | |
).select( | |
(pl.col("list_1") - pl.col("list_2")).abs().sum().alias("list_distance") | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment