From cc5f51ed21543342cea60bd373721d4faa664e94 Mon Sep 17 00:00:00 2001 From: Yonatan Date: Wed, 6 Dec 2017 00:05:17 -0500 Subject: [PATCH 1/6] - [X] Se crean carpetas java y ruby - [X] Se mueven los archivo a la carpeta correspondiente - [X] Se crea una solucion nueva en lenguaje Ruby ubicada en la carpeta Ruby --- Ruby/impresorLCD.rb | 141 ++++++++++++++++++++++++++++++++++++++++++++ impresorLCD.rb | 141 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 282 insertions(+) create mode 100644 Ruby/impresorLCD.rb create mode 100644 impresorLCD.rb diff --git a/Ruby/impresorLCD.rb b/Ruby/impresorLCD.rb new file mode 100644 index 0000000..05d40f2 --- /dev/null +++ b/Ruby/impresorLCD.rb @@ -0,0 +1,141 @@ +require 'pry' + +class LCD + # _ -> Horizontal + # | -> Vertical + attr_accessor(:size, :spacing) + + # + # This hash is used to define the segment display for the + # given digit. Each entry in the array is associated with + # the following states: + # + # HORIZONTAL + # VERTICAL + # HORIZONTAL + # VERTICAL + # HORIZONTAL + # DONE + # + # The HORIZONTAL state produces a single horizontal line. There + # are two types: + # + # 0 - skip, no line necessary, just space fill + # 1 - line required of given size + # + # The VERTICAL state produces a either a single right side line, + # a single left side line or a both lines. + # + # 0 - skip, no line necessary, just space fill + # 1 - single right side line + # 2 - single left side line + # 3 - both lines + # + # The DONE state terminates the state machine. This is not needed + # as part of the data array. + # + # + def initialize(spacing = 1) + @spacing = spacing + end + + def input + puts 'Ingrese tamaño de letra y numeros a imprimir en pantalla, termine con 0,0' + puts 'Ejm: 1,1234 0,0' + puts '' + STDOUT.flush + arr_input(gets.chomp) + end + + def arr_input(input) + arr_input = input.split + arr_input.each do |value| + return if value.eql? '0,0' + validate_value(value) + end + end + + def validate_value(value) + value = value.split(',') + # binding.pry + return unless (value.size.eql? 2) && value[0].to_i.integer? && value[0].to_i != 0 && (value[0].to_i != (1..10)) && value[1].to_i.integer? + display(value[0].to_i, value[1].to_s) + rescue + '' + end + + def lcdDisplayData + @lcdDisplayData = { + '0' => [1, 3, 0, 3, 1], + '1' => [0, 1, 0, 1, 0], + '2' => [1, 1, 1, 2, 1], + '3' => [1, 1, 1, 1, 1], + '4' => [0, 3, 1, 1, 0], + '5' => [1, 2, 1, 1, 1], + '6' => [1, 2, 1, 3, 1], + '7' => [1, 1, 0, 1, 0], + '8' => [1, 3, 1, 3, 1], + '9' => [1, 3, 1, 1, 1] + } + end + + def lcdStates + @lcdStates = %w[ + DONE + HORIZONTAL + VERTICAL + HORIZONTAL + VERTICAL + HORIZONTAL + ] + end + + def display(size, digits) + states = lcdStates + 0.upto(lcdStates.length) do |state| + case states.pop + when 'HORIZONTAL' + line = '' + digits.each_byte do |digit| + line += horizontal_segment(lcdDisplayData[digit.chr][state], size) + end + print line + "\n" + when 'VERTICAL' + 1.upto(size) do |_j| + line = '' + digits.each_byte do |digit| + line += vertical_segment(lcdDisplayData[digit.chr][state], size) + end + print line + "\n" + end + when 'DONE' + break + end + end + end + + def horizontal_segment(type, size) + case type + when 1 + ' ' + ('-' * size) + ' ' + (' ' * @spacing) + else + ' ' + (' ' * size) + ' ' + (' ' * @spacing) + end + end + + def vertical_segment(type, size) + case type + when 1 + ' ' + (' ' * size) + '|' + (' ' * @spacing) + when 2 + '|' + (' ' * size) + ' ' + (' ' * @spacing) + when 3 + '|' + (' ' * size) + '|' + (' ' * @spacing) + else + ' ' + (' ' * size) + ' ' + (' ' * @spacing) + end + end +end + +start = LCD.new +start.input diff --git a/impresorLCD.rb b/impresorLCD.rb new file mode 100644 index 0000000..05d40f2 --- /dev/null +++ b/impresorLCD.rb @@ -0,0 +1,141 @@ +require 'pry' + +class LCD + # _ -> Horizontal + # | -> Vertical + attr_accessor(:size, :spacing) + + # + # This hash is used to define the segment display for the + # given digit. Each entry in the array is associated with + # the following states: + # + # HORIZONTAL + # VERTICAL + # HORIZONTAL + # VERTICAL + # HORIZONTAL + # DONE + # + # The HORIZONTAL state produces a single horizontal line. There + # are two types: + # + # 0 - skip, no line necessary, just space fill + # 1 - line required of given size + # + # The VERTICAL state produces a either a single right side line, + # a single left side line or a both lines. + # + # 0 - skip, no line necessary, just space fill + # 1 - single right side line + # 2 - single left side line + # 3 - both lines + # + # The DONE state terminates the state machine. This is not needed + # as part of the data array. + # + # + def initialize(spacing = 1) + @spacing = spacing + end + + def input + puts 'Ingrese tamaño de letra y numeros a imprimir en pantalla, termine con 0,0' + puts 'Ejm: 1,1234 0,0' + puts '' + STDOUT.flush + arr_input(gets.chomp) + end + + def arr_input(input) + arr_input = input.split + arr_input.each do |value| + return if value.eql? '0,0' + validate_value(value) + end + end + + def validate_value(value) + value = value.split(',') + # binding.pry + return unless (value.size.eql? 2) && value[0].to_i.integer? && value[0].to_i != 0 && (value[0].to_i != (1..10)) && value[1].to_i.integer? + display(value[0].to_i, value[1].to_s) + rescue + '' + end + + def lcdDisplayData + @lcdDisplayData = { + '0' => [1, 3, 0, 3, 1], + '1' => [0, 1, 0, 1, 0], + '2' => [1, 1, 1, 2, 1], + '3' => [1, 1, 1, 1, 1], + '4' => [0, 3, 1, 1, 0], + '5' => [1, 2, 1, 1, 1], + '6' => [1, 2, 1, 3, 1], + '7' => [1, 1, 0, 1, 0], + '8' => [1, 3, 1, 3, 1], + '9' => [1, 3, 1, 1, 1] + } + end + + def lcdStates + @lcdStates = %w[ + DONE + HORIZONTAL + VERTICAL + HORIZONTAL + VERTICAL + HORIZONTAL + ] + end + + def display(size, digits) + states = lcdStates + 0.upto(lcdStates.length) do |state| + case states.pop + when 'HORIZONTAL' + line = '' + digits.each_byte do |digit| + line += horizontal_segment(lcdDisplayData[digit.chr][state], size) + end + print line + "\n" + when 'VERTICAL' + 1.upto(size) do |_j| + line = '' + digits.each_byte do |digit| + line += vertical_segment(lcdDisplayData[digit.chr][state], size) + end + print line + "\n" + end + when 'DONE' + break + end + end + end + + def horizontal_segment(type, size) + case type + when 1 + ' ' + ('-' * size) + ' ' + (' ' * @spacing) + else + ' ' + (' ' * size) + ' ' + (' ' * @spacing) + end + end + + def vertical_segment(type, size) + case type + when 1 + ' ' + (' ' * size) + '|' + (' ' * @spacing) + when 2 + '|' + (' ' * size) + ' ' + (' ' * @spacing) + when 3 + '|' + (' ' * size) + '|' + (' ' * @spacing) + else + ' ' + (' ' * size) + ' ' + (' ' * @spacing) + end + end +end + +start = LCD.new +start.input From ab4667f72ac48c0d7b707ecef3fc5ba75242b48a Mon Sep 17 00:00:00 2001 From: Yonatan Date: Wed, 6 Dec 2017 00:05:17 -0500 Subject: [PATCH 2/6] - [X] Se crean carpetas java y ruby - [X] Se mueven los archivo a la carpeta correspondiente - [X] Se crea una solucion nueva en lenguaje Ruby ubicada en la carpeta Ruby --- Ruby/impresorLCD.rb | 141 ++++++++++++++++++++++ ImpresorLCD.java => java/ImpresorLCD.java | 0 LCDTester.java => java/LCDTester.java | 0 3 files changed, 141 insertions(+) create mode 100644 Ruby/impresorLCD.rb rename ImpresorLCD.java => java/ImpresorLCD.java (100%) rename LCDTester.java => java/LCDTester.java (100%) diff --git a/Ruby/impresorLCD.rb b/Ruby/impresorLCD.rb new file mode 100644 index 0000000..05d40f2 --- /dev/null +++ b/Ruby/impresorLCD.rb @@ -0,0 +1,141 @@ +require 'pry' + +class LCD + # _ -> Horizontal + # | -> Vertical + attr_accessor(:size, :spacing) + + # + # This hash is used to define the segment display for the + # given digit. Each entry in the array is associated with + # the following states: + # + # HORIZONTAL + # VERTICAL + # HORIZONTAL + # VERTICAL + # HORIZONTAL + # DONE + # + # The HORIZONTAL state produces a single horizontal line. There + # are two types: + # + # 0 - skip, no line necessary, just space fill + # 1 - line required of given size + # + # The VERTICAL state produces a either a single right side line, + # a single left side line or a both lines. + # + # 0 - skip, no line necessary, just space fill + # 1 - single right side line + # 2 - single left side line + # 3 - both lines + # + # The DONE state terminates the state machine. This is not needed + # as part of the data array. + # + # + def initialize(spacing = 1) + @spacing = spacing + end + + def input + puts 'Ingrese tamaño de letra y numeros a imprimir en pantalla, termine con 0,0' + puts 'Ejm: 1,1234 0,0' + puts '' + STDOUT.flush + arr_input(gets.chomp) + end + + def arr_input(input) + arr_input = input.split + arr_input.each do |value| + return if value.eql? '0,0' + validate_value(value) + end + end + + def validate_value(value) + value = value.split(',') + # binding.pry + return unless (value.size.eql? 2) && value[0].to_i.integer? && value[0].to_i != 0 && (value[0].to_i != (1..10)) && value[1].to_i.integer? + display(value[0].to_i, value[1].to_s) + rescue + '' + end + + def lcdDisplayData + @lcdDisplayData = { + '0' => [1, 3, 0, 3, 1], + '1' => [0, 1, 0, 1, 0], + '2' => [1, 1, 1, 2, 1], + '3' => [1, 1, 1, 1, 1], + '4' => [0, 3, 1, 1, 0], + '5' => [1, 2, 1, 1, 1], + '6' => [1, 2, 1, 3, 1], + '7' => [1, 1, 0, 1, 0], + '8' => [1, 3, 1, 3, 1], + '9' => [1, 3, 1, 1, 1] + } + end + + def lcdStates + @lcdStates = %w[ + DONE + HORIZONTAL + VERTICAL + HORIZONTAL + VERTICAL + HORIZONTAL + ] + end + + def display(size, digits) + states = lcdStates + 0.upto(lcdStates.length) do |state| + case states.pop + when 'HORIZONTAL' + line = '' + digits.each_byte do |digit| + line += horizontal_segment(lcdDisplayData[digit.chr][state], size) + end + print line + "\n" + when 'VERTICAL' + 1.upto(size) do |_j| + line = '' + digits.each_byte do |digit| + line += vertical_segment(lcdDisplayData[digit.chr][state], size) + end + print line + "\n" + end + when 'DONE' + break + end + end + end + + def horizontal_segment(type, size) + case type + when 1 + ' ' + ('-' * size) + ' ' + (' ' * @spacing) + else + ' ' + (' ' * size) + ' ' + (' ' * @spacing) + end + end + + def vertical_segment(type, size) + case type + when 1 + ' ' + (' ' * size) + '|' + (' ' * @spacing) + when 2 + '|' + (' ' * size) + ' ' + (' ' * @spacing) + when 3 + '|' + (' ' * size) + '|' + (' ' * @spacing) + else + ' ' + (' ' * size) + ' ' + (' ' * @spacing) + end + end +end + +start = LCD.new +start.input diff --git a/ImpresorLCD.java b/java/ImpresorLCD.java similarity index 100% rename from ImpresorLCD.java rename to java/ImpresorLCD.java diff --git a/LCDTester.java b/java/LCDTester.java similarity index 100% rename from LCDTester.java rename to java/LCDTester.java From 0cd1fe87db987a00a959f43044a95e07daf0d0b5 Mon Sep 17 00:00:00 2001 From: Yonatan Date: Wed, 6 Dec 2017 00:11:50 -0500 Subject: [PATCH 3/6] - [X] Elimino archivo copiado a la carpeta Ruby --- impresorLCD.rb | 141 ------------------------------------------------- 1 file changed, 141 deletions(-) delete mode 100644 impresorLCD.rb diff --git a/impresorLCD.rb b/impresorLCD.rb deleted file mode 100644 index 05d40f2..0000000 --- a/impresorLCD.rb +++ /dev/null @@ -1,141 +0,0 @@ -require 'pry' - -class LCD - # _ -> Horizontal - # | -> Vertical - attr_accessor(:size, :spacing) - - # - # This hash is used to define the segment display for the - # given digit. Each entry in the array is associated with - # the following states: - # - # HORIZONTAL - # VERTICAL - # HORIZONTAL - # VERTICAL - # HORIZONTAL - # DONE - # - # The HORIZONTAL state produces a single horizontal line. There - # are two types: - # - # 0 - skip, no line necessary, just space fill - # 1 - line required of given size - # - # The VERTICAL state produces a either a single right side line, - # a single left side line or a both lines. - # - # 0 - skip, no line necessary, just space fill - # 1 - single right side line - # 2 - single left side line - # 3 - both lines - # - # The DONE state terminates the state machine. This is not needed - # as part of the data array. - # - # - def initialize(spacing = 1) - @spacing = spacing - end - - def input - puts 'Ingrese tamaño de letra y numeros a imprimir en pantalla, termine con 0,0' - puts 'Ejm: 1,1234 0,0' - puts '' - STDOUT.flush - arr_input(gets.chomp) - end - - def arr_input(input) - arr_input = input.split - arr_input.each do |value| - return if value.eql? '0,0' - validate_value(value) - end - end - - def validate_value(value) - value = value.split(',') - # binding.pry - return unless (value.size.eql? 2) && value[0].to_i.integer? && value[0].to_i != 0 && (value[0].to_i != (1..10)) && value[1].to_i.integer? - display(value[0].to_i, value[1].to_s) - rescue - '' - end - - def lcdDisplayData - @lcdDisplayData = { - '0' => [1, 3, 0, 3, 1], - '1' => [0, 1, 0, 1, 0], - '2' => [1, 1, 1, 2, 1], - '3' => [1, 1, 1, 1, 1], - '4' => [0, 3, 1, 1, 0], - '5' => [1, 2, 1, 1, 1], - '6' => [1, 2, 1, 3, 1], - '7' => [1, 1, 0, 1, 0], - '8' => [1, 3, 1, 3, 1], - '9' => [1, 3, 1, 1, 1] - } - end - - def lcdStates - @lcdStates = %w[ - DONE - HORIZONTAL - VERTICAL - HORIZONTAL - VERTICAL - HORIZONTAL - ] - end - - def display(size, digits) - states = lcdStates - 0.upto(lcdStates.length) do |state| - case states.pop - when 'HORIZONTAL' - line = '' - digits.each_byte do |digit| - line += horizontal_segment(lcdDisplayData[digit.chr][state], size) - end - print line + "\n" - when 'VERTICAL' - 1.upto(size) do |_j| - line = '' - digits.each_byte do |digit| - line += vertical_segment(lcdDisplayData[digit.chr][state], size) - end - print line + "\n" - end - when 'DONE' - break - end - end - end - - def horizontal_segment(type, size) - case type - when 1 - ' ' + ('-' * size) + ' ' + (' ' * @spacing) - else - ' ' + (' ' * size) + ' ' + (' ' * @spacing) - end - end - - def vertical_segment(type, size) - case type - when 1 - ' ' + (' ' * size) + '|' + (' ' * @spacing) - when 2 - '|' + (' ' * size) + ' ' + (' ' * @spacing) - when 3 - '|' + (' ' * size) + '|' + (' ' * @spacing) - else - ' ' + (' ' * size) + ' ' + (' ' * @spacing) - end - end -end - -start = LCD.new -start.input From 9b2d298b09e0a660c4169f8459bda9a68200af28 Mon Sep 17 00:00:00 2001 From: Yonatan Date: Wed, 6 Dec 2017 00:14:17 -0500 Subject: [PATCH 4/6] - [X] Cambio nombre de carpeta Java --- {java => Java}/ImpresorLCD.java | 0 {java => Java}/LCDTester.java | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {java => Java}/ImpresorLCD.java (100%) rename {java => Java}/LCDTester.java (100%) diff --git a/java/ImpresorLCD.java b/Java/ImpresorLCD.java similarity index 100% rename from java/ImpresorLCD.java rename to Java/ImpresorLCD.java diff --git a/java/LCDTester.java b/Java/LCDTester.java similarity index 100% rename from java/LCDTester.java rename to Java/LCDTester.java From 499a7939b71f4ecda4e5de772b61b9fc5e149165 Mon Sep 17 00:00:00 2001 From: Yonatan Date: Wed, 6 Dec 2017 00:31:12 -0500 Subject: [PATCH 5/6] =?UTF-8?q?=20-=20[X]=20A=C3=B1adiendo=20README=20de?= =?UTF-8?q?=20la=20soluci=C3=B3n=20Ruby?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ruby/README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Ruby/README.md diff --git a/Ruby/README.md b/Ruby/README.md new file mode 100644 index 0000000..4fb2c87 --- /dev/null +++ b/Ruby/README.md @@ -0,0 +1,43 @@ +# LCD refactor + +Objetivo: Crear un programa que imprime números en estilo de una pantalla LCD + +Entrada: La entrada contiene varias líneas. Cada línea contiene 2 números separados por coma. El primer número representa el tamaño de la impresión (entre 1 y 10, esta variable se llama “size”). El segundo número es el número a mostrar en la pantalla. Para terminar, se debe digitar 0,0. Esto terminará la aplicación. + +Salida: Imprimir los números especificados usando el caracter “-“ para los caracteres horizontales, y “|” para los verticales. Cada dígito debe ocupar exactamente size+2 columnas y 2*size + 3 filas. + +Entre cada impresión debe haber una línea blanca. + +Ejemplo: +Entrada: +2,12345 +3,67890 +0,0 + +Salida: +
  
+   _ _  _ _        _ _
+|     |    | |  | |
+|  _ _| _ _| |__| |_ _
+| |        |    |     |
+| |_ _  _ _|    |  _ _|
+
+ _ _ _  _ _ _   _ _ _   _ _ _   _ _ _ 
+|            | |     | |     | |     |
+|            | |     | |     | |     |
+|_ _ _       | |_ _ _| |_ _ _| |     |
+|     |      | |     |       | |     |
+|     |      | |     |       | |     |
+|_ _ _|      | |_ _ _|  _ _ _| |_ _ _|
+
+ 
+ +**Requerimientos**: + - [X] Ruby + +**Ejecutar archivo:** +En la carpeta Ruby ejecutar el comando + +`ruby impresorLCD.rb` + +![img](https://imgur.com/c2989dG) \ No newline at end of file From 8ed21aa60f0174a26ff25b1cab7454f31b06ccfa Mon Sep 17 00:00:00 2001 From: Yonatan Valencia Date: Wed, 6 Dec 2017 00:37:16 -0500 Subject: [PATCH 6/6] Ajuste a README --- Ruby/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Ruby/README.md b/Ruby/README.md index 4fb2c87..48cd68b 100644 --- a/Ruby/README.md +++ b/Ruby/README.md @@ -40,4 +40,5 @@ En la carpeta Ruby ejecutar el comando `ruby impresorLCD.rb` -![img](https://imgur.com/c2989dG) \ No newline at end of file + +![img](https://i.imgur.com/c2989dG.png)