All Questions
Tagged with exercism or programming-challenge
3,358 questions
-1
votes
0
answers
52
views
Creating struct/interface for Advent of Code helper in Go
I'm using Advent of Code to learn Go and was looking for tips and feedback on how I'm using Go. Here's code I came up with for a helper with puzzles that have what I call an Area. I would call it ...
4
votes
2
answers
863
views
LeetCode 3366: Minimum Array Sum - w/o DP/memoisation
This program solves this LeetCode problem.
A Python iteration of the approach chosen got annoyingly verbose when using partition by value and rank - open coded because I wouldn't know which ...
2
votes
1
answer
59
views
Advent of Code 2024 - Day 1 (Common Lisp)
I have recently started learning lisp by reading ANSI Common Lisp, and I thought advent of code would be good for practice. Any feedback on my code for Day 1 would be appreciated.
...
4
votes
1
answer
67
views
LeetCode Rust solution for the Sliding Puzzle problem #773
Here is the solution to the LeetCode Sliding Puzzle Problem #773. The problem is to find the shortest solution for a 3 x 2 sliding puzzle.
I would appreciate any ideas to improve this code. But it's ...
3
votes
0
answers
39
views
LeetCode Rust solution for the Flip Columns problem #1072
Here is the solution to LeetCode Problem #1072.
The problem is to find the maximum number of rows in a matrix where all the values can be made equal after some columns are flipped. It's assumed that ...
6
votes
1
answer
789
views
Basic C++ implementation of linux wc command
I am working on the Build Your Own wc Tool coding challenge in C++. I have a working implementation that seems to match the output of the wc command for different ...
4
votes
1
answer
156
views
Poker Lite (AOC 2023 Day 7) using structs wrapped in an enum
I've been trying to learn Rust by working through Advent of Code 2023, specifically for day 7, part 1, here. It's Poker Lite:
You're given a list of hands. The input is formatted as ...
4
votes
4
answers
415
views
Convert the number formats (Decimal - Hexadecimal - Octal) to Decimal
Problem statement:
Write a program called multi_input.cpp that prompts the user to enter several integers in any combination of octal, decimal, or hexadecimal, ...
2
votes
1
answer
241
views
Roman Numerals Look and Say in rust (BIO 2020 Q1)
I was practicing question 1a of the British Informatics Olympiad 2020 past paper.
The Roman look-and-say description of a string (of Is, Vs, Xs, Ls, Cs, Ds and Ms) is made by taking each block of ...
1
vote
1
answer
136
views
golang - Kth largest element in an array using quick select - time limit exceeded issue
I am trying to solve the following problem in leetcode.
https://leetcode.com/problems/kth-largest-element-in-an-array/description
Given an integer array \$nums\$ and an integer \$k\$, return the \$k^\...
5
votes
1
answer
419
views
FORTRAN90 test suite for Project Euler
The intent of this test file is to go through each of my Project Euler solutions and see if they:
return the correct answer, and
do so in under 60 seconds (unless expected otherwise).
I am using ...
4
votes
1
answer
64
views
Parsing Lists: BIO 2024 Q2
I was practising question 2a of the British Informatics Olympiad 2024 past paper.
In this task you will manipulate lists of integers to create new lists. There are three fundamental lists that you ...
3
votes
1
answer
135
views
Efficient polynomial multiplication in Python
I'm practicing problems for the ICPC competition, and one of the problems requires solving it by using an FFT to compute the product of two polynomials efficiently. Since this is for the ICPC ...
4
votes
2
answers
359
views
BIO 2021 Q3a: Window Dressing (BFS in C++)
I was practicing question 3a of the British Informatics Olympiad 2021 past paper.
A shop is looking to display some boxes (conveniently labelled A, B, …) in their window. There is a
desired order for ...
4
votes
1
answer
129
views
BIO 2021 Q1a: Down Pat
I was practicing question 1a of the British Informatics Olympiad 2021 past paper.
A pat is a single letter or a string of letters which can be split into a left and right string (of at least 1 letter)...
1
vote
1
answer
96
views
Finding the number of distinct decompositions a number has using only repdigits
This is a problem from a previous semester that I am trying to upsolve. I am trying to solve a problem involving the total number of ways of decomposing a number using only repdigits. A repdigit is a ...
6
votes
3
answers
752
views
Finding the Zeckendorf Representation of a Positive Integer (BIO 2023 Q1)
I was practicing question 1a of the British Informatics Olympiad 2023 past paper.
In the Fibonacci sequence each number is generated by adding the previous two numbers in the
sequence. We will start ...
5
votes
1
answer
368
views
String Decryption in C (BIO 2022 Q1)
I was practicing question 1a of the 2022 British Informatics Olympiad past paper.
Each letter in the alphabet can be given a value based on its position in the alphabet, A being 1 through to Z being ...
5
votes
3
answers
867
views
Project Euler 127 - abc-hits
Problem (Rephrased from here):
The radical of \$n\$, \$rad(n)\$, is the product of distinct prime factors of \$n\$. For example, \$504 = 2^3 × 3^2 × 7\$, so \$rad(504) = 2 × 3 × 7 = 42\$.
We shall ...
6
votes
2
answers
432
views
Family, felon & fuzz River Crossing challenge
I first saw this challenge when a user posted it to SO about two years ago without a shred of code.
The post's plea, "How do I get started?" meant the user's post didn't survive long on that ...
2
votes
1
answer
46
views
Optimal Extraction of Longest Sorted Sequence from Individually Sorted Bucket Arrays Without Repetitions
Consider a bucket array containing sorted and/or empty buckets, and the goal is to extract the longest possible sequence in sorted order, under the following conditions:
Only one element in each ...
3
votes
1
answer
231
views
Leetcode: Number of Islands - BFS (Queue vs Recursion)
I was playing around with leetcode's Number of Islands.
As per the challenge's description:
Given an m x n 2D binary grid grid which represents a map of '1's
(land) and '0's (water), return the ...
3
votes
2
answers
94
views
Optimizing a Function to Check Pronic Numbers in JavaScript
I've written a function in JavaScript to check whether a given number is a Pronic number. A Pronic number, also known as an oblong number, rectangular number, or ...
4
votes
2
answers
63
views
Optimizing a Function to Generate a Row of Consecutive Odd Numbers in a Triangle
I've written a JavaScript function that generates a row of consecutive odd numbers in a triangle. The triangle looks like this:
...
5
votes
1
answer
210
views
Performance Tuning to enable answer for Project Euler #566 "Cake Icing Puzzle"
Related to this question I am still looking for a solution to Project Euler Problem 566 (see link for a nice simulation also):
Adam plays the following game with his birthday cake.
He cuts a piece ...
9
votes
2
answers
602
views
Advent of code 2023 day 5 in Java: mapping integer ranges to new integer ranges
Context
I'll be passing an interview coding test in java soon. I am experienced with other programming languages but am very unfamiliar with Java. I am looking for critiques of the coding style much ...
5
votes
2
answers
345
views
Coding challenge for mixing a string
Challenge at https://www.codewars.com/kata/5629db57620258aa9d000014/train/python
Given two strings s1 and s2, we want to visualize how different the
two strings are. We will only take into account ...
3
votes
1
answer
106
views
Coding puzzle - Passing year books
Question:
There are n students, numbered from 1 to n, each with their own
yearbook. They would like to pass their yearbooks around and get them
signed by other students.
You're given a list of n ...
5
votes
1
answer
350
views
Leetcode: Largest Number
I was trying out leetcode's Largest Number.
As per the challenge's description:
Given a list of non-negative integers nums, arrange them such that
they form the largest number and return it. Since ...
2
votes
0
answers
47
views
Last Stone Weight Problem in Haskell Using `fold`
A previous solution of this code has been posted on Code Review before.
This solution is more complicated then that one, but more performant (see the below)
Why is this another Question instead of a ...
2
votes
3
answers
567
views
Extract data from poorly formatted phonebook
The Problem
John keeps a backup of his old personal phone book as a text file. On
each line of the file he can find the phone number (formated as
+X-abc-def-ghij where X stands for one or two digits),...
4
votes
1
answer
173
views
Last Stone Weight Problem in Haskell using list `insert`
Background
Saw this problem on TheJobOverflow which seems to be a LeetCode question.
It bothered me that the "challenge" of this problem was to recognize the need for a specific data-type (...
3
votes
0
answers
84
views
Sum all numbers touching symbols in 2D grid (Advent of Code 2023 Day 3, Part 1)
Please offer suggestions to my below Rust approach for solving AoC 2023 Day 3, Part 1. The code is functionally correct, so I'm interested in understanding how I could have solved it in a more ...
4
votes
1
answer
145
views
Longest spell to cast from pages of spellbook follow-up
This question is from the PCTC 2022 R2 Past Paper and is a follow-up on my previous question. Previous question
I have implemented several solutions suggested, such as creating an array with pages ...
6
votes
4
answers
581
views
Longest spell to cast from pages of spellbook
While practicing for a school coding challenge, I came across this problem. My code got the right answers but exceeded the time limited. Any tips for how to reduce the time complexity?
https://pctc....
4
votes
2
answers
505
views
Leetcode: Steps to Make Array Non-decreasing
I was trying out leetcode's Steps to Make Array Non-decreasing
As per the challenge's description:
You are given a 0-indexed integer array nums. In one step, remove all
elements nums[i] where nums[i ...
1
vote
3
answers
217
views
LeetCode 856: Score of Parentheses
Given a balanced parentheses string s, return the score of the string.
The score of a balanced parentheses string is based on the following rule:
- "()" ...
1
vote
2
answers
127
views
Optimizing an algebraic assignment puzzle
I am going to do a math competition which allows writing programs to solve problems.
The code attempts to solve problem 25 from the Purple Comet Spring 2004 Mathematics Meet:
In the addition problem
<...
9
votes
4
answers
2k
views
Leetcode : First Missing Positive
I was trying out leetcode's first missing positive.
As per the challenge's description:
Given an unsorted integer array nums, return the smallest missing
positive integer.
You must implement an ...
1
vote
2
answers
91
views
Advent of Code 2023 day 1: Trebuchet (Part 2)
Task:
The task involves analyzing a calibration document containing lines of text. Each line represents a calibration value that needs to be recovered by extracting the first and last digits (which ...
4
votes
3
answers
1k
views
Advent of Code 2023 day 1: Trebuchet (Part 1)
Task:
The task involves analyzing a calibration document containing lines of text. Each line represents a calibration value that needs to be recovered by extracting the first and last digits and ...
4
votes
2
answers
295
views
Count frequency of words and print them in sorted order
Objective:
Write a program to count the frequencies of unique words from standard input, then print them out with their frequencies, ordered most frequent first. For example, given this input:
...
1
vote
1
answer
133
views
Read millions of integers from stdin and process them in Python within 2 seconds
This is a competitive programming problem which has never been solved in Python within the time limit of 2 seconds. It is about Disjoint Set Union:
Source: Algorithms In Context #10: Disjoint Sets
...
5
votes
1
answer
123
views
Locate and multiply numbers in a 2D grid (Advent of Code 2023 Day 3, Part 2)
I am using the Advent of Code 2023 to study functional programming and the ranges library in C++. This code is for the second part of Day 3 and is the best solution using FB I've created. I'd ...
6
votes
2
answers
717
views
Making a Rock Paper Scissors game in Python - How to reduce repetition and make it more effective?
I am a "new" coder to Python - saying this because I got stuck in the tutorial hell - and I saw that doing projects was a way of consolidating what I had learnt from those tutorials, so here ...
1
vote
0
answers
22
views
Determine top t values with few calls to order(), a given procedure to order k values, Java take 2
My 2nd take of the problem in Determine top t values with few calls to order(), a given procedure to order k values:
Given an array and a procedure to order \$k\$ ...
0
votes
2
answers
119
views
Advent of Code 2023 - Day 19: Aplenty (Part 1)
Description:
The task involves processing a set of workflows, each comprising rules. These rules define conditions based on part ratings and dictate the destination workflow if the conditions are ...
4
votes
2
answers
118
views
Delete a node in binary tree
Problem Statement
Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.
Basically, the deletion ...
4
votes
1
answer
170
views
Roman numerals look and say sequence
I was practicing question 1 of the 2020 british informatics olympiad past paper:
The Roman look-and-say description of a string (of Is, Vs, Xs, Ls, Cs, Ds and Ms) is made by taking each
block of ...
0
votes
2
answers
74
views
Advent of Code 2023 - Day 15: Lens Library
Part 1:
The task involves initializing the Lava Production Facility using an
initialization sequence. The sequence consists of steps, each requiring the
application of the Holiday ASCII String Helper ...