WCCC_ 2Rules
Kofi / Illestpreacha
3 min read
Table of contents
PoemsFromDials
For this week's Creative Code challenge by @sableRaph: " Two Rules",
PoemsFromDials is coded in Ruby and turns numbers into an array of their possible letters as seen on a phone below. After that it proceeds to reverse the tranpose matrix of letters.
Which then allows for the Two Rules of this poem framework to be mentioned:
If there is a letter the word must start or end with the letter shown
If there is a “*” instead of a letter, any word can be used but if it is “-”, that word has to be crossed out
Sample Poems
Poem 1
Number = "745" + "911"
Output/Ruleset
s i * z * *
r h l y * *
q * k x * *
p g j w * *
Simply invested as zoo animals wander
roaming, hurdling, lingering, yapping with danger
quickly asking, Keeping Xylophones for bangers
Paused! Green Jaguars woefully increasing ponders
Poem 2
Number = "18007932154"
Output/Ruleset
* v * * s z f c * * i
* u * * r y e * * l h
* * * * q x d b * k *
* t * * p w * a * j g
Breezing Victoriously! Through as the sea zooms furiously ,countering the progress inside
Motions under the current, reeling yaks elongated by the landscape heights
Blitzing through the means, quickly X’s domains by the King flights
Tipping Towards as the premise which, the antics and juxtaposition grinds
Interactive Version
https://www.jdoodle.com/ia/1jir
Change the numbers seen in the brackets to have your own PoemsFromDials
dailing("745" + "911")
dailing("18007932154")
Ruby Code
#two rule poetic format maker
#turn a phone a number that doesnt contain 7 or 9 into the letters of the phone
#then transpose the words , so a poem can be written out of the components
# Include matrix
require "matrix"
def dailing(digits)
#turn the number dailed to a string
digits = digits.to_s
len_dig = digits.length
count = 0
digits_array = digits.split("")
let_com = []
#phone numbercombos and to match the four letter matrix for a tranpose
#the star will represent that you have any letter and will be across different indexes
#this allows zero and one to be included
a0 = ['*','*','*','*']
a1 = ['*','*','*','*']
a2 = ['a','b','*','c']
a3 = ['*','d','e','f']
a4 = ['g','*','h','i']
a5 = ['j','k','l','*']
a6 = ['m','n','o','*']
a7 = ['p','q','r','s']
a8 = ['t','*','u','v']
a9 = ['w','x','y','z']
#hash the strings into the array
dial = { "0" => a0 , "1" => a1,"2" => a2, "3" => a3,"4" => a4,"5" => a5,"6" => a6,"7" => a7,"8" => a8,"9" => a9}
#default value for the array, when a random non number value enters
dial.default = ['-','-','-','-']
#push the array into the other via the dial index hash
while count < len_dig
let_com.push(dial[digits_array[count]])
count += 1
end
#transpose the array and then reverses the outcome
lineOfStr = let_com.transpose.reverse
counter = 0
while counter < lineOfStr.length
puts lineOfStr[counter].join(" ") #makes every subarray space out its elements
counter += 1
end
end
puts dailing("745" + "911")
puts dailing("18007932154")
0
Subscribe to my newsletter
Read articles from Kofi / Illestpreacha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by