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
I would like to validate master card for New series The BIN range (222100-272099). currently I have Regular expression for existing mastercard series...5[1-5][0-9]{14}
Edit : based on the comment of Kul-Tigin
When working with numbers this may be easier :
Title = "Valid card number or not"
Do
CardNumber = InputBox("Please type your card number ",Title,"222100")
If IsValidcard(CardNumber) = True Then
MsgBox CardNumber & " The Card number is valid !",64,Title
Else
MsgBox CardNumber & " The Card number is not valid !",16,Title
End if
Loop Until CardNumber = ""
'**********************************************************************
Function IsValidCard(Num)
IsValidCard = False
Set regEx = New RegExp
regEx.Pattern = "^\d{6}$"
If regEx.Test(Num) then
x = CDbl(num)
if x >= 222100 AND x <= 272099 Then
IsValidCard = True
Else
'not in range
End If
Else
'not 6 digits
end if
End Function
'**********************************************************************
Related
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 4 years ago.
Improve this question
Please output the number obtained by adding a and b.
At the end of the line break, do not include extra characters, blank lines.
expmple1
1 1
result1
2
expmple2
0 99
result2
99
My code is:
input_lines = gets.chop
a = input_lines[0]
b = input_lines[1]
puts a + b
But it's not working, please help.
Add split to the chopped gets would work:
input_lines = gets.chop.split
a = input_lines[0].to_i
b = input_lines[1].to_i
puts a + b
Try it.
Check String doc.
More DRY way to do it:
input_lines = gets.chop.split.map(&:to_i)
a,b = input_lines
puts a + b
In this case the numbers inside input_lines already changed to Integers.
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 5 years ago.
Improve this question
I want to make this simple program that returns the weight quantity by choosing the units. When I run the program it runs with no problems and asks the two questions in if but doesn't return the value
Here is my code:
puts "What is your starting weight and ratio unit?
1:kg.m/h
2:gm.m/s
3:mm.m/s"
inputing_unit = gets.chomp
puts "What is your ending weight and ratio unit?
1:kg.m/h
2:gm.m/s
3:mm.m/s"
ending_unit = gets.chomp
if inputing_unit == 1 and ending_unit == 1 then
puts "What is your weight?"
input_weight = gets.chomp.to_i
puts "What is your ratio?"
input_ratio = gets.chomp.to_i
puts "Your moving value is #{input weight * input_ratio}"
end
As I can see from that screenshot in the beginning of the description on pre-last line where is your puts statement there is a typo #{input weight * input_ratio}. You should change ...#{input weight... to ...#{input_weight... (with a dash).
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 7 years ago.
Improve this question
I'm trying to do a binary search on a list of 1 million employee IDs, already sorted out.
def exist?(id)
lower = -1
upper = $employee_list.count
while true
mid = (lower + upper) / 2
if upper == lower + 1
return nil
if id == $employee_list[mid]
return mid
if id < $employee_list[mid]
upper = mid
else
lower = mid
end
end
end
end
end
I get the error:
NoMethodError:undefined method 'call' for nil:NilClass
Also, I'm trying to make it such that if exist?(54) is in the list, it will return true.
Just use Array#bsearch:
$employee_list.bsearch { |employee| id <=> employee }
As for the error - it comes from somewhere else.
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 7 years ago.
Improve this question
I'm trying to do a simple math operation, but I'm stuck.
Ask user to introduce an amount of money:
puts "Capital to deposit"
capital = gets.chomp
Ask user to introduce a fixed number of days:
puts "Indicate days of deposit"
deposit_time = gets.chomp
I made the following array with the only possible answers for step #2:
deposit_time = [30, 45, 60]
I need a multiplication operation that depends on what the user chooses in step #2. For instance, let's suppose the user chooses 30. I would need the code to read:
capital = 10
deposit_time = 30
to multiply 10 * 1.0219 and print the resulting number: 10.219. Any ideas?
Use a hash, not an array.
deposit_rates = { 30 => 1.0219, 45 => 1.0336, 60 => 1.0467 }
deposit_time = gets.to_i
deposit_rate = deposit_rates[deposit_time]
# will be `nil` if not one of the defined ones
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 need to sort the numeric data in a row/column while leaving space of missing values at scale of 1-5.
Like:
A B
13245 1_2_3_4_5
152.... 1_2_ _ _5
Try this UDF:
Function ModSort(Str As String) As String
Res = ""
For Iter = 1 To 5
If InStr(1, Str, CStr(Iter)) Then
Hold = CStr(Iter) & "_"
Else
Hold = " _"
End If
Res = Res & Hold
Next Iter
Res = Left(Res, 9)
ModSort = Res
End Function
Screenshot:
Let us know if this helps.
Not meant as a serious answer (UDF seems good enough) but appears possible with a formula:
=IF(LEN(SUBSTITUTE(A2,1,""))<LEN(A2),"1_"," _")
&IF(LEN(SUBSTITUTE(A2,2,""))<LEN(A2),"2_"," _")
&IF(LEN(SUBSTITUTE(A2,3,""))<LEN(A2),"3_"," _")
&IF(LEN(SUBSTITUTE(A2,4,""))<LEN(A2),"4_"," _")
&IF(LEN(SUBSTITUTE(A2,5,""))<LEN(A2),"5",)