find divisors of a number using while loops [closed] - while-loop

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 5 years ago.
Improve this question
I am new to coding and I would like some assistance with how to find the divisors of a number (I would like to add them all together and return the result). Ive seen some examples in different post, but they used for loops. I only know, and can only use, while loops.
anything helps.

You can use while loop to find positive divisors of a number in the following way:
def find_divisors(n):
if n==0:
return []
if n<0:
n=-n
divisors=[]
i=n
while(i):
if n%i==0:
divisors.append(i)
i=i-1
return divisors

Related

A newbie in SQL asking about functions [closed]

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 6 months ago.
Improve this question
How can I find data that dont end with letter 'g' without using NOT LIKE function, please help
select * from table where right(column, 1) != 'g'
Since you asked how to do it using "not like," I'll answer that. The function version provided by #Zoories would be more efficient.
This works at w3schools.com
SELECT * FROM Customers where CustomerName not like '%g';

How do i find difference of two columns in SQL [closed]

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 2 years ago.
Improve this question
I want to find if the difference between 2 columns. How do I achieve that?
For example,
select(col1-col2) output is 1
select(col2-col1) output is -1
Is there a way to get just the difference as 1 without the negative (-) sign?
use abs() function
select abs(col2-col1) as diff

regular expression for double consonants [closed]

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 1 year ago.
Improve this question
I have a problem writing regular expression. I want to write a regular expression that replaces all double consonants with a single consonant.
Please help me to write such a rule in only one line.
Thanks in advance.
Here's a .NET regex that'll find any group of exactly two non-vowels:
[^aeiou]{2}
The following will work for groups longer than 2:
[^aeiou]{2,}
For example, this will match "llst" in "allstar."
Slightly uglier, but will match groups of 2 consonants, case-insensitive:
[QqWwRrTtYyPpSsDdFfGgHhJjKkLlZzXxCcVvBbNnMM]{2}
The following will match two identical non-vowels:
([^aeiou])\1
For example, this would match the "ll" in "all."
Once you have your regex, just use your chosen language's Regex.Replace function.
Since you did not specify the language, I'm going to go ahead and assume Javascript.
This should get you started:
console.log('babble bubble http htttp www'.replace(/([^aeiou\.,\/=?:\d&\s!##$%^*();\\|<>"'_+-])\1{1}/gi, "$1"));
See more here:
http://regexr.com/3ee47

awk colum or grep for multiple IP ranges in a file [closed]

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 9 years ago.
Improve this question
I have a rather large file and one of the columns is a list of various IP addresses. I have multiple IP ranges I need to print from this file. What's the best way to pull only these ranges. Can it be done in a single statement? For example:
10.0.0.0/8
10.102.175.0/28
10.102.231.0/24
10.102.79.0/24
10.102.93.0/30
10.103.141.0/30
10.103.141.0/32
10.103.154.0/26
10.104.152.0/27
10.105.25.0/26
10.107.64.0/24
10.111.130.0/26
10.111.147.0/24
10.111.148.0/24
10.111.149.0/24
10.111.150.0/24
10.27.28.0/24
172.16.208.0/29
172.26.92.0/23
192.1.53.0/24
192.168.16.0/30
192.168.55.0/30
192.200.9.0/24
grepcidr seems to do what I need.
try GNU ERE Regex:
(19[01]|1[0-8][0-9]|[1-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])|0\.((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])|0\.((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])|0\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[89])))|192\.((1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])|200\.([0-8]\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])|9\.0))
It's a single statement (one-liner).

Convert fraction to decimal [closed]

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 9 years ago.
Improve this question
Working on 10g.
I am writing a query to sort a list, and sorting is an important aspect of the list.
I have already isolated the fraction from the mixed number.
I have data that come in fraction form. (3/4, 5/8, 1/2)
I need to convert them to decimal to be able to 'order by' with them.
Any help would be appreciated.
This will blow up badly if the input is not a fraction such as 3/4, 5/8, etc., but here goes:
CAST(SUBSTR(theFraction, 1, INSTR(theFraction, '/')-1) AS NUMBER) /
CAST(SUBSTR(theFraction, INSTR(theFraction, '/')+1) AS NUMBER)
The logic is basically "get everything before the '/' and convert it to a number, then divide it by everything after the '/' converted as a number".