Questions tagged [language-agnostic]

Use this tag for PROGRAMMING QUESTIONS that are independent of any particular programming language.

Filter by
Sorted by
Tagged with
1 vote
2 answers
76 views

How to compute mean of two floating-point numbers?

What is the most accurate way to compute mean of two numbers in floating-point arithmetic? Let's consider the most common double precision 64-bit numbers. (a + b) / 2 a / 2 + b / 2 a + (b - a) / 2 ...
fdermishin's user avatar
  • 3,549
-4 votes
0 answers
54 views

Algorithm - Maximize subarray sum so that total doesn't exceed max [closed]

I need to write an algorithm that seems simple but I can't find a way to do it (neither can find any algorithm that already does this). The input is an ordered array of integers and a single integer ...
Rui's user avatar
  • 1
0 votes
2 answers
41 views

How to compress 256^3 unique data points in order. Each data point is a value from 1 to 255

I am trying to compress 256^3 datapoints into a 256 digit or less long string (using only base 10 numbers). I have already tried a few things which I will list below. I have tried to switch between ...
Isaac Lenchus's user avatar
0 votes
0 answers
28 views

Is there a way to write a regex that recognizes overlapping patterns? (any language) [duplicate]

I'm wondering if there is, for example, a way to write a regular expression that matches all of ("a.b", "b.c", "c.d") in the string "a.b.c.d". I can only think ...
Albert Ai's user avatar
0 votes
1 answer
13 views

Is it up to the caller or called to ensure to make sure the arguments exist?

This question should be language agnostic, but for simplicity, I will provide an example in python. Suppose that I have a pandas dataframe with some columns and I have a getter that gets one of the ...
24n8's user avatar
  • 1,936
-2 votes
2 answers
77 views

count number of unique integers from multiple ranges to calculate horizontal coverage of blast result [closed]

When I tried to map/align DNA sequence reads to protein database, I could not find many mapping tools which provide horizontal reference/subject sequence coverage, however blastx/diamond does aligned ...
SWK's user avatar
  • 47
0 votes
1 answer
43 views

Algorithm for allocating whole gold bars amongst thieves by % share of the booty

I have N big gold bars and 1 small gold bar equivalent in weight to some fraction x of a large bar. E.g N = 10 and x = 0.5 then I have 10.5 large bars worth of gold, in 10 large bars and 1 small bar I ...
Greedo's user avatar
  • 4,967
0 votes
0 answers
44 views

Algorithm for most efficient memory write

I have the following problem and need help coming up with an algorithm for it You have value which you must write at a specific address in memory and a counter which starts from 0. The objective is ...
bluehelp8's user avatar
1 vote
6 answers
142 views

How can I replace multiple lines in a string?

I want to replace multiline string as below using sed/awk/perl #------------------------------------------------------------------------------- # supply connections #-----------------------...
santy's user avatar
  • 27
0 votes
0 answers
36 views

Decide when to return high and low in a binary search

In binary we have low and high values upon which we move either left or right. I'm solving questions on binary search and have a confusion on which value to return; low or high. For eg., to find the ...
Karthik's user avatar
  • 31
1 vote
1 answer
86 views

Search for text patterns from a file in another file

I have two text files. "file1.txt" contains a big number of strings of characters and each string has 77 characters. Each string is in its own line and every group of lines makes a block of ...
Noha Kamal's user avatar
0 votes
1 answer
29 views

Packing a specific number of equally sized rectangles on a grid with obstacles most effectively

I'm trying to find an algorithm that can place a specific number of equally sized rectangles in a grid with obstacles. The rectangles should not overlap and the total distance to a given starting ...
Crater Hater's user avatar
2 votes
2 answers
148 views

Algorithm for combining two trees

I'm looking for an algorithm to merge or combine two trees (if possible). While I've tried to search the web in general, as well as Stack Overflow in particular, I haven't been able to find anything ...
Mark Seemann's user avatar
1 vote
0 answers
111 views

How do I integrate an external OpenGL render loop into my application?

If you need specifics, I'm working with Avalonia 11.0.0-rc1.1, though the same advice might apply to other GUI frameworks like Qt. Typically, when working with OpenGL-capable libraries (e.g. CEF), the ...
itzjackyscode's user avatar
1 vote
1 answer
52 views

Remembering Lists in backtracking

I am working on a question that requires me to generate an array that includes all of the difference values. Backtracking naturally seemed to be the method to use here but im having some issues with ...
MrKhonsu's user avatar
0 votes
2 answers
55 views

Algorithm to calculate if bottleneck distance between Nodes s and t in a weighted undirected graph is at most W in O(V+E) time

I am currently working through exercise 9.b) on Page 270 of Jeff Erickson's Algorithms book Consider a path between two vertices s and t in a undirected weighted graph G. The width of this path is ...
user1171376's user avatar
0 votes
0 answers
36 views

How to determine if a email address belongs to a K12 school?

A site I work on disallows using emails from K12 schools (elementary, middle, and high schools) because policy disallows users under age 18. It is a lot of manual moderator work to verify unusual ...
sgfit's user avatar
  • 183
0 votes
1 answer
47 views

Is tail call (including tail recursion) compiler/implementation dependent?

Searching tail recursion on the internet I stumbled on How does compiler know whether the recursion is a tail recursion or not and how does it optimize tail recursion. If I understand correctly then ...
duong_dajgja's user avatar
  • 4,216
0 votes
1 answer
50 views

Why must skip lists hold duplicate elements within the same tower?

I'm learning about skip lists currently, and I'm struggling to understand why a tower holds duplicates of the same element on each level. My intuition tells me that this is redundant and the same ...
Lily-Heather Crawford's user avatar
3 votes
1 answer
109 views

Why does Object provide equals and hash code methods?

Many object-oriented programming languages where something like Object is the root of the type hierarchy provide some default equality and hash code methods; for example: C# System.Object: Equals and ...
Matthew Layton's user avatar
2 votes
1 answer
77 views

Using Map/Dictionary as an alternative to switch case

At the risk of this being an opinion based question, would creating a Map/dictionary where the keys are predicates and the values the action to be made be a good and viable substitute for switch case? ...
Shmuel Greenberger's user avatar
1 vote
3 answers
83 views

Question about volatile keyword in java, csharp. Why do most sources say volatile updates to main memory rather than the shared cache?

Depending on the source I've heard different things. Some say that volatile updates to shared cache, but most others have said it updates to ram(main memory) and is read from ram. Clearly if you ...
omar santaella's user avatar
1 vote
2 answers
84 views

Distance to circumference of circle from any point and angle within the circle

Technically it's a math problem, but I don't understand how to turn it into code. I have the center C of a circle, its radius r, and points A and B within the circle. I need to find the distance AD, ...
TheFurryDevil's user avatar
0 votes
0 answers
25 views

Calendar Scheduling Algorithm

I need an algorithm that can sort multiple assignments of varying length and due dates into a single timetable based on the user's availability. I've cut the user's schedule into 10 minute blocks to ...
Isiah's user avatar
  • 305
1 vote
1 answer
52 views

Can breaking into helper functions help performance?

Recently I was curious about why compilers don't always inline every function. One reason that I thought was interesting after I searched it up was the fact that inlining every function would blow up ...
k huang's user avatar
  • 411
-4 votes
4 answers
109 views

How do I perform pattern replacement in command line in which I find patterns in one vector and replace from same position in other vector?

So say I have two character vector lists in .txt docs, in which one has the patterns to be replaced, and the other has their replacements in the same position. For example: Pattern.txt this is the ...
avery's user avatar
  • 43
1 vote
1 answer
75 views

Is there a fast method to extract bits by index (not just masking)?

I have a certain binary number for example: 11110000 And a mask with exactly 4 bits set: 10101010 Im searching for a fast operation that would return the 4 bits of the input corresponding to the ...
António Leitão's user avatar
4 votes
1 answer
152 views

Order of words in multiple-word variables (and identifiers in general) [closed]

This is a question about variable naming (or naming of identifiers in general). Head-initial (right-branching) languages tend to have postnominal modifiers, while head-final (left-branching) languages ...
Lover of Structure's user avatar
0 votes
1 answer
69 views

Time complexity of the following two programs?

I know that the time complexity of the following code is O(n). n = 10 for x in range(0,n): print("") I also know that the time complexity of the following code is O(n^2): n = 10 for x ...
Yash's user avatar
  • 13
0 votes
2 answers
63 views

variables that are scoped to a call stack

Premise: This is not a question particular to a specific language, but rather a generic programming question to understand if some language out there has this construct, and if not, what are the ...
Giacomo Tagliabue's user avatar
4 votes
2 answers
140 views

Optimal algorithm for encoding data within pre-existing data

Say we have some existing random data, uniformly distributed, that's been written to some medium. Lets also say that the writing of 1 bits is a destructive action, while for 0 bits it is non-...
Dillon Davis's user avatar
  • 6,709
0 votes
1 answer
49 views

Will compiler optimize away called-once functions

I've been reading "Clean Code" by Robert C Martin, and one of the pieces of advice is to use more but smaller functions; i.e. instead of int main(){ // do one thing // ... 10 lines ...
acenturyandabit's user avatar
1 vote
2 answers
448 views

Run Windows application on startup; operative differences between registry, autostart and task scheduler?

Recently, I once again came across the problem of having to run my Windows app on startup and wondered which of the options is the most usual one and causing least trouble long term. Registry Add ...
Baumflaum's user avatar
  • 748
1 vote
0 answers
104 views

When to create a new class in OOP?

I have experience in C programming, with the procedural way to solve problems using code. And I finally decided to learn OOP, since this is vastly used on modern languages. But I have a lot of trouble ...
Henrique Rodrigues's user avatar
0 votes
1 answer
50 views

Restful way to delete a write-protected resource

In my API, resources can be write-protected. Trying to DELETE such a resource will return a 409 (Conflict) response. For users that are allowed to change the protected state of a resource, I want to ...
Cephalopod's user avatar
  • 14.6k
1 vote
2 answers
2k views

What is the most efficient way to sort a stack using a limited set of instructions?

I know an almost identical question as already been asked here, but I do not find the provided answers to be very helpful since the goal of the exercise was not clearly stated in the OP. I have ...
Emperor_Udan's user avatar
3 votes
1 answer
98 views

What do files actually contain, and how are they "read"? What is a "format" and why should I worry about them?

As it becomes ever easier to use computers in general and get into programming in particular, an increasing fraction of beginners seem to lack certain fundamental understanding that was once taken for ...
Karl Knechtel's user avatar
2 votes
1 answer
140 views

Floating point representation of a real number is not unique

I am reading about floating point representation of real numbers. In any real number system with arithmetic base β, a real number x can be represented as x=(0.d1d2 --- dtdt+1---) β X βe (1) where 0≤di≤...
Iti's user avatar
  • 121
0 votes
0 answers
19 views

class object definition - programming jargon:

what's the definition of class object that has more than one version? what's the name of object like that that has a default and than versions with more parameters? say you have it like that: public ...
vlaamseFriet's user avatar
1 vote
1 answer
71 views

Fastest way to iterates through records in file and replace contents on another file

Need suggestions on the fastest way to read from a file containing list of values (~30k lines) and use the values to search and replace contents in another file (~500k lines) in Linux. Currently I am ...
Slug's user avatar
  • 77
0 votes
1 answer
188 views

How to represent n-ary tree in 2D matrix?

I am trying to represent an n-ary tree in an 2D matrix. Not sure how to approach the problem. This would be some sort of hierarchy. I have the root node of the tree Example : Output:
stackUnderflow's user avatar
2 votes
3 answers
104 views

How to get the last 2 characters of a string with last character being A or B and second to the last character being 1-360? (REGEX GREP)

I'm not really using regex in a daily basis and I'm still new to this. For example, I have these strings and this is the format of the strings: APPLE20B50A APPLE30A60B APPLE12B5B APPLE360A360B ...
x2ffer12's user avatar
  • 111
2 votes
7 answers
131 views

sorting by inconsistently formatted elapsed time field ( k8s events by actual time since event )

edited I find myself frequently looking to see if something has stopped happening. To do this, it helps to see events in chronological order... This solution seems to work, but the formatting still ...
Paul Hodges's user avatar
  • 13.5k
0 votes
0 answers
77 views

Bucket prediction given an integer?

If I have a dictionary of integers where the value is an array of two integers sorted, with the two values being the largest value, and the smallest value out of k values present in bucket n, how can ...
nropgrammer's user avatar
2 votes
0 answers
92 views

Getting full blame history all at once for a given file

I'm working on a program that analyzes git blame history over time, starting with the first commit of a given file all the way to HEAD, along a given branch. Currently, the way I'm doing it is: Use ...
Jason C's user avatar
  • 38.8k
1 vote
1 answer
70 views

Modify text file with math expression

I have a file called POSCAR that looks like this. Pt-FCC 3.975 3.975000 0.000000 0.000000 0.000000 3.975000 0.000000 0.000000 0.000000 3.975000 I need to ...
user19619903's user avatar
1 vote
1 answer
163 views

reverse a queue using an empty queue

I have a queue [3,2,1] and I want to reverse it using only enqueue and dequeue functions. My final queue should be [1,2,3]. I cannot declare any local variables. I only have 2 queues one is empty and ...
teewhy's user avatar
  • 15
0 votes
0 answers
117 views

How to use Dijkstra's algorithm to generate an undirected, unweighted graph of a given diameter?

My job is to generate a random undirected, unweighted graph with a given diameter d. What I did already is to generate a random distance matrix D where each element Dij represents the distance between ...
Ambitions's user avatar
  • 2,389
0 votes
3 answers
92 views

exclude words those may or may not end with slash

I am trying to exclude certain words from dictionary file. # cat en.txt test testing access/p batch batch/n batches cross # cat exclude.txt test batch # grep -vf exclude.txt en.txt access/p cross ...
shantanuo's user avatar
  • 31.7k
1 vote
2 answers
406 views

How to map angles from [0..360] to [-180..180]

I'm drawing a blank at the moment. I need to translate back and forth between "signed" and "unsigned" degrees, [-180..180] and [0..360] The simple way to go from [-180..180] to [0.....
iter's user avatar
  • 4,171

1
2 3 4 5
167