I'm having trouble finding a transformation that adheres to the following criteria:
The 3 input numbers can be negative, positive, or 0
The scale is unknown for a single trio of numbers, however, I could scan through the data to find the min and max values for the entire data-set, if that helps.
The 3 output numbers must be between 0 and 100 (inclusive) and sum up to 150, with 50 being the 'new zero'. So for 3 input numbers of 0, 0, 0, the output would be 50, 50, 50. Negative numbers would end up below 50 (but >= 0), and positive numbers would end up above 50 (but <= 100).
Here are two real examples of input numbers:
-19, 253, -267
-479, 137, -179
Your help would be appreciated.
Related
I have the following vector a:
a<-c(100, 84, 126, 336, 544, 0, 2176)
I want to subset a using the following index vector `b:
b<-c(1,2,4,5,7)
In this case, the subset would be:
a[b]=c(100,84,336,544,3276)
From this subset of a I want to take the smallest three numbers. I then want to know what indexes of a these smallest three numbers are.
The smallest 3 numbers in this subset would be:
c(84,100,336)
So the indexes of these numbers in a would be:
result<-c(2,1,4)
How can I get to this final result?
If efficiency is not important:
match(sort(a[b])[1:3], a)
# [1] 2 1 4
A bit faster:
match(sort(a[b], partial = 1:3)[1:3], a)
A bit cleaner:
intersect(order(a), b)[1:3]
I have a list of numbers a1, a2, a3, a4, a5, ... and so on. If we find XOR of all subsets then I noticed that frequency of each distinct XOR is the same.
Example 1
# list of numbers
[2, 0, 9]
# XOR of all subsets including empty set
XOR of () = 0
XOR of (2,) = 2
XOR of (0,) = 0
XOR of (9,) = 9
XOR of (2, 0) = 2
XOR of (2, 9) = 11
XOR of (0, 9) = 9
XOR of (2, 0, 9) = 11
# Frequency of each XOR value
{0: 2, 2: 2, 9: 2, 11: 2}
In the above example, we can see that XOR values 0, 2, 9, 11 have the same frequency that is 2
Example 2
It doesn't matter what is the size of the list, whether elements are repeated or not, the property seems to hold
# list of numbers
[2, 0, 9, 9, 9, 45, 1, 2, 1, 1]
# skipping showing the subsets
# Frequency of each XOR value
{0: 64,
2: 64,
9: 64,
45: 64,
1: 64,
11: 64,
47: 64,
3: 64,
36: 64,
8: 64,
44: 64,
38: 64,
10: 64,
46: 64,
37: 64,
39: 64}
First of all, I am not sure whether it will always hold. I have tested it for quite a few numbers of examples and it seems to work for all of them. There are a lot of XOR questions asked on StackOverflow but I didn't find anything related to this question.
Can someone please help with the following?
Whether this property will always hold?
If no, can you share 1 example?
If yes, can you please answer why?
Assuming you know about the linear combination of basis elements.,
Let ai1,ai2,ai3,....aik be the basis elements for the given array.
We get 2k unique xor values by spanning above set.
Let that set be X = { x1,x2,.......x2k }
Now coming to remaining (n-k) non basis elements,
There are 2(n-k) subsets among them.
let the set of xor of each subsets be D = { d1,d2,....d2n-k }
Note: ∀di∈X
proof:
We know that, Each di is xor of(linear combination of) some subset of non basis elements, and a non basis elements itself linearly representable using basis elements.(ie:can be formed by xor-ing some subset of basis elements).
Therefore, each di is linearly representable with basis element, thus it belongs to set X.
Now coming to the original question, let A be given array.
Then set of subset of A = X×D.
Because X is set of subset of some k distinct element of array, and D is set of subset of remaining n-k elements., So merging them with all combinations gives set of subset of original array
Claim: ∀i, Li=di⊕X produces the same set, actually the set X itself, but just in different order.
proof:
For any two different integer p,q : we have p⊕u≠q⊕u
Since all x1,x2...... are distinct.
Here di is similar to u in above equation.
so Li = di⊕X = di⊕{x1,x2,......} produces a another unique set of numbers.
ie: lij ≠ lik for j≠k
Now we are left with proving that each Li is X itself.
proof:
The value of Each lij∈Li cannot have any new value apart that span of basis, as lij = di⊕xj, here what we did is only linear combination within basis.
So all lij still belongs to span of basis(and distinct). so, the Li is X.
Now the size of D is 2^(n-k), and ∀i, di×X = X
hence the same set of xor values in X is repeated 2^(n-k) times.
ie: each element in X (span of basis elements) is repeated 2^(n-k) times.
Where k is number of basis elements.
I am trying to find out the numbers between 1 and 1,000 that the sum of their digits is equal to 3. I am just looking for any formula that can help me calculate this. For e.g. 111, or 12 equals to 3, the ones, tens, and hundreds added up together will equal 3.
any help will be appreciated.
think of all numbers having 3 digits: 001 and 002
We can start to iterate on this quickly. You cannot have a number in that sequence greater than 3.
So immediately we rule out all numbers >= 400
We can also rule out,within each group of hundred, any number that is greater than ?40 (eg 140 340)
Then we can start to just press into the numbers a bit.
We only have to dig into ?01 - ?39 for 0, 1, 2 and 3.
Start with 00?. We know that there is only one number works here : 0 + 0 + x =3 solve : 003
So we have 0, moving up to the next set of 10 : 01? we know there is only one number that will work. 012.
We have logic, each leading two digit combination leads to only one solution. We know we only have 0?? 1?? 2?? and 3?? for the leading digit. We have ?0? ?1? ?2? and ?3? for the second digit.
We can be comfortable listing : 3, 12, 21, 30, 102, 111, 120, x13?, 201, 210, x22?, 300
If you don't want to use math, use python:
a=[]
for x in range(10):
for y in range(10):
for z in range(10):
if x+y+z==3:
a.append('%r%r%r'%(x,y,z))
a = ['003','012','021','030','102','111','120','201','210','300]
Write a program that reads a series of numbers, ending with 0, and then tells you how
many numbers you have keyed in (other than the last 0). For example, if you keyed in
the numbers 5, -10, 50, 22, -945, 12, 0 it would output ‘You have entered 6 numbers.’.
doing my homework and can get this one to work
what stumps me is i understand adding the numbers to get the sum total but what do i call the number of numbers ...
thanks
Python has a very simple function that could be used here, string.count(). Given each number is separated by a comma, you can count the amount of commas to get the amount of numbers (not including the 0, which doesn't have a comma after it). An example of this in use would be
input = 5, -10, 50, 22, -945, 12, 0
Number_of_Numbers = input.count(',')
I'm trying to store a counter that can become very large (well over 32 and probably 64-bit limits), but rather than use a single integer, I'd like to store it as an array of counters for each digit. This should be pretty language-agnostic.
In this form, 0 would be [1, 0, 0, 0, 0, 0, 0, 0, 0, 0] (one zero, none of the other digits up to 9). 1 would be [0, 1, 0, ...] and so on. 10 would therefore be [1, 1, 0, ...].
I can't come with a way to keep track of which digits should be decremented (moving from 29 to 30, for example) and how those should be moved. I suspect that it can't be done without another counter, either a single value representing the last cell touched, or an array of 10 more counters to flag when each digit should be touched.
Is it possible to represent a number in this fashion and count up without using a simple integer value?
No, this representation by itself would be useless because it fails to encode digit position, leading to many numbers having the same representation (e.g. 121 and 211).
Either use a bignum library, or 80-bits worth of raw binary (that being sufficient to store your declared range of 10e23)