MapScreenToInterface
as ingame (edited)// create nameplates at standard zoom
This.Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
This.RenderTools()->MapScreenToInterface(This.m_pClient->m_Camera.m_Center.x, This.m_pClient->m_Camera.m_Center.y);
CNamePlates::OnRender
just uses the screen size from the previous componentspectate
and spectate_multiview
still works on yourself, and of course modded server can just send a SpectatorId to force it.
Note that left...qsort
, it segfaults let input = open_in "inputs/day1_p1.txt" in
try
let lines = In_channel.input_lines input in
let parse_line x =
List.map int_of_string
@@ List.filter (fun x -> x <> "")
@@ String.split_on_char ' ' @@ String.trim x
in
let values = List.map parse_line lines in
let lhs, rhs =
List.split
@@ List.filter_map
(fun value ->
match value with [x; y] -> Option.Some (x, y) | _ -> Option.None )
values
in
let lhs = List.fast_sort Int.compare lhs in
let rhs = List.fast_sort Int.compare rhs in
let result =
List.map (fun (x, y) -> Int.abs (y - x)) @@ List.combine lhs rhs
in
let result = List.fold_left ( + ) 0 result in
let () = print_int result in
let () = print_newline () in
close_in input
with e -> close_in_noerr input ; raise e
part 1
learning ocaml which is also kinda my first functional lang so im going slow aflet input = open_in "inputs/day1_p1.txt" in
try
let lines = In_channel.input_lines input in
let parse_line x =
List.map int_of_string
@@ List.filter (fun x -> x <> "")
@@ String.split_on_char ' ' @@ String.trim x
in
let values = List.map parse_line lines in
let lhs, rhs =
List.split
@@ List.filter_map
(fun value ->
match value with [x; y] -> Option.Some (x, y) | _ -> Option.None )
values
in
let lhs = List.fast_sort Int.compare lhs in
let rhs = List.fast_sort Int.compare rhs in
let result =
List.map (fun (x, y) -> Int.abs (y - x)) @@ List.combine lhs rhs
in
let result = List.fold_left ( + ) 0 result in
let () = print_int result in
let () = print_newline () in
close_in input
with e -> close_in_noerr input ; raise e
part 1
learning ocaml which is also kinda my first functional lang so im going slow af (lang dune 3.16)
(name aoc2024)
(generate_opam_files true)
(source
(github edg-l/aoc2024-ocaml))
(authors "Edgar Luque")
(maintainers "Edgar Luque")
(license LICENSE)
(documentation https://url/to/documentation)
(package
(name aoc2024)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml dune)
(tags
(topics "to describe" your project)))
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html
(lang dune 3.16)
(name aoc2024)
(generate_opam_files true)
(source
(github edg-l/aoc2024-ocaml))
(authors "Edgar Luque")
(maintainers "Edgar Luque")
(license LICENSE)
(documentation https://url/to/documentation)
(package
(name aoc2024)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml dune)
(tags
(topics "to describe" your project)))
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html
s_SkinLastRefreshTime
is initialized to the current refresh time, which prevents the list from being updated unless the user already has favorite skins, as adding these also cause the list to be updated.
The static s_SkinLastRefreshTime
variable is replaced with a member variable m_SkinListNeedsUpdate
and an empty optional is used as initial value to always refresh the list.
The separate m_SkinListNeedsUpdate
and `m_SkinFavo...skin_lumas = float[len(skin_pixels)]
for idx, pixel in skin_pixels {
// magic numbers from Wikipedia
skin_lumas[idx] = pixel.r * 0.2126 + pixel.g * 0.7152 + pixel.b * 0.0722
}
brightest = 0.0f
for _, luma in skin_lumas {
if luma > brightest {
brightest = luma
}
}
brightest /= 255
if brightest == 0 {
brightest = 1
}
bw_skin_pixels = Pixel[len(skin_pixels)]
for idx, pixel in bw_skin_pixels {
value = int(skin_lumas[idx] / brightest)
pixel.r = value
pixel.g = value
pixel.b = value
}
(edited)/ brightest
What is brightest is 0?let input = open_in "inputs/day1.txt" in
try
let lines = In_channel.input_lines input in
let parse_line x =
List.map int_of_string
@@ List.filter (fun x -> x <> "")
@@ String.split_on_char ' ' @@ String.trim x
in
let values = List.map parse_line lines in
let lhs, rhs =
List.split
@@ List.filter_map
(fun value ->
match value with [x; y] -> Option.Some (x, y) | _ -> Option.None )
values
in
let countn x =
List.fold_left (fun acc a -> if a = x then acc + 1 else acc) 0
in
let result = List.map (fun x -> x * countn x rhs) lhs in
let result = List.fold_left ( + ) 0 result in
let () = print_int result in
let () = print_newline () in
close_in input
with e -> close_in_noerr input ; raise e
part 2{
pkgs ? import <nixpkgs> { },
}:
let
parseNumberPair =
line:
let
parts = builtins.filter (s: s != "") (builtins.split "[ \t]+" line);
nums =
if builtins.length parts == 2 then
let
first = builtins.parseInt (builtins.elemAt parts 0);
second = builtins.parseInt (builtins.elemAt parts 1);
in
if builtins.isInt first && builtins.isInt second then
[
first
second
]
else
null
else
null;
in
nums;
readNumberPairs =
filePath:
let
content = builtins.readFile filePath;
lines = builtins.filter (line: line != "") (builtins.split "\n" content);
pairs = builtins.filter (x: x != null) (map parseNumberPair lines);
in
pairs;
calculateDistance =
pairs:
let
leftList = builtins.sort (a: b: a < b) (map (pair: builtins.elemAt pair 0) pairs);
rightList = builtins.sort (a: b: a < b) (map (pair: builtins.elemAt pair 1) pairs);
distances = builtins.genList (
i: builtins.abs (builtins.elemAt leftList i - builtins.elemAt rightList i)
) (builtins.length leftList);
totalDistance = if distances != [ ] then builtins.foldl' (acc: dist: acc + dist) 0 distances else 0;
in
totalDistance;
in
{
processInput =
inputFile:
let
inputPairs = readNumberPairs inputFile;
in
calculateDistance inputPairs;
}
let countn x =
List.fold_left (fun acc a -> if a = x then acc + 1 else acc) 0
{
pkgs ? import <nixpkgs> { },
}:
let
parseNumberPair =
line:
let
parts = builtins.filter (s: s != "") (builtins.split "[ \t]+" line);
nums =
if builtins.length parts == 2 then
let
first = builtins.parseInt (builtins.elemAt parts 0);
second = builtins.parseInt (builtins.elemAt parts 1);
in
if builtins.isInt first && builtins.isInt second then
[
first
second
]
else
null
else
null;
in
nums;
readNumberPairs =
filePath:
let
content = builtins.readFile filePath;
lines = builtins.filter (line: line != "") (builtins.split "\n" content);
pairs = builtins.filter (x: x != null) (map parseNumberPair lines);
in
pairs;
calculateDistance =
pairs:
let
leftList = builtins.sort (a: b: a < b) (map (pair: builtins.elemAt pair 0) pairs);
rightList = builtins.sort (a: b: a < b) (map (pair: builtins.elemAt pair 1) pairs);
distances = builtins.genList (
i: builtins.abs (builtins.elemAt leftList i - builtins.elemAt rightList i)
) (builtins.length leftList);
totalDistance = if distances != [ ] then builtins.foldl' (acc: dist: acc + dist) 0 distances else 0;
in
totalDistance;
in
{
processInput =
inputFile:
let
inputPairs = readNumberPairs inputFile;
in
calculateDistance inputPairs;
}
skin_lumas = float[len(skin_pixels)]
for idx, pixel in skin_pixels {
// magic numbers from Wikipedia
skin_lumas[idx] = pixel.r * 0.2126 + pixel.g * 0.7152 + pixel.b * 0.0722
}
brightest = 0.0f
for _, luma in skin_lumas {
if luma > brightest {
brightest = luma
}
}
brightest /= 255
if brightest == 0 {
brightest = 1
}
bw_skin_pixels = Pixel[len(skin_pixels)]
for idx, pixel in bw_skin_pixels {
value = int(skin_lumas[idx] / brightest)
pixel.r = value
pixel.g = value
pixel.b = value
}
(edited)if brightest == 0
part is only in case the entire image is pure blackskin_lumas = float[len(skin_pixels)]
for idx, pixel in skin_pixels {
// magic numbers from Wikipedia
skin_lumas[idx] = pixel.r * 0.2126 + pixel.g * 0.7152 + pixel.b * 0.0722
}
brightest = 0.0f
for _, luma in skin_lumas {
if luma > brightest {
brightest = luma
}
}
brightest /= 255
if brightest == 0 {
brightest = 1
}
bw_skin_pixels = Pixel[len(skin_pixels)]
for idx, pixel in bw_skin_pixels {
value = int(skin_lumas[idx] / brightest)
pixel.r = value
pixel.g = value
pixel.b = value
}
(edited)qsort
, it segfaults compare:
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-24], rdi
mov QWORD PTR [rbp-32], rsi
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax]
mov DWORD PTR [rbp-4], eax
mov rax, QWORD PTR [rbp-32]
mov eax, DWORD PTR [rax]
mov DWORD PTR [rbp-8], eax
mov eax, DWORD PTR [rbp-4]
sub eax, DWORD PTR [rbp-8]
pop rbp
ret
r14
, r15
registers breaks everything, cool#!/bin/bash
#Advent of Code - Day 01
mapfile -t a < <(sort -k1 -n "$1" | cut -d' ' -f1)
mapfile -t b < <(sort -k2 -n "$1" | cut -d' ' -f4)
for i in "${!a[@]}"; do x=$((${a[$i]}-${b[$i]})); t1=$((${t1:-0}+${x#-})); done
while read -r i; do
x=$(cut -d' ' -f4 "$1" | sort | uniq -c | sed 's/^[ \t]*//' | grep " $i" | cut -d' ' -f1)
t2=$((${t2:-0}+(i * ${x:-0})))
done < <(cut -d' ' -f1 "$1")
printf -- "p1: %s\\np2: %s\\n" "$t1" "$t2"
# windows-toolchain.cmake
set(CMAKE_SYSTEM_NAME Windows) # Target system
#set(CMAKE_SYSTEM_PROCESSOR AMD64) # Target processor architecture (x86_64 for 64-bit)
# Specify the compiler paths
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
set(CMAKE_LINKER x86_64-w64-mingw32-ld)
# Add extra flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -shared")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -shared")
# I am missing my dlls
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_SHARED_LIBRARY_PREFIX "") # Windows doesn't use 'lib' prefix for DLLs
set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")
# Optional: Define the Windows library path
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
# Optional: Adjust search paths for headers and libraries
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# windows-toolchain.cmake
set(CMAKE_SYSTEM_NAME Windows) # Target system
#set(CMAKE_SYSTEM_PROCESSOR AMD64) # Target processor architecture (x86_64 for 64-bit)
# Specify the compiler paths
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
set(CMAKE_LINKER x86_64-w64-mingw32-ld)
# Add extra flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -shared")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -shared")
# I am missing my dlls
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_SHARED_LIBRARY_PREFIX "") # Windows doesn't use 'lib' prefix for DLLs
set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")
# Optional: Define the Windows library path
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
# Optional: Adjust search paths for headers and libraries
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
#! /usr/bin/awk -f
function diff(a, b) {
if (a > b) {
return a - b
} else {
return b - a
}
}
BEGIN {
} {
a[FNR] = $1
b[FNR] = $2
}
END {
asort(a)
asort(b)
for (line in a)
sum += diff(a[line], b[line])
print sum
}
2:
#! /usr/bin/awk -f
BEGIN {
} {
numbers[FNR] = $1
occurences[$2] += 1
}
END {
for (line in numbers) {
number = numbers[line]
sum += number * occurences[number]
}
print sum
}
(edited)