Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Considering using the characters (elements) a-z and 0-9 how many different permutations are there when using a string of length 32?
The elements can be used more than once, but the results have to be unique (as is the case with a permutation).
I've looked at WolframAlpha however that doesn't state how many 'elements' that would be used, it only considers the length.
You have 32 positions for either 10 different digits or 26 characters. In each position either goes a character or a digit so you have 36 possibilities. This leave us with:
36*36*36...*36 (32 times)
= 36^32
= 63340286662973277706162286946811886609896461828096 # (thanks Python ;) )
The answer is (26+10)^32 = 6.3340287e+49
Well, it depends on if you're allowed to have replacement or not.
If you are allowed replacement, you have 36 possibilities for each character position = 36^32.
If you're not allowed replacement, you have 36 for the first, 35 for the second, etc, until you run out of character positions. That's 36! / 4!, also written as 36 P 32.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
This post was edited and submitted for review 7 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
Why not 4 bits, or 16 bits?
I assume some hardware-related reasons and I'd like to know how 8bit 1byte became the standard.
I'ts been a minute since I took computer organization, but the relevant wiki on 'Byte' gives some context.
The byte was originally the smallest number of bits that could hold a single character (I assume standard ASCII). We still use ASCII standard, so 8 bits per character is still relevant. This sentence, for instance, is 41 bytes. That's easily countable and practical for our purposes.
If we had only 4 bits, there would only be 16 (2^4) possible characters, unless we used 2 bytes to represent a single character, which is more inefficient computationally. If we had 16 bits in a byte, we would have a whole lot more 'dead space' in our instruction set, we would allow 65,536 (2^16) possible characters, which would make computers run less efficiently when performing byte-level instructions, especially since our character set is much smaller.
Additionally, a byte can represent 2 nibbles. Each nibble is 4 bits, which is the smallest number of bits that can encode any numeric digit from 0 to 9 (10 different digits).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
On what language is more easy to code that kind of algorithm and make it more flexible to changes.
It's pretty easy to do, at least in widely used programming languages that I'm aware of (e.g. C++, Java, etc).
Store all possible characters in an ordered collection like array or a string. For example, you can make a string that contains all letters and digits like so:
// Exact syntax depends on your programming language.
//
// I used a string for simplicity here but some languages don't allow
// you to access individual string characters so you'll need an array.
//
string a = "abcdefghijklmnopqrstuvwxyz0123456789";
Generate a random number between 0 and length(a) - 1 (size of your character set array minus one).
Use the number you generated as an index and extract the character from the array at that index.
Congratulations! You've just generated one random character from your character set. Go back to step #2 and repeat N - 1 times (N is here the total number of characters you want to generate).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
So I Heard that one character is a byte. But then I went to a website which measures text capacity,(Making website) and I typed in a 1. It showed on the byte count 1 byte. 8 bits = 1 byte, right? I thought 8 binary digits made 1 character. How can a 1 be a byte and a bit at the same time?
These days, the number of bits per character is not so simple but there are most definitely 8 bits per byte.
The number of bits/bytes per character will vary depending on your system and the character set.
Original ASCII was 7bits per character.
That was extended to 8bits per character and stayed there for a very long time.
These days, with Unicode, you have variants that are 8, 16 and 32 bits (1, 2 and 4 bytes) wide. Were the 8 bit variety corresponds to ASCII.
The character 1 is represented by binary 00110001b which is 8 bits thus 1byte. The actual binary number 1b would be at a minimum 00000001b which represents a special character not the character 1.
Hopefully this helps.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a list of keywords call it [cat, dog, bird] and a regex to find a weight (\dlbs).
I only want to find items that
start with the items in the array
(cat|dog|bird?)
match the weight regex
(\dlbs)
only have a max of 30 characters (excluding whitespace) between 1. and 2.
do not want to or care to capture the 1-30 characters
Any help appreciated!
This will do it:
(cat|dog|bird)\s*(?:(?:\S\s*){0,30})(\dlbs)
Debuggex Demo
Edited to reflect the "excluding whitespace" point.
It matches, for example, each of the following:
The cat weighs almost exactly 7lbs.
The cat weighs almost exactly 7lbs
Note: you appear to have a stray ? in your question in (cat|dog|bird?) - I have ignored it. Also, are you sure you will have \dlbs, not, say, 17 lbs or 17 pounds? You can easily address those scenarios with
(cat|dog|bird)\s*(?:(?:\S\s*){0,30})(\d\s*(?:lb|pound)s)
(\s*.){0,30} Maximum 30 characters excluding white spaces:
(cat|dog|bird)(\s*.){0,30}\s*(\dlbs)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a number that comes from an external API but it has two extra zeros at the end. What would be a solution to remove the two zeros. I have tried the chomp method and that doesn't work. The number I receive from the API is a Bignum. I am using Ruby 2.
This is a sample input from the API is 1374577200000
This is a sample output I want is 13745772000
If the number is an integer, you can use integer division:
> 123456 / 100
=> 1234
You can't chomp a Fixnum or Bignum, so you'd have to convert it back and forth:
number = 123400
number.to_s[0..-3].to_i