Karmmah

joined 2 years ago
[–] Karmmah 1 points 2 weeks ago* (last edited 2 weeks ago)

Julia

I did not try to make my solution concise and kept separate code for part 1 and part 2 with test cases for both to check if I broke anything. But after struggling with Day 2 I am quite pleased to have solved Day 3 with only a little bugfixing.

function calcLineResult(line::String)
	lineResult::Int = 0
	enabled::Bool = true
	for i=1 : length(line)
		line[i]!='m' ? continue : (i<length(line) ? i+=1 : continue)
		line[i]!='u' ? continue : (i<length(line) ? i+=1 : continue)
		line[i]!='l' ? continue : (i<length(line) ? i+=1 : continue)
		line[i]!='(' ? continue : (i<length(line) ? i+=1 : continue)
		num1Str::String = ""
		while line[i] in ['0','1','2','3','4','5','6','7','8','9'] #should check for length of digits < 3, but works without
			num1Str = num1Str*line[i]; (i<length(line) ? i+=1 : continue)
		end
		line[i]!=',' ? continue : (i<length(line) ? i+=1 : continue)
		num2Str::String = ""
		while line[i] in ['0','1','2','3','4','5','6','7','8','9'] #should check for length of digits < 3, but works without
			num2Str = num2Str*line[i]; (i<length(line) ? i+=1 : continue)
		end
		line[i]==')' ? lineResult+=parse(Int,num1Str)*parse(Int,num2Str) : continue
	end
	return lineResult
end

function calcLineResultWithEnabling(line::String,enabled::Bool)
	lineResult::Int = 0
	for i=1 : length(line)
		if enabled && line[i] == 'm'
			i<length(line) ? i += 1 : continue
			line[i]!='u' ? continue : (i<length(line) ? i+=1 : continue)
			line[i]!='l' ? continue : (i<length(line) ? i+=1 : continue)
			line[i]!='(' ? continue : (i<length(line) ? i+=1 : continue)
			num1Str::String = ""
			while line[i] in ['0','1','2','3','4','5','6','7','8','9']
				num1Str = num1Str*line[i]; (i<length(line) ? i+=1 : continue)
			end
			line[i]!=',' ? continue : (i<length(line) ? i+=1 : continue)
			num2Str::String = ""
			while line[i] in ['0','1','2','3','4','5','6','7','8','9']
				num2Str = num2Str*line[i]; (i<length(line) ? i+=1 : continue)
			end
			line[i]==')' ? lineResult+=parse(Int,num1Str)*parse(Int,num2Str) : continue
		elseif line[i] == 'd'
			i<length(line) ? i += 1 : continue
			line[i]!='o' ? continue : (i<length(line) ? i+=1 : continue)
			if line[i] == '('
				i<length(line) ? i += 1 : continue
				line[i]==')' ? enabled=true : continue
				#@info i,line[i-3:i]
			elseif line[i] == 'n'
				i<length(line) ? i += 1 : continue
				line[i]!=''' ? continue : (i<length(line) ? i+=1 : continue)
				line[i]!='t' ? continue : (i<length(line) ? i+=1 : continue)
				line[i]!='(' ? continue : (i<length(line) ? i+=1 : continue)
				line[i]==')' ? enabled=false : continue
				#@info i,line[i-6:i]
			else
				nothing
			end
		end
	end
	return lineResult,enabled
end

function calcMemoryResult(inputFile::String,useEnabling::Bool)
	memoryRes::Int = 0
	f = open(inputFile,"r")
	lines = readlines(f)
	close(f)
	enabled::Bool = true
	for line in lines
		if useEnabling
			lineRes::Int,enabled = calcLineResultWithEnabling(line,enabled)
			memoryRes += lineRes
		else
			memoryRes += calcLineResult(line)
		end
	end
	return memoryRes
end

if abspath(PROGRAM_FILE) == @__FILE__
	@info "Part 1"
	@debug "checking test input"
	inputFile::String = "day03InputTest"
	memoryRes::Int = calcMemoryResult(inputFile,false)
	try
		@assert memoryRes==161
	catch e
		throw(ErrorException("$e memoryRes=$memoryRes"))
	end
	@debug "test input ok"
	@debug "running real input"
	inputFile::String = "day03Input"
	memoryRes::Int = calcMemoryResult(inputFile,false)
	try
		@assert memoryRes==153469856
	catch e
		throw(ErrorException("$e memoryRes=$memoryRes"))
	end
	println("memory result: $memoryRes")
	@debug "real input ok"

	@info "Part 2"
	@debug "checking test input"
	inputFile::String = "day03InputTest"
	memoryRes::Int = calcMemoryResult(inputFile,true)
	try
		@assert memoryRes==48
	catch e
		throw(ErrorException("$e memoryRes=$memoryRes"))
	end
	@debug "test input ok"
	@debug "running real input"
	inputFile::String = "day03Input"
	memoryRes::Int = calcMemoryResult(inputFile,true)
	try
		@assert memoryRes==77055967
	catch e
		throw(ErrorException("$e memoryRes=$memoryRes"))
	end
	println("memory result: $memoryRes")
	@debug "real input ok"

end
[–] Karmmah 4 points 2 weeks ago

Julia, since I used it for some projects this year but never for something "time critical" like AoC with a new problem each day. I really like that it's simple like python but with strong typing. Originally I wanted to use Ocaml to learn it, but on day 1 I realised I don't know how to do anything in it yet πŸ˜„.

[–] Karmmah 3 points 4 weeks ago

I only have experience with Gnome out of the two but I haven't had the urge to switch yet. I like the look of it (I like that it looks different to Windows), the simplicity and the customisation with extensions (only a few and small ones, I recently started using OpenBar for some customization but I could do without). I keep my system rather minimal and I am not looking to put a lot of time into theming or customization.

I also tried Cosmic and I like the tiling aspect of it, but I also don't feel the need to switch. Maybe once it is released and I can figure out how to install it on Aeon.

[–] Karmmah 7 points 1 month ago

If I remember correctly I got them from this collection on archive.org and honestly they are just really nice quality pictures. But probably also a bit of nostalgia. πŸ˜„

[–] Karmmah 1 points 1 month ago (1 children)

The cars are just too big and maybe also too fast for Monaco at the moment. Maybe in the future this will change again.

[–] Karmmah 5 points 1 month ago

Or make the cars smaller again. They're finally getting smaller in 2026 but in the long term they should aim for v10 era size cars IMO.

[–] Karmmah 37 points 1 month ago (5 children)

TIL there's people thinking about stuff like this. Honestly a wallpaper is just some image that you chose to make your desktop nice to look at to me. I think I even used Windows XP wallpapers on Linux for some time.

[–] Karmmah 1 points 1 month ago

Also only very little software comes preinstalled which does not apply to Silverblue for example if I remember correctly.

[–] Karmmah 11 points 1 month ago (2 children)

Hab ich auch erst vor kurzem gelernt, aber Firefox ist ein Name fΓΌr den roten Panda, nicht fΓΌr einen Fuchs. Aber ja das Logo sieht eher nach Fuchs aus.

[–] Karmmah 9 points 1 month ago

Absolutely. If this rule was a permanent rule I don't think so many people would defend it. However from experience (reddit for example) I think many people know that US politics has the ability to claim and overrun just about every space on the "western" internet. This is not something that really creates value for many people especially those that don't live in the US and I think this ruling is trying to prevent that.

[–] Karmmah 93 points 1 month ago (26 children)

Instead of complaining can someone who dislikes this decision please just create a community like "AskLemmyUS", post a link here so people can find it and get on with it?

[–] Karmmah 31 points 1 month ago (8 children)

What's wrong about it though? The freedom lies in the ability to create your own community that is not regulated by one company/organisation owning the platform. You can go to the place where you agree with the rules and you don't have to live under the rules of someone you don't like.

view more: β€Ή prev next β€Ί