This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Code Golf - Banner Generation
Post your shortest code to convert a number into a ASCII art digits.
Input - Assume that an integer variable called z has already been set containing the number.
Output - Print the output to the console.
Quality - The lower number of characters, the better.
Formatting - Flexible, providing it is ASCII art and looks like a number. There must also be some spacing between digits.
Test input: 365
GGGGGGGGGGG....GGGGGGGGGGGG...GGGGGGGGGGG
..........G....G..............G..........
..........G....G..............G..........
..GGGGGGGGG....GGGGGGGGGGGG...GGGGGGGGGGG
..........G....G..........G.............G
..........G....G..........G.............G
GGGGGGGGGGG....GGGGGGGGGGGG...GGGGGGGGGGG
Python: 173 characters
for i in range(5):
a=""
for j in str(z):
y=int("03330222220201002020330220102001030022220303003020"[int(j)*5+i])*8
a+="."+("#"*9+"."*14+"##"+"."*6+"#")[y:y+8]
print a
Bash: 9 characters
figlet $z
;)
Ruby - 139 chars
(0..4).map{|i|puts z.to_s.chars.map{|j|(?#*9+?.*14+'##'+?.*6+?#)[(?0+"ubp9x453o9jzme0cs08".to_i(36).to_s(4))[j.to_i*5+i].to_i*8,8]+' '}*''}
Output for z = 365
> asciinum.rb
######## ######## ########
.......# #....... #.......
######## ######## ########
.......# #......# .......#
######## ######## ########
Related
This question already has answers here:
Understanding slicing
(38 answers)
Closed 1 year ago.
def add_binary(a,b):
return bin(a+b)[2:]
Why is "[2:]" used here?
convert number into it's binary and remove first two characters 0b.
Example:
Original number: 10
Binary string: 0b1010
after that it will be 1010 only.
If i have a string like "123123123" - Here 123 is repeated 3 times.
1. So how can i get only "123" in ruby?
2. So if the string is "12312312" - Here 123 is repeated 2 times and then just 12, so here still i need to get "123".
3. Even if string is 99123123123, still i need to get 123.
Is this possible in Ruby Regex?
EDIT: I want this to solve Project Euler Problem 26 . So here 123 can be anything. All i want is to extract 1 number of at-least 2 repeated numbers.
This regex will detect all repeating groups.
(\d+)(?=.*\1)
Demo
Works great with ruby too.
result = '9912341234123'.scan(/(\d+)(?=.*\1)/)
#gets group with largest length
longestRepeatingGroup = result.max_by{|arr| arr[0].length}
puts longestRepeatingGroup
puts longestRepeatingGroup[0].length
Try this
99123123123.scan(/123/).count
12312312.scan(/123/).count
I am trying to make a program that will read in a number and then output every digit of that number in a list. However, most of the things look fine until I try with number 8 and 9. The program only output \b \t instead.
if the input number contains 8 or 9, and in the same time there are other numbers, for example 283, it will print normally. Otherwise if there is only 8 or 9, such as8, 99, then it will give me that binary representation of 8 and 9 (if I remember correctly).
My program is as below:
digitize(0)-> 0;
digitize(N) when N < 10 -> [N];
digitize(N) when N >= 10 -> digitize(N div 10)++[N rem 10].
The function returns the expected list, but the shell shows lists of numbers which are ASCII-codes of characters as strings (because that's just what strings are in Erlang; there's no special string type). You can see it by just entering [8, 8] (e.g.) at the prompt and disable this behavior by calling shell:strings(false) (and shell:strings(true) when you need the normal behavior again).
Strings in Erlang are no separate type but a list of numbers. List printing has a heuristic to detect when it might be a string. If it thinks it's a string it will be printed as such. \b is the backspace character and \t is the tab character which are ASCII codes 8 and 9
See also:
Description what a string means
Erlang escape sequences
Explanation of this in LYSE
I want to check whether the given string includes "test_icon_<integer>". the integer could be 10 or 22 or 32 or 109 or 120.( first integer can't be zero but second and third digits can be zero)
Following strings are not accepted
1."test_icon_<1a>"
2."test_icon_<1.1>"
3. "test_icon_<!#q>"
4. "test_icon_<abced>"
Please help me to solve this.
This regex matches your strings and fails on the bad ones:
test_icon_<[1-9]\d{0,2}>
see demo.
Explain Regex
test_icon_< # 'test_icon_<'
[1-9] # any character of: '1' to '9'
\d{0,2} # digits (0-9) (between 0 and 2 times
# (matching the most amount possible))
> # '>'
This should work for you:
test_icon_<((?!0)\d)\d{0,2}>
Demo with explanation
Following regex should solve your problem:
/test_icon_\<[0-9]+\>/
Hope this helps :)
This question already has an answer here:
Regular expression for password complexity
(1 answer)
Closed 8 years ago.
I'm trying to have the following rules for NSString validation using regular expression:
8 characters minimum length
at least 1 digit
at least 1 uppercase
at least 1 lowercase
I'm only able to do the following to get the first rule like this:
^[a-zA-Z0-9]{8,}$
Which if i understand correctly check for minimum 8 characters length with lower/uppercase and digit
Thank you
Use a lookahead for each assertion:
(?=.*\d)(?=.*[A-Z])(?=.*[a-z])^.{8,}$