Skip to content

Instantly share code, notes, and snippets.

@LevitatingBusinessMan
Created October 13, 2024 20:27
Show Gist options
  • Select an option

  • Save LevitatingBusinessMan/2181cca2b6de5ebec45446e82f0a25ca to your computer and use it in GitHub Desktop.

Select an option

Save LevitatingBusinessMan/2181cca2b6de5ebec45446e82f0a25ca to your computer and use it in GitHub Desktop.
this sentence has
digraph {
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
20->32
32->36
21->36
22->36
23->38
24->37
37->38
25->37
37->38
26->36
27->38
28->38
29->37
37->38
30->32
32->36
31->36
32->36
33->38
34->37
37->38
35->37
37->38
37->38
39->37
37->38
40->31
31->36
}
#!/usr/bin/env ruby
require 'numbers_and_words'
vertices = (20..40).to_a
$edges = []
class Integer
def try
length = "This sentence has #{self.to_words} letters".length
if self != length
$edges << [self, length]
length.try
end
end
end
vertices.each(&:try)
dot = "digraph {\n#{vertices.join "\n"}\n"
for e1, e2 in $edges
dot << "#{e1}->#{e2}\n"
end
File.write "out.dot", dot << "}\n"
`dot -Tpng out.dot -o out.png && xdg-open out.png`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment