ASCII character help!

Hi, I am new to ruby and following some tutorial of “Daniel Carrera”
i already finish this overall tutorial answered the exercise and now
just reviewing the lesson.
here is the exercise that bothering me:
I understand the lesson conditional that (equal, greter than and so
on…)
the “a” > “R” = true

1.Re-arrange these characters in ASCIIbetical order: 2, u, A, 4, w, f,
R, y

here is my answer: I attach the rb file if you want to run it in command
line.

puts “type this:” + “2” + “u”+ “A” + “4” + “w” + “f” + “R” + “y”
asci = gets.chomp.to_s
if asci ==“2uA4wfRy”
else asci != “2uA4wfRy”
puts “retype this:” + “2” + “u”+ “A” + “4” + “w” + “f” + “R” + “y”
asci = gets.chomp.to_s
end until asci == “2uA4wfRy” #recycle if wrong input, I put this for fun
puts “2, 4, A, R, f, u, w, y”

I am not really sure if this is what the question looking for? I think
it is looking for a automated ascii alphabetically (you know the math
thing).

2.The ASCII table contains all the characters in the keyboard. Use irb
to find out wheter the characters “?” lies:

  1. Before 0. #what lies he is looking for here… I know how to use Irb
  2. After 9 but before A.
  3. After Z but before a.
  4. After z.

…I check the ascii table so “Before 0” is this “/” =/ this is
his number…After 9 is this “:” and before A is this “@” character, do
my understanding correct?

3.Using your experience the previous question, make a program that
accepts a character input and tells you if the character lines:

Before 0.
After 9 but before A.
After Z but before a.
After z.
Then try the program with the following characters:

$, +, ?, <, -, ~, :, %, ^, {, [

Sample answers:
$ lies before 0 #…why $ this lies before 0? confusing…
< lies between 9 and A

  • lies between Z and a
    ~ lies after z

…Now i don’t get it or confuse, I know to input the “gets” method and
the conditional method. here is the site of that exercise, scroll down
at the bottom.
http://localdoc.scusa.lsu.edu/ruby/Tutorial/part_02/conditionals.html

Thanks for someone answering this question

On 10/23/11 10:23 PM, Ray DarkScythe wrote:

else asci != “2uA4wfRy”
puts “retype this:” + “2” + “u”+ “A” + “4” + “w” + “f” + “R” + “y”
asci = gets.chomp.to_s
end until asci == “2uA4wfRy” #recycle if wrong input, I put this for fun
puts “2, 4, A, R, f, u, w, y”

I am not really sure if this is what the question looking for? I think
it is looking for a automated ascii alphabetically (you know the math
thing).
The question isn’t asking you to write a program. It is only asking you
to sort the characters, and you’ve done that already.

When you learn about arrays, you’ll learn about a method to sort it
automatically. :slight_smile:

his number…After 9 is this “:” and before A is this “@” character, do
my understanding correct?
“Lies” does not mean deception or falsehood here; “lies” means “is
located”. It is asking where the “?” is located in the ASCII table. Try
running “?” < “0” on irb and let your truth value be your guide.

Thanks for replying Alan, also for the help and pointers…

Alan Schwarz wrote:
When you learn about arrays, you’ll learn about a method to sort it
automatically. :slight_smile:

are you talking about the .sort method, it’s in the lesson in the array
section
I didn’t use it because the lesson is conditional, I assume there is a
way to write it automatically without using .sort method… using only
the conditional topic to arrange automatically.


Alan Schwarz wrote:
“Lies” does not mean deception or falsehood here; “lies” means “is
located”. It is asking where the “?” is located in the ASCII table. Try
running “?” < “0” on irb and let your truth value be your guide.

I already did that it say false, what will I do now, now I know it
false?
how do I find the location.here is the table chart of “?” ascii.

Binary:011 1111 Oct:077 Dec:63 Hex:3F Glyph:?

I am confuse about the location.

Thanks for people answering this question

Oops, sorry about that "From: " thing. I don’t know how it got there.

On Oct 24, 2011, at 1:16, Ray DarkScythe [email protected]
wrote:

are you talking about the .sort method, it’s in the lesson in the array
section
I didn’t use it because the lesson is conditional, I assume there is a
way to write it automatically without using .sort method… using only
the conditional topic to arrange automatically.

Yes, it is possible to use conditional statements to arrange
automatically. You can try to find algorithms on merge sort and
insertion sort and quicksort online to convert to Ruby.


I already did that it say false, what will I do now, now I know it
false?
how do I find the location.here is the table chart of “?” ascii.

Binary:011 1111 Oct:077 Dec:63 Hex:3F Glyph:?

I am confuse about the location.

If “?” < “0” is false, then “?” >= “0” must be true, “? lies or is
located after 0 in the ASCII table”.

What about the following?
“?” > “9”
“?” > “A”
“?” > “a”
“?” > “z”

Yes, Josh C.'s suggestion would be better.

On Mon, Oct 24, 2011 at 3:16 AM, Ray DarkScythe <
[email protected]> wrote:

the conditional topic to arrange automatically.

Binary:011 1111 Oct:077 Dec:63 Hex:3F Glyph:?

I am confuse about the location.

Thanks for people answering this question


Posted via http://www.ruby-forum.com/.

You can use String#ord and Fixnum#chr to convert between ascii value and
character.

“0”.ord # => 48
48.chr # => “0”

repost the code: forgot and edit something

puts "type any ascii character: "
lies = gets.chomp.to_s
asci = true
########### Before 0 :asci characte to type (/) (.) (-)
if lies == “/”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " before 0”
elsif lies == “.”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " before 0”
elsif lies == “-”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " before 0”
###########After 9 but before A
elsif lies == “@”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “?”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “>”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “=”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “<”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “;”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “:”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
########### After Z but before a
elsif lies == “`”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After Z but
before a”
elsif lies == “_”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After Z but
before a”
elsif lies == “^”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After Z but
before a”
elsif lies == “]”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After Z but
before a”
########### After z
elsif lies == “~”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After z”
elsif lies == “}”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After z”
elsif lies == “|”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After z”
elsif lies == “{”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After z”
end

Finaly it went through my head… thanks for all the help guys! (correct
me if I am wrong)

1.Before 0. ##this thing is looking for the ascii character before 0
which
is (/)(.)(-)(,)(+) and so on.
2.After 9 but before A. ## this (:)(;)(<)(=)(<)(?)(@)
3.After Z but before a. ## this (`)(_)(^)(])()([)
4.After z. ## this ({)(|)(})(~) and so on…

its like what letter will come next after A… and thats B and so on…
I put the code of my exercise…

yeah I know bad programming and lazy but the important thing now i
understand what the exercise is all about. I could have used array but
this is much straight forward. yeah cheating heheehehehe. I didn’t
include
the other ascii too many.

puts "type any ascii character: "
lies = gets.chomp.to_s
asci = true
########### Before 0 :asci characte to type (/) (.) (-)
if lies == “/”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " before 0”
elsif lies == “.”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " before 0”
elsif lies == “-”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " before 0”
###########After 9 but before A
elsif lies == “@”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “?”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “>”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “=”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “<”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “;”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “:”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
########### After Z but before a
elsif lies == “`”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “_”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “^”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “]”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
########### After z
elsif lies == “~”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “}”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “|”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
elsif lies == “{”
puts lies + " is “+ asci.to_s + " " + lies.ord.to_s + " After 9 but
before A”
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs