NaPoWriMo x NaPoGenMo 2024 Day 29 : Rule Based Carousel 3
Kofi / Illestpreacha
2 min read
Table of contents
Poetic Carousel 3
For the 29th day of NaPoWriMo/NaPoGenMo 2024, Poetic Carousel 3 contains rules and prompts coded in Ruby & Python. This is done by making a comparison between 6 random assortments of the alphabet and only outputting, letters that match.
Poetic Rule
The following rule set for this poem:
4 lines of poetry
3 stanzas
Words must start with the letter shown in these arrays
['x', 'j', 'p']
[]
['m', 'h', 'p']
[]
['p', 's']
['e', 'b', 'g', 'l']
Poem
Xylophones jumping profusely
Managing hopes perfectly
Persistence, Simply
Excludes Bass, Grabs & Leave
Code
Ruby
#random seed mapped to time, so it becomes "more" random
timer = use_random_seed Time.now.to_i
#range of letters in an array
grid = ('a'..'z').to_a
#shuffling as a random generator
grid_shuffled = grid.shuffle(random: Random.new(timer))
#empty erray
grid_final= []
#iteration to fill an array of 9 letters in
(0..36).each {|i| grid_final.push(grid_shuffled[i]) }
#print the final grid
puts grid_final.inspect
for letters in grid_final do
puts letters
end
#Output to a file
File.open("E:/Creatuve Code Challenges/Simplify/Simplification.txt", "w+") do |f|
f.puts(grid_final)
end
Python - File Read
#reading the file and adjusting it to become am array
import numpy as np
def reading(x):
f = open(x, "r")
arr = f.read().replace("\n", " ") # replace newline with space
print(arr)
arr1 = arr.split(" ") #puts its as an array
#arr1 = arr1_space.pop() #takes away the space at the end
print(arr1)
arr1_fix = arr1.pop() #removes last element
return arr1
text_1 = reading("E:\Creatuve Code Challenges\Simplify\Simplification5x5.txt")
text_2 = reading("E:\Creatuve Code Challenges\Simplify\Simplification5x5_1.txt")
text_3 = reading("E:\Creatuve Code Challenges\Simplify\Simplification5x5_2.txt")
text_4 = reading("E:\Creatuve Code Challenges\Simplify\Simplification5x5_3.txt")
Python - File Comparison
#comparison of the two list of letters and outputs the one that are in the identical spot
def charcheck(a,b):
#empty array
letters = []
#this will run a loop to the length of the array and if the elements match, it will be append to the letters array
i = 0
while i < len(text_1):
if (a[i] == b[i]):
letters.append(a[i])
i += 1
print(letters)
return letters
#All possible comparisons
tx1_a = charcheck(text_1,text_2)
tx1_b = charcheck(text_1,text_3)
tx1_c = charcheck(text_1,text_4)
tx2_a = charcheck(text_2,text_3)
tx2_b = charcheck(text_2,text_4)
tx3_a = charcheck(text_3,text_4)
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