fi
fi
Red [title: "AOC Day 2"]
file: split trim/lines read %instructions #" "
aim: 0
horizontal: 0
depth: 0
depth2: 0
foreach [cmd arg] file [
arg: to-float arg
switch cmd [
"forward" [
horizontal: horizontal + arg
depth2: depth2 + (aim * arg)
]
"up" [
depth: depth - arg
aim: aim - arg
]
"down" [
depth: depth + arg
aim: aim + arg
]
]
]
print append "The first answer is: " horizontal * depth
print append "The second answer is: " horizontal * depth2
puts "What file would you like to solve for?"
print "> "
file = gets.not_nil!
unless File.exists? file
puts "You must provide a valid file!"
exit
end
instructions = File.read(file).lines.map {|line| line.split(" ")}
def getAnswers(instructions)
horizontal = 0
depth = 0
depth2 = 0
aim = 0
instructions.each do |instruction|
command = instruction[0]
argument = instruction[1].to_i
case command
when "forward"
horizontal &+= argument
depth2 &+= aim * argument
when "up"
depth &-= argument
aim &-= argument
when "down"
depth &+= argument
aim &+= argument
end
end
return [horizontal &* depth, horizontal &* depth2]
end
answers = getAnswers instructions
puts "The first answer is: #{answers[0]}"
puts "The second answer is: #{answers[1]}"
cat bigboy
takes a little bit to complete, so some time is wasted on reading the damn file before processing itRed [title: "fuck"]
file: split trim/lines read %instructions #" "
aim: 0
horizontal: 0
depth: 0
depth2: 0
foreach [cmd arg] file [
arg: to-float arg
switch cmd [
"forward" [
horizontal: horizontal + arg
depth2: depth2 + (aim * arg)
]
"up" [
depth: depth - arg
aim: aim - arg
]
"down" [
depth: depth + arg
aim: aim + arg
]
]
]
print append "The first answer is: " horizontal * depth
print append "The second answer is: " horizontal * depth2
let rec calculatePos depth horiz aim instructions =
match instructions with
| [] -> (depth, horiz)
| (dir, num) :: tail ->
match dir with
| "up" -> calculatePos depth horiz (aim - num) tail
| "down" -> calculatePos depth horiz (aim + num) tail
| "forward" -> calculatePos (depth + aim * num) (horiz + num) aim tail
| _ -> failwith "invalid direction"
package main
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
)
type instr struct {
dir string
num int
}
func main() {
content, _ := ioutil.ReadFile(os.Args[1])
raw := strings.Split(string(content), "\n")
parsed := []instr{}
for _, s := range raw {
split := strings.Split(s, " ")
i, _ := strconv.Atoi(split[1])
parsed = append(parsed, instr{split[0], i})
}
depth, horiz, aim := 0, 0, 0
for _, e := range parsed {
if e.dir == "forward" {
horiz += e.num
depth += aim * e.num
} else if e.dir == "up" {
aim -= e.num
} else if e.dir == "down" {
aim += e.num
}
}
fmt.Println(depth * horiz)
}
def getAnswers(instructions)
horizontal = 0
depth = 0
depth2 = 0
aim = 0
instructions.each do |instruction|
command = instruction[0]
argument = instruction[1].to_i
case command
when "forward"
horizontal &+= argument
depth2 &+= aim * argument
when "up"
depth &-= argument
aim &-= argument
when "down"
depth &+= argument
aim &+= argument
end
end
return [horizontal &* depth, horizontal &* depth2]
end
type instr = int * int
in my f# one then im like "fuck this let the compiler infer it"-w
?Benchmark 1: GOGC=off ./1 bigbigbigbigboy
Time (mean ± σ): 247.3 ms ± 7.4 ms [User: 208.3 ms, System: 39.2 ms]
Range (min … max): 235.4 ms … 254.5 ms 11 runs
Benchmark 2: GOGC=off ./2 bigbigbigbigboy
Time (mean ± σ): 250.9 ms ± 5.8 ms [User: 210.5 ms, System: 40.0 ms]
Range (min … max): 236.3 ms … 256.3 ms 11 runs
Summary
'GOGC=off ./1 bigbigbigbigboy' ran
1.01 ± 0.04 times faster than 'GOGC=off ./2 bigbigbigbigboy'
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char what[256];
int num;
int depth=0;
int hpos=0;
int aim=0;
FILE* fp = fopen("input","r");
while (EOF != fscanf(fp,"%s %d",what,&num)){
if (!strcmp(what, "forward")){
hpos+=num;
depth+=aim*num;
}
else if (!strcmp(what, "down")){
aim+=num;
}
else if (!strcmp(what, "up")){
aim-=num;
}
}
printf("%d\n",depth*hpos);
return 0;
}
declare -A counts=()
firstChars=()
for f in "${input[@]}" ; do
firstChars+=( ${f:0:1} )
done
firstChars
counts_$row
for (( i=1; i < 10; i++)); do
var_$i = $i
print "$var_$i"
done
(edited)$var_
and $i
separately instead of considering it as one variableeval "print \$var_$i"
are possible, though (edited)puts "What file would you like to solve for?"
print "> "
file = gets.not_nil!
unless File.exists? file
puts "You must provide a valid file!"
exit
end
def toDecimal(binary)
binary.reverse.chars.map_with_index do |digit, index|
digit.to_i * 2 ** index
end.sum
end
instructions = File.read(file).lines
counts = {} of Int32 => Array(Int32)
size = (0...instructions[0].size)
# This is always like, 6, but I want to make clean code
size.each do |i|
# Left is 0, right is 1
counts[i] = [0, 0]
end
instructions.each do |i|
i.chars.each_with_index do |num, index|
counts[index][num.to_i] += 1
end
end
gammaArr = [] of String
size.each do |i|
if counts[i][0] > counts[i][1]
gammaArr.push("0")
else
gammaArr.push("1")
end
end
finalGamma = gammaArr.join
finalEpsilon = gammaArr.map{|i| i == "1" ? "0": "1"}.join
puts toDecimal(finalGamma) * toDecimal(finalEpsilon)
(edited)[
'1', '1', '0', '1',
'1', '0', '0', '0',
'0', '1', '0', '0'
][12]
-> doesn't existvar length = input.length - 1
puts "What file would you like to solve for?"
print "> "
file = gets.not_nil!
unless File.exists? file
puts "You must provide a valid file!"
exit
end
def toDecimal(binary)
binary.reverse.chars.map_with_index do |digit, index|
digit.to_i * 2 ** index
end.sum
end
instructions = File.read(file).lines.map{|arr| arr.split("") }.transpose
gammaArr = [] of String
instructions.each do |i|
zeroCount = i.count("0")
oneCount = i.count("1")
if zeroCount > oneCount
gammaArr.push("0")
else
gammaArr.push("1")
end
end
finalGamma = gammaArr.join
finalEpsilon = gammaArr.map{|i| i == "1" ? "0": "1"}.join
puts toDecimal(finalGamma) * toDecimal(finalEpsilon)
for
loop???proc greaterThan32(x: int): bool = x > 32
f# to compare:
let greaterThan32 x = x > 32
(edited)proc greaterThan32(x: int): bool = x > 32
f# to compare:
let greaterThan32 x = x > 32
(edited)gyy gop vnature pussy , lt nach
cookie yopt law ( ) zhy
vilkoyvglaz ( gop type nechotko ) zhy
ksiva . malyava ( " I really am a language " ) nah
gop bitch chotko tries
have ilivzhopuraz zhy
gop bitch chotko nach
potreschim ( semki choblyasuka Troole ) zhy
lt bitch ksiva . compute LohaByNumber ( " list " ) nah
fucked up . nix ( " Hello, yopta " ) nah
there
is
there is
gop
is just a reference to old gopnik cultureimport std/rdstdin
func readStdin(): string =
var txt = ""
while true:
var line = ""
if not rdstdin.readLineFromStdin("", line):
break
txt &= line & "\n"
txt[0..^2]
let split = readStdin().split({'\n'})
let (gr, er) = calculateRates(split)
echo gr * er
FUCK_OFF_AND_DIE <|
(["mom"] |> (List.append <| ["your"])
|> cumcord.modules.webpack.findByProps)
\((?>\((?<c>)|[^()]+|\)(?<-c>))*(?(c)(?!))\)
^ lisp interpreterp!
Use p!help
to get a list of commands, and p!help <command>
to see more info about a command.
If you need help or find a bug, ask for help in our support serverdef getSecondAnswer(input)
data = input
pos = 0
while true
return if data.size == 1
easier = data.map {|i| i.split("")}.transpose[pos]
zeroCount = easier.count "0"
oneCount = easier.count "1"
keep = "0"
if zeroCount > oneCount
keep = "1"
end
data.reject! {|i| i[pos].to_s != keep }
pos += 1
puts data
end
end
here's my oxygen generator rating solution, it's a fucking mess (the cleaner one was made literally hours ago and trashed) (edited)puts "What file would you like to solve for?"
print "> "
file = gets.not_nil!
unless File.exists? file
puts "You must provide a valid file!"
exit
end
def toDecimal(binary)
binary.reverse.chars.map_with_index do |digit, index|
digit.to_i * 2 ** index
end.sum
end
def flipBits(binaryArr)
binaryArr.map do |digit|
digit == "1" ? "0" : "1"
end
end
input = File.read(file).lines
def getFirstAnswer(input)
gammaArr = [] of String
input.map{|arr| arr.split("")}.transpose.each do |i|
zeroCount = i.count "0"
oneCount = i.count "1"
if zeroCount > oneCount
gammaArr.push "0"
else
gammaArr.push "1"
end
end
finalGamma = gammaArr.join
finalEpsilon = flipBits(gammaArr).join
toDecimal(finalGamma) * toDecimal(finalEpsilon)
end
def getOxygen(input)
data = input
pos = 0
while true
return data[0] if data.size == 1
easier = data.map {|i| i.split("")}.transpose[pos]
zeroCount = easier.count "0"
oneCount = easier.count "1"
keep = "1"
if zeroCount > oneCount
keep = "0"
end
data = data.reject {|i| i[pos].to_s != keep }
pos += 1
end
end
def getCo2(input)
data = input
pos = 0
while true
return data[0] if data.size == 1
easier = data.map {|i| i.split("")}.transpose[pos]
zeroCount = easier.count "0"
oneCount = easier.count "1"
keep = "0"
if zeroCount > oneCount
keep = "1"
end
data = data.reject {|i| i[pos].to_s != keep }
pos += 1
end
end
def getSecondAnswer(input)
oxygen = getOxygen(input)
co2 = getCo2(input)
toDecimal(oxygen) * toDecimal(co2)
end
puts "The first answer is: #{getFirstAnswer input}"
puts getSecondAnswer input
mostCommon
function) if you want but I'm afraid that it will just spoil you7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1
22 13 17 11 0
8 2 23 4 24
21 9 14 16 7
6 10 3 18 5
1 12 20 15 19
3 15 0 2 22
9 18 13 17 5
19 8 7 25 23
20 11 10 24 4
14 21 16 12 6
14 21 17 24 4
10 16 15 9 19
18 8 23 26 20
22 11 13 6 5
2 0 12 3 7
1 1 1 1 1 1 1 2 0 0
1 1 1 1 1 1 1 2 0 0
1 1 1 1 1 1 1 2 0 0
1 1 1 1 1 1 1 2 0 0
1 1 1 2 2 2 2 2 1 0
1 1 1 1 1 1 1 1 0 0
1 1 1 1 1 1 1 1 0 0
1 1 1 1 1 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0
2 2 1 1 1 0 0 0 0 0
type coord = int * int
let pointCoveredByLine (line: coord * coord) (point: coord) =
let inBoundsX = fst (fst line) <= fst point && fst (snd line) >= fst point
let inBoundsY = snd (fst line) <= snd point && snd (snd line) >= snd point
inBoundsX && inBoundsY
0 0 0 0 0 0 0 1 0 0
0 0 1 0 0 0 0 1 0 0
0 0 1 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 0 0
0 1 1 2 1 1 1 2 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
2 2 2 1 1 1 0 0 0 0
arr
|> List.map List.concat
|> List.concat
|> List.filter (fun x => x >= 1)
damn (edited)1.fsx
THANK GOD FOR GIT4/1.fsx
| 2.fsx
| > 5/1.fsx
<
"OH FUCK"if(coord["x1"] == coord["y2"] && coord["x2"] == coord["y1"]) { // 9,7 -> 7,9
if(x == coord["x1"] && y == coord["y1"]) { // 7,9
addPoint(x,y)
} else if(x == coord["x2"] && y == coord["y2"]) { // 9,7
addPoint(x,y)
} else if(x == y && x == (parseInt(coord["x1"]) + parseInt(coord["x2"]))/2) { // 8,8
addPoint(x,y)
}
}
x1,y1 -> x2,y2
/
direction diagonals just work/
direction diagonals just work 0,4 -> 4,0
for example, you count the horizontal distance (or vertical distance if you want), then iterate over the x's 0, 1, 2, 3, 4
and y's 4, 3, 2, 1, 0
. Because x and y are going opposite directions, x is plus and y is minus.0,4 -> 4,0
for example, you count the horizontal distance (or vertical distance if you want), then iterate over the x's 0, 1, 2, 3, 4
and y's 4, 3, 2, 1, 0
. Because x and y are going opposite directions, x is plus and y is minus. 0 0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
snd p - (fst p - fst (fst l)) = snd (fst l)
or in a more readable form
p.y - (p.x - l.a.x) = l.a.y
where l.a
is the first vertex of th eline (edited)(function() {
'use strict';
var coll = document.getElementsByTagName('ul');
var elements = Array.from(coll);
var ul = elements.filter(element => element.textContent.includes("About"))[0];
var boardItem = document.createElement('li')
boardItem.innerHTML = "<a href=\"/2021/leaderboard/private/view/1679699\">[Cum Board]</a>"
ul.appendChild(boardItem)
})();
(function() {
'use strict';
var coll = document.getElementsByTagName('ul');
var elements = Array.from(coll);
var ul = elements.filter(element => element.textContent.includes("About"))[0];
var boardItem = document.createElement('li')
boardItem.innerHTML = "<a href=\"/2021/leaderboard/private/view/1679699\">[Cum Board]</a>"
ul.appendChild(boardItem)
})();
(function() {
'use strict';
var coll = document.getElementsByTagName('ul');
var elements = Array.from(coll);
var ul = elements.filter(element => element.textContent.includes("About"))[0];
var boardItem = document.createElement('li')
boardItem.innerHTML = "<a href=\"/2021/leaderboard/private/view/1679699\">[Cum Board]</a>"
ul.appendChild(boardItem)
})();
https://adventofcode.com/2021/leaderboard/private/view/$ID.json
for rline in lines:
var line = rline
if line[0][0] == line[1][0]:
if line[0][1] > line[1][1]:
line = (line[1], line[0])
# line has equal x coords, so is vertical
for y in line[0][1]..line[1][1]:
grid[y][line[0][0]] += 1
elif line[0][1] == line[1][1]:
if line[0][0] > line[1][0]:
line = (line[1], line[0])
# line has equal y coords, so is horizontal
for x in line[0][0]..line[1][0]:
grid[line[0][1]][x] += 1
else:
echo "Line was not vertical nor horizontal"
doAssert false
import 'dart:convert';
import 'dart:io';
String readAllStdin() {
var working = "";
while (true) {
final line = stdin.readLineSync(encoding: utf8);
if (line == null) {
return working.substring(0, working.length - 1);
}
working += line + "\n";
}
}
out of memory edition
1 + 2 + 3 + ... + n
= n(n + 1) / 2
(edited)1 + 2 + 3 + ... + n
= n(n + 1) / 2
(edited)int
gives you ascii codes so mapping it thru string >> int
, tho inefficient, is more correct let leftSafe = x > 0
let topSafe = y > 0
let rightSafe = x + 1 < grid[y].Length
let bottomSafe = y + 1 < grid.Length
begin walk
0 0
1 0
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at FSI_0001.walk[a](a[][] grid, Int32 x, Int32 y)
readStdin().Split("\n", StringSplitOptions.RemoveEmptyEntries)
|> Array.map scanForError
|> Array.sum
|> printfn "%i"
just dont ask about the internals of scanForError...# seq<seq<int>>
let input = readStdin()
.split("\n")
.map((l) => cast[seq[char]](l).map((x) => parseInt($x)))
// input: int[][]
let input =
readStdin().Split("\n")
|> Array.map (fun x -> x.ToCharArray() |> Array.map (string >> int))
(edited)