New answers tagged

1 vote

Advent of Code 2023 - Day 2: Cube Conundrum

three variables for one concept MAX_RED = 12 MAX_GREEN = 13 MAX_BLUE = 14 My first impression is that this will likely turn out to be inconvenient, with three <...
J_H's user avatar
  • 17.3k
1 vote

Advent of Code 2023 Day 3, Part 2 in Python

representation What would you do differently? You used many immutable strings to represent the schematic diagram. Given that this spatially-oriented problem is asking us to examine Moore ...
J_H's user avatar
  • 17.3k
0 votes

Advent of Code 2023 day 1: Trebuchet in JS, part 2

Automatic Semicolon Insertion ASI Generally your use of semicolons is consistent as preferred (use them rather than not) however there is one potential issue. JavaScript requires semicolon. If you do ...
Blindman67's user avatar
  • 21.6k
2 votes

Advent of Code 2023, Day 8 Part 1 - Beginner Rust Solution

I honed my Rust through Advent of Code as well, so welcome to the club. I can tell you with hindsight that trying to handle errors in a formal way for early days with relatively simple input ...
naiveai's user avatar
  • 131
1 vote

Advent of Code 2023 day 1: Trebuchet (Part 1 and 2)

Don't assume all lines will fit into a fixed-size buffer You use a buffer with a hardcoded size of 1024 characters. As you write in the comments, it suffices for the sample data. But what if you would ...
G. Sliepen's user avatar
  • 50.7k
1 vote

Advent of Code 2023 day 1: Trebuchet in JS

Use functions ALways encapsulate code in a function at the very minimum. Example It should look something like... ...
Blindman67's user avatar
  • 21.6k
2 votes
Accepted

Advent of Code 2023 day 1: Trebuchet

Bug "1zero" is probably supposed to evaluate to 10. You don't handle the digit "zero". Reversing the string ...
AJNeufeld's user avatar
  • 33.3k
1 vote
Accepted

String represents a road. One character travels on the road obeying the stops - Code challenge (advent.js day 5)

carefully read the requirements The original problem asks us to Create a function that simulates the sled's movement ... Somehow you leapt from that to All must be in just one function. I see no ...
J_H's user avatar
  • 17.3k
3 votes

Advent of code 2023 day 4: Count scratchcard points - mostly in Bash

Got a tip from @choroba's alternative solution. To conditionally initialize or update an entry in a map, instead of: ...
janos's user avatar
  • 111k
3 votes

Advent of code 2023 day 4: Count scratchcard points - mostly in Bash

one word per line In nums_to_lines, these six lines follow a very clear pattern. But it seems a bit long. I tend to use ...
J_H's user avatar
  • 17.3k
4 votes

Advent of code 2023 day 2: count possible qube games - in pure Bash

What would you do differently? Well, choosing a language better suited to the task springs to mind, maybe python. In particular, I find this inconsistency distracting when reading such scripts: ...
J_H's user avatar
  • 17.3k
5 votes

Advent of code 2023 day 2: count possible qube games - in pure Bash

It's going to be a really minor thing, but a review is a review and thus doesn't belong in the comments. I've learned that calling files solve_day2_part2 in an &...
Mast's user avatar
  • 13.1k
3 votes
Accepted

Advent of code 2023 day 1: count trebuchet calibration numbers - mostly in Bash

For me, bash solution would rather be something like this: Part 1 ...
choroba's user avatar
  • 1,383
0 votes

Print a hollow Rhombus

Imagine you know someone beginning Java three years after writing this. You show them the code presented: Can they easily find out from looking at the code what it is to do? Whether it is correct? Do ...
greybeard's user avatar
  • 6,104
1 vote

HackerRank Algorithm Problem: Climbing the Leaderboard (Python)

My approach, described below, should definitely be an improvement. I have named my version climbing_leaderboard so as to not conflict with your name (I have ...
Booboo's user avatar
  • 749
1 vote

Trailing Digits

finally I found a link with a lot of examples. I found trailingdigits.py with a much more elegant approach github.com/RussellDash332/kattis/blob/main/src/… and another webpage that shows more detail ...
qleoz12's user avatar
  • 141
1 vote
Accepted

Given an array, remove zero or more elements to maximize the reduction where you add odd values and subtract even values

You could simply use this pattern: [greatest value, smallest value, greatest value, smallest value, ...] local maximum, local minimum, ... That means, go until ...
Nina Scholz's user avatar
2 votes

Trailing Digits

Picture yourself coming back to "V1 code" a decade from now: You can read it, you can run it. Do you know what does, and to what end? Name things for what they are good for. ...
greybeard's user avatar
  • 6,104
2 votes

Project Euler 60: Prime Pair Sets

Eliminate 2 and 5 from your sieve! Any 2+ digit prime cannot end in a 2 or a 5, as these will be multiples of ...
AJNeufeld's user avatar
  • 33.3k
4 votes

HackerRank Project Euler 12 (Python) | Highly Divisible Triangular Numbers

Inaccuracy Many Project Euler problems deal with BIG numbers. These often are large enough that int(number**0.5) will give you the incorrect result! Mathematically,...
AJNeufeld's user avatar
  • 33.3k
2 votes

Project Euler 10(Python) | Summation of Primes

It was clarified that this problem is the Hacker Rank version: https://www.hackerrank.com/contests/projecteuler/challenges/euler010/problem This problem has the format of multiple test cases being ...
harold's user avatar
  • 9,139

Top 50 recent answers are included