discrete-mathematics Questions
10
Solved
How can I get the number of "1"s in the binary representation of a number without actually converting and counting ?
e.g.
def number_of_ones(n):
# do something
# I want to MAKE this FASTER (co...
Ladida asked 9/5, 2009 at 18:54
11
I don't understand the following definition of a contiguous subsequence:
A contiguous subsequence of a list S is a subsequence made up of consecutive elements of S.
If S is {5, 15, -30, 10, -5, 40...
Frady asked 21/10, 2010 at 14:33
5
The x-derivative Sobel looks that way:
-1 0 +1
-2 0 +2
-1 0 +1
Lets say there are two samples of my image which look like that (0=black, 1=white):
0 0 1 1 0 0
0 0 1 & 1 0 0
0 0 1 1 0 0
I...
Raleighraley asked 9/4, 2013 at 2:6
8
Solved
I'm trying to write a piece of code that can automatically factor an expression. For example,
if I have two lists [1,2,3,4] and [2,3,5], the code should be able to find the common elements in the ...
Camus asked 5/7, 2012 at 16:9
15
Solved
Multiplying two binary numbers takes n^2 time, yet squaring a number can be done more efficiently somehow. (with n being the number of bits) How could that be?
Or is it not possible? This is insan...
Remington asked 4/9, 2009 at 5:48
10
Solved
Given n nodes, if every node is connected to every other node (except itself) the number of connections will be n*(n-1)/2
How does one prove this ?
This is not a homework question. I have been aw...
Primogeniture asked 5/12, 2012 at 19:3
5
Solved
My problem is to compute (g^x) mod p quickly in JavaScript, where ^ is exponentiation, mod is the modulo operation. All inputs are nonnegative integers, x has about 256 bits, and p is a prime numbe...
Jolie asked 20/9, 2009 at 8:48
0
In this question, we consider how to pack a collection of polyominos into a rectangle of a fixed size.
In my case, I'm concerned with the special case where all polyominos are rectangles and while ...
Flyn asked 17/4, 2022 at 7:0
4
Solved
I'm looking at the entry Find the log base 2 of an N-bit integer in O(lg(N)) operations with multiply and lookup from Bit Twiddling hacks.
I can easily see how the second algorithm in that entr...
Approve asked 9/9, 2011 at 17:57
3
Solved
I've coded this but this is very long:
for i in range(n + 1):
for j in range(n + 1):
for k in range(n + 1):
if i + j + k == n:
Is there a clever way to make it go faster? Currently it's O(n^3) ...
Stamen asked 24/1, 2022 at 21:22
3
Solved
Code:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10000)
plt.plot(x, np.tan(x))
plt.show()
Expected result:
The result I get:
Crucial asked 3/2, 2019 at 18:2
7
Solved
I am facing a rather peculiar problem. I am working on a compiler for an architecture that doesn't support bitwise operations. However, it handles signed 16-bit integer arithmetics and I was wonder...
Cristobal asked 6/6, 2010 at 1:3
6
Solved
How can I sum the following sequence:
⌊n/1⌋ + ⌊n/2⌋ + ⌊n/3⌋ + ... + ⌊n/n⌋
This is simply O(n) solution on C++:
#include <iostream>
int main()
{
int n;
std::cin>>n;
unsigned long ...
Miterwort asked 4/1, 2015 at 18:4
5
Solved
I haven't yet found a good answer. Or any answer, for that matter. I've been asked to teach a discrete structures for CS course, but at the same time make sure it's not a discrete mathematics...
Stanleystanly asked 14/4, 2009 at 18:38
2
Solved
Understanding why Floyd's tortoise and hare algorithm works when applied to an array of integers
I was trying to solve this leetcode problem https://leetcode.com/problems/find-the-duplicate-number/ using my own implementation of the tortoise and hare algorithm which resulted in an infinite loo...
Intersexual asked 27/10, 2020 at 19:11
4
Solved
By rotating 2 lists either from left to right, Find the smallest possible sum of the absolute value of the differences between each corresponding item in the two lists given they're the same length...
Brahmanism asked 20/10, 2020 at 0:31
2
Solved
I have an integer array of length N containing the values 0, 1, 2, .... (N-1), representing a permutation of integer indexes.
What's the most efficient way to determine if the permutation has odd o...
Malarkey asked 1/8, 2020 at 16:44
7
Solved
We have a machine with O(1) memory and we want to pass n numbers (one by one) in the first pass, and then we exclude the two numbers and we will pass n-2 numbers to the machine.
write an algorithm...
Sabadilla asked 18/4, 2012 at 22:8
3
Solved
Good night. I'm a Math bachelor and I'm studying log() and series. And I do want to see how GCC compute all those stuffs, it will help me a lot, there's nothing inside math.h I alread read it. I cr...
Volva asked 10/4, 2020 at 3:43
2
Solved
The question is:
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. Link to the question
Example
Given n = 12, return ...
Varletry asked 18/7, 2017 at 9:57
11
Solved
I am trying to solve a bigger problem, and I think that an important part of the program is spent on inefficient computations.
I need to compute for a given number N, the interval [P, Q], where P ...
Rapparee asked 20/10, 2011 at 22:31
2
I am in a Discrete Math course and am trying to replicate De Morgan's law of
Complement(B union C) = Complement(B) intersect Complement(C).
I tried searching for Python's ability to perform a...
Zinn asked 15/5, 2018 at 20:6
10
Solved
I use the following function to calculate log base 2 for integers:
public static int log2(int n){
if(n <= 0) throw new IllegalArgumentException();
return 31 - Integer.numberOfLeadingZeros(n);...
Brosy asked 22/7, 2010 at 1:3
2
Solved
Suppose I have a Python list of arbitrary length k. Now, suppose I would like a random sample of n , (where n <= k!) distinct permutations of that list. I was tempted to try:
import random
impo...
Fifine asked 5/1, 2019 at 8:29
1
Solved
I am trying to find a pattern to convert Sketch shape points(json format) to svg path, as we know sketch files are just zip files, unzipping you will get json files.
here are sample json codes
{...
Interlineate asked 26/11, 2018 at 11:47
1 Next >
© 2022 - 2025 — McMap. All rights reserved.