math

How can I convert an RGB input into a decimal color code?

一个人想着一个人 提交于 2020-02-05 07:07:25
问题 Say I have an rgb color code with values 255 for red, 255 for green and 0 for blue. How can I get the decimal color code from those numbers, using only mathematical operations? So my setup, in pseudo-code, would look like: int r = 255; int g = 255; int b = 0; int result = /*decimal color code for yellow*/ Please help, I have spent ages trying to find an answer already and would love a simple quick answer :) 回答1: int result = (r * 256 * 256) + (g * 256) + b Or, if your language has a bit shift

How can I convert an RGB input into a decimal color code?

不想你离开。 提交于 2020-02-05 07:07:24
问题 Say I have an rgb color code with values 255 for red, 255 for green and 0 for blue. How can I get the decimal color code from those numbers, using only mathematical operations? So my setup, in pseudo-code, would look like: int r = 255; int g = 255; int b = 0; int result = /*decimal color code for yellow*/ Please help, I have spent ages trying to find an answer already and would love a simple quick answer :) 回答1: int result = (r * 256 * 256) + (g * 256) + b Or, if your language has a bit shift

C++, not in order combination of array elements

≯℡__Kan透↙ 提交于 2020-02-05 03:31:07
问题 I am trying to get all combinations of an array with C++ such that double* list1 = new double[size]; Items in that array is {1,2,3,4,5} I need to add all possible combinations into a stack, such as: 1+2, 1+2+3, 1+2+3+4,1+2+3+4+5, 1+3, 1+3+4, 1+3+4+5, 1+4, 1+4+5, 1+5... the problem I am running into is I am doing this through 2 for loops and a while loop for(int i = 0; i < size - 1; i++) { for(int j = i; j < size - 1; j++) { double temp = list1[i] + list1[j + 1]; list1combos.push(temp); int k

How to get nth permutation when repetition is allowed?

北城以北 提交于 2020-02-03 23:31:20
问题 Project Euler 24: What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9? What if repetitions are allowed? like 1111111111 , 1223344457 etc. How can I get millionth permutation where repetitions are also included in counting. And please note that input would still be the same. No repetitions in input. I want to generate all possible passwords of length 10. And passwords can contain repeated characters so I want my function to work for that too. Here is

Midpoint thick ellipse drawing algorithm

本小妞迷上赌 提交于 2020-02-03 04:46:06
问题 I'm really close to getting a thick ellipse algorithm working but I'm having a bit of trouble. I've taken the midpoint thick circle algorithm from here, and the midpoint ellipse algorithm from here, and I'm trying to combine them together to get the midpoint thick ellipse algorithm. I'm doing this because Googling "midpoint thick ellipse algorithm" didn't show what I'm looking for. The output from my attempt resembles a thick circle (images are at the bottom of the post). This is the image

Reverse Percentage Lookup

人盡茶涼 提交于 2020-02-02 16:27:30
问题 This must be a simple question but I can't work it out! I have a number that I know has been reduced to 70% of its original size, how do I find the original number? For example I have the number 9.1, which is 13 x 70%, but what is the calculation for finding 13? 回答1: You want originalNumber = reducedNumber / (percentage / 100); for example 13 = 9.1 / (70 / 100) 回答2: Well if you have some number x , you're looking for a y so that y * 70% = x y * 70/100 = x y = 100 * x / 70 回答3: Taking your

TypeError: 'int' object is not subscriptable {Python}

你说的曾经没有我的故事 提交于 2020-01-30 06:36:26
问题 from math import log lliste = [2] bovengrenspriem = eval(input('geef een getal van die je weten wil welke priemgetal het is? ',)) while not type(bovengrenspriem) == int: bovengrenspriem = eval(input('Foute invoer, geef een getal van die je weten wil welke priemgetal het is? ',)) if type(bovengrenspriem) == int: break counter = 2 x = 2 while lliste[-1] < bovengrenspriem or lliste[-1]== bovengrenspriem: liste = [] for i in range (1,counter+1): if counter % i == 0: liste.append(i) if len(liste)

TypeError: 'int' object is not subscriptable {Python}

爷,独闯天下 提交于 2020-01-30 06:34:24
问题 from math import log lliste = [2] bovengrenspriem = eval(input('geef een getal van die je weten wil welke priemgetal het is? ',)) while not type(bovengrenspriem) == int: bovengrenspriem = eval(input('Foute invoer, geef een getal van die je weten wil welke priemgetal het is? ',)) if type(bovengrenspriem) == int: break counter = 2 x = 2 while lliste[-1] < bovengrenspriem or lliste[-1]== bovengrenspriem: liste = [] for i in range (1,counter+1): if counter % i == 0: liste.append(i) if len(liste)

Pygame- make bullet shoot toward cursor direction

自作多情 提交于 2020-01-30 05:45:06
问题 I'm trying to make the bullets in my game shoot toward the direction of my cursor until it hits the window borders. My bullets currently go toward my cursor but stops once it reaches where the cursor was. I noticed that the bullet could reach the border if my cursor were offscreen and so I tried to modify the cursor position used to calculate the movement of my bullet to always be outside of the window via multiplying and adding but I couldn't quite get it working the way I want it to. win =

Pygame- make bullet shoot toward cursor direction

 ̄綄美尐妖づ 提交于 2020-01-30 05:45:05
问题 I'm trying to make the bullets in my game shoot toward the direction of my cursor until it hits the window borders. My bullets currently go toward my cursor but stops once it reaches where the cursor was. I noticed that the bullet could reach the border if my cursor were offscreen and so I tried to modify the cursor position used to calculate the movement of my bullet to always be outside of the window via multiplying and adding but I couldn't quite get it working the way I want it to. win =