From b0bbbf9103e78d5c08d97d4db271cf2618accdc4 Mon Sep 17 00:00:00 2001 From: KOTP Date: Tue, 26 Oct 2021 22:43:52 -0400 Subject: [PATCH 1/3] Initial documentation Still work to be done, but this should provide a guide to get started on the discussion as you might want to record it. I am, as "not the author" of the code, unsure if I have represented the listings accurately. --- crypto-square/README.adoc | 135 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 crypto-square/README.adoc diff --git a/crypto-square/README.adoc b/crypto-square/README.adoc new file mode 100644 index 0000000..7a93b53 --- /dev/null +++ b/crypto-square/README.adoc @@ -0,0 +1,135 @@ += Notes on Crypto Square as inspired by Exercism +:author: Gemp +:description: A discussion of Crypto Square as offered by Exercism. +:sectanchors: <.> +:safe: SERVER +:date: 26 October 2021 +:copyright: 2021 +:source-highlighter: pygments +:pygments-style: manni +:pygments-linenums-mode: inline +:toc: right +:icons: font + +This document is focused on Ruby, using the exercise called Crypto Square on +Exercism. The current version of the exercise description may have +changed.footnote:cryptosquare[https://github.com/exercism/ruby/blob/main/exercises/practice/crypto-square/.docs/instructions.md] + +.Description of Crypto Square +**** +As it was when solved, the documentation was written as: + +include::https://raw.githubusercontent.com/exercism/ruby/main/exercises/practice/crypto-square/.docs/instructions.md[leveloffset=+1] +**** + +== Crypto Square Iteration 1 + +=== Version 1 + + +[TIP] +Indentation in Ruby is two spaces, not tab, not four spaces. We can use a +variance from consistent style, though, to bring attention to an area when +needed. A very nice side effect from consistent style adherence! + +[source, ruby, linenums] +---- +class Crypto + +private # <1> + + attr_reader :text + + def initialize(text) + @text = text.downcase.scan(/\w/).freeze # <2> + end + + def cipher + return text if text.empty? + chars = Math.sqrt(text.size).ceil + length = chars * (text.size / chars.to_f).ceil + (0...chars).map do |start| + (start...length).step(chars).map { |i| text.fetch(i, ' ') }.join + end + end + +public + + def ciphertext + cipher.join(' ') + end + +end +---- +<1> Indentation in Ruby is two spaces, so this is contrary to convention +<2> Explanation of why we would want to freeze this, and if it is immune to +garbage collection + + +== Crypto Square iteration 2 + +=== Version 1 + +This is the second iteration as submitted to Exercism. + +[source, ruby, linenums] +---- +class Crypto + +private + + attr_reader :text + + def initialize(text) + @text = text.downcase.gsub(/\W/, '').freeze + end + + def cipher + cols = Math.sqrt(text.size).ceil + text.scan(/.{1,#{cols}}/).map { |s| s.ljust(cols).chars }.transpose + end + +public + + def ciphertext + return text if text.empty? + @cipher ||= cipher.map(&:join).join(' ') + end + +end +---- + +== Crypto Square Version 3 + +=== Version 1 + +[source, ruby, linenums] +---- +class Crypto + +private + + attr_reader :text + + def initialize(text) + @text = text.downcase.gsub(/\W/, '').freeze + end + + def cipher + cols = Math.sqrt(text.size).ceil + miss = text.size.modulo(cols) #avoid ljust on every string (comment) + adjusted = miss.zero? ? text : text + ' ' * (cols - miss) + adjusted.scan(/.{1,#{cols}}/).map(&:chars).transpose + end + +public + + def ciphertext + return text if text.empty? + @cipher ||= cipher.map(&:join).join(' ') + end + +end +---- + + From 6446a538c06c9e928984317d6a4c3bc3b59d293c Mon Sep 17 00:00:00 2001 From: KOTP Date: Tue, 26 Oct 2021 23:10:30 -0400 Subject: [PATCH 2/3] Use Ruby as default source language --- crypto-square/README.adoc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crypto-square/README.adoc b/crypto-square/README.adoc index 7a93b53..fdd49b4 100644 --- a/crypto-square/README.adoc +++ b/crypto-square/README.adoc @@ -6,6 +6,7 @@ :date: 26 October 2021 :copyright: 2021 :source-highlighter: pygments +:source-language: ruby :pygments-style: manni :pygments-linenums-mode: inline :toc: right @@ -72,7 +73,7 @@ garbage collection This is the second iteration as submitted to Exercism. -[source, ruby, linenums] +[source%linenums] ---- class Crypto @@ -103,7 +104,7 @@ end === Version 1 -[source, ruby, linenums] +[source%linenums] ---- class Crypto @@ -133,3 +134,4 @@ end ---- + From e9d39d8ddd0008dd9f4bc04e1a9dc504dc093a3a Mon Sep 17 00:00:00 2001 From: KOTP Date: Mon, 22 Sep 2025 02:51:33 -0400 Subject: [PATCH 3/3] Update to provide Gemfile and refactor document --- Gemfile | 5 + crypto-square/README.adoc | 108 +---- crypto-square/README.html | 718 +++++++++++++++++++++++++++++++ crypto-square/crypto_square_1.rb | 6 +- 4 files changed, 745 insertions(+), 92 deletions(-) create mode 100644 Gemfile create mode 100644 crypto-square/README.html diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..98dcead --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' + +gem 'asciidoctor' +gem 'asciidoctor-pdf' +gem 'pygments.rb' diff --git a/crypto-square/README.adoc b/crypto-square/README.adoc index fdd49b4..3d7b565 100644 --- a/crypto-square/README.adoc +++ b/crypto-square/README.adoc @@ -12,9 +12,8 @@ :toc: right :icons: font -This document is focused on Ruby, using the exercise called Crypto Square on -Exercism. The current version of the exercise description may have -changed.footnote:cryptosquare[https://github.com/exercism/ruby/blob/main/exercises/practice/crypto-square/.docs/instructions.md] +This document is focused on Ruby, using the exercise called Crypto Square on Exercism. +The current version of the exercise description may have changed.footnote:cryptosquare[https://github.com/exercism/ruby/blob/main/exercises/practice/crypto-square/.docs/instructions.md] .Description of Crypto Square **** @@ -23,115 +22,46 @@ As it was when solved, the documentation was written as: include::https://raw.githubusercontent.com/exercism/ruby/main/exercises/practice/crypto-square/.docs/instructions.md[leveloffset=+1] **** +<<< == Crypto Square Iteration 1 === Version 1 [TIP] -Indentation in Ruby is two spaces, not tab, not four spaces. We can use a -variance from consistent style, though, to bring attention to an area when -needed. A very nice side effect from consistent style adherence! +Indentation in Ruby is two spaces, not tab, not four spaces. +We can use a variance from consistent style, though, to bring attention to an area when needed. +A very nice side effect from consistent style adherence! +.crypto_square_1.rb [source, ruby, linenums] ---- -class Crypto - -private # <1> - - attr_reader :text - - def initialize(text) - @text = text.downcase.scan(/\w/).freeze # <2> - end - - def cipher - return text if text.empty? - chars = Math.sqrt(text.size).ceil - length = chars * (text.size / chars.to_f).ceil - (0...chars).map do |start| - (start...length).step(chars).map { |i| text.fetch(i, ' ') }.join - end - end - -public - - def ciphertext - cipher.join(' ') - end - -end +include::crypto_square_1.rb[] ---- <1> Indentation in Ruby is two spaces, so this is contrary to convention -<2> Explanation of why we would want to freeze this, and if it is immune to -garbage collection - +<2> Explanation of why we would want to freeze this, and if it is immune to garbage collection +<<< == Crypto Square iteration 2 -=== Version 1 +=== Version 2 This is the second iteration as submitted to Exercism. -[source%linenums] +.crypto_square_2.rb +[source, ruby, linenums] ---- -class Crypto - -private - - attr_reader :text - - def initialize(text) - @text = text.downcase.gsub(/\W/, '').freeze - end - - def cipher - cols = Math.sqrt(text.size).ceil - text.scan(/.{1,#{cols}}/).map { |s| s.ljust(cols).chars }.transpose - end - -public - - def ciphertext - return text if text.empty? - @cipher ||= cipher.map(&:join).join(' ') - end - -end +include::crypto_square_2.rb[] ---- +<<< == Crypto Square Version 3 -=== Version 1 +=== Version 3 -[source%linenums] +.cryto_square_2_bis.rb +[source, ruby, linenums] ---- -class Crypto - -private - - attr_reader :text - - def initialize(text) - @text = text.downcase.gsub(/\W/, '').freeze - end - - def cipher - cols = Math.sqrt(text.size).ceil - miss = text.size.modulo(cols) #avoid ljust on every string (comment) - adjusted = miss.zero? ? text : text + ' ' * (cols - miss) - adjusted.scan(/.{1,#{cols}}/).map(&:chars).transpose - end - -public - - def ciphertext - return text if text.empty? - @cipher ||= cipher.map(&:join).join(' ') - end - -end +include::crypto_square_2_bis.rb[] ---- - - diff --git a/crypto-square/README.html b/crypto-square/README.html new file mode 100644 index 0000000..e0ceb9b --- /dev/null +++ b/crypto-square/README.html @@ -0,0 +1,718 @@ + + + + + + + + + + +Notes on Crypto Square as inspired by Exercism + + + + + + + +
+
+
+
+

This document is focused on Ruby, using the exercise called Crypto Square on Exercism. +The current version of the exercise description may have changed.[1]

+
+
+
+
Description of Crypto Square
+
+

As it was when solved, the documentation was written as:

+
+ +
+
+
+
+
+
+

Crypto Square Iteration 1

+
+
+

Version 1

+
+ + + + + +
+ + +Indentation in Ruby is two spaces, not tab, not four spaces. +We can use a variance from consistent style, though, to bring attention to an area when needed. +A very nice side effect from consistent style adherence! +
+
+
+
crypto_square_1.rb
+
+
 1class Crypto
+ 2
+ 3private (1)
+ 4
+ 5  attr_reader :text
+ 6
+ 7  def initialize(text)
+ 8    @text = text.downcase.scan(/\w/).freeze (2)
+ 9  end
+10
+11  def cipher
+12    return text if text.empty?
+13    chars = Math.sqrt(text.size).ceil
+14    length = chars * (text.size / chars.to_f).ceil
+15    (0...chars).map do |start|
+16      (start...length).step(chars).map { |i| text.fetch(i, ' ') }.join
+17    end
+18  end
+19
+20public
+21
+22  def ciphertext
+23    cipher.join(' ')
+24  end
+25
+26end
+
+
+
+ + + + + + + + + +
1Indentation in Ruby is two spaces, so this is contrary to convention
2Explanation of why we would want to freeze this, and if it is immune to garbage collection
+
+
+
+
+
+
+

Crypto Square iteration 2

+
+
+

Version 2

+
+

This is the second iteration as submitted to Exercism.

+
+
+
crypto_square_2.rb
+
+
 1class Crypto
+ 2
+ 3private
+ 4
+ 5  attr_reader :text
+ 6
+ 7  def initialize(text)
+ 8    @text = text.downcase.gsub(/\W/, '').freeze
+ 9  end
+10
+11  def cipher
+12    cols = Math.sqrt(text.size).ceil
+13    text.scan(/.{1,#{cols}}/).map { |s| s.ljust(cols).chars }.transpose
+14  end
+15
+16public
+17
+18  def ciphertext
+19    return text if text.empty?
+20    @cipher ||= cipher.map(&:join).join(' ')
+21  end
+22
+23end
+
+
+
+
+
+
+
+

Crypto Square Version 3

+
+
+

Version 3

+
+
cryto_square_2_bis.rb
+
+
 1class Crypto
+ 2
+ 3private
+ 4
+ 5  attr_reader :text
+ 6
+ 7  def initialize(text)
+ 8    @text = text.downcase.gsub(/\W/, '').freeze
+ 9  end
+10
+11  def cipher
+12    cols = Math.sqrt(text.size).ceil
+13    miss = text.size.modulo(cols) #avoid ljust on every string (comment)
+14    adjusted = miss.zero? ? text : text + ' ' * (cols - miss)
+15    adjusted.scan(/.{1,#{cols}}/).map(&:chars).transpose
+16  end
+17
+18public
+19
+20  def ciphertext
+21    return text if text.empty?
+22    @cipher ||= cipher.map(&:join).join(' ')
+23  end
+24
+25end
+
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/crypto-square/crypto_square_1.rb b/crypto-square/crypto_square_1.rb index 0abcd37..e393f1d 100644 --- a/crypto-square/crypto_square_1.rb +++ b/crypto-square/crypto_square_1.rb @@ -1,11 +1,11 @@ class Crypto -private +private # <1> attr_reader :text def initialize(text) - @text = text.downcase.scan(/\w/).freeze + @text = text.downcase.scan(/\w/).freeze # <2> end def cipher @@ -23,4 +23,4 @@ def ciphertext cipher.join(' ') end -end \ No newline at end of file +end