A Pen by John

Developer
Size
8,909 Kb
Views
14,168

How do I make an a pen by john?

What is a a pen by john? How do you make a a pen by john? This script and codes were developed by John on 16 November 2022, Wednesday.

A Pen by John Previews

A Pen by John - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>A Pen by John</title> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<!-- COMMENT: To my fellow Coursera students: If you expand the the HTML window's width so that these two coment lines -->
<!-- appear full width on your screen, the indenting of everything should make my raw HTML code easier to read. -->
<CENTER>
<table border=0 width=100%> <TR> <TD align=left> Homework project for <a href=https://www.coursera.org>Coursera.org</a> course<BR> <a href=https://www.coursera.org/learn/duke-programming-web>Programming and the Web for Beginners</a><TD> <TD align=right>www.bit.ly/<B>HowToCreateRandomPuzzlePages</B><small><BR> <B>Please note:</B> This is a <em><u>page in process</u></em>. It is not complete<BR> (Suggestions are warmly welcomed)</small></TD> </tr>
</table>
<h1>How to Create Random Puzzles on a Web Page</h1> <a href="http://tinypic.com?ref=2m35us8" target="_blank"><img src="http://i66.tinypic.com/2m35us8.gif" size=316 border="0" alt="Image and video hosting by TinyPic"></a> <BR> Sample Puzzle randomized by <a href=http://qb64.net>QB64.net</a> program
</CENTER>
<h2>1. Find a puzzle or problem to imitate</h2>
<ul> <LI class=LiBold>From someone's website <UL> <LI class=LiExam>Example: <a href=https://maths-tricks-puzzles.blogspot.com/>maths-tricks-puzzles.blogspot.com</a></LI> </ul> </li> <LI class=LiBold>From a puzzle magazine <UL> <LI class=LiExam>Example: <a href=https://bit.ly/MathLogicPuzzles>Logic Lovers Math and Logic Problems</a></li> </UL> <table border=1 align=center> <TR> <TD><a href=https://bit.ly/PencilPuzzlesMag><img border="0" src=http://amzn.to/2aoYe5N></a></TD> <TD><a href=https://bit.ly/GamesPuzVariety><img border="0" src=http://amzn.to/2aFn6uI></a></TD> <TD><a href=https://bit.ly/GamesWorldPuzzles><img border="0" src=http://amzn.to/2aDAyxz></a></TD> <TD><a href=https://bit.ly/BestMathPuzzles><img border="0" src=http://amzn.to/2aijGdu></a></TD> </tr> </table> </li> <LI class=LiBold>Math books are great resources, because many problems can be rewritten and randomized to make new puzzles. <UL> <LI class=LiExam>Example: <a href="https://bit.ly/AlgebraTrigText">Algebra and Trigonometry, 5th Edition text</a></li> </UL> <table border=1 align=center> <tr> <td><a href=https://bit.ly/BlitzerAlgebra><img border="0" src=http://amzn.to/2azwu0h></a></td> <TD><a href=https://bit.ly/PracticalAlgebra><img border="0" src=http://amzn.to/2aHoJ7Z></a></TD> <TD><a href=https://bit.ly/AlgebraDummies><img border="0" src=http://amzn.to/2ap0wlr></a></TD> <TD><a href=https://bit.ly/EZalgebra><img border="0" src=http://amzn.to/2aDCNAZ></a></td> </tr> </table> </li> <LI class=LiBold>There are many other sources, ask your math teacher, friends or a librarian for help.
</UL>
<h2>2. Is it okay to use such a <i>found</i> puzzle on your page</h2>
<UL> <LI class=LiBold>Public Domain <UL class=LiExam> <LI>Any puzzle found on the Internet might have been originally copyrighted, so play it safe and don't copy it.</LI> <LI>If you rewrite into your own words, you are probably not in violation of any author's original rights.</LI> <LI>Remember, ignorance of the copyright law is no excuse.</LI> <LI>One way to guess if something is Public Domain is to do a Google Search: <OL> <LI>Search for a specific section of that puzzle, phrase, sentence or more.</LI> <LI>Include quotes before and after so that the search is ONLY on that exact syntax.</LI> <LI>If you get lots of matches, it is probably public domain, but play it safe and either rewrite the puzzle or give credit to the Google Search as a source for the puzzle if you use that exact puzzle.</LI> </OL> </li> </UL> </li> <LI class=LiBold>Request Permission <UL class=LiExam> <LI>If you find a quite detailed puzzle, play it safe and request permission to use the puzzle.</LI> </UL> </Li>
</UL>
<h2>3. Rewrite the Puzzle or Problem into your Own Words</h2>
<UL> <LI class=LiBold>Play it safe and rewrite into your own words <UL class=LiExam> <LI>If you get the idea for a brand new puzzle based on another person's problem page, the original author's copyright no longer covers your version of the puzzle.</LI> <LI>Even if you don't see a copyright and cannot determine authorship, it is safest to write your own version.</LI> <LI>Some puzzles are so involved that, even if rewritten, your version might still violate an author's rights.</LI> <LI>Relatively simple puzzles can be rewritten into a new puzzle that is all yours.</LI> <LI>If in doubt about your ownership, show the original author your version, if authorship can be determined.</LI> </UL> </li>
</UL>
<h2>4. Identify all information that can be randomized</h2>
<UL> <LI>Numbers</LI> <LI>Places</LI> <LI>Group names</LI> <li>et cetera</li>
</ul>
<h2>5. Plan the program to create random puzzles</h2>
<UL> <LI>Do the entire process yourself on paper</LI> <LI>Analyze every step you made as you did the work</li> <LI>Explain every step to a friend</LI> <LI>Pretend to be the computer and present your friend with a puzzle you create randomly</LI> <LI>Outline every step you made, like a flowchart or a list of steps</LI>
</UL>
<h2>6. Create Javascript to create the puzzle itself and display it.</h2>
<UL> <LI>This is why I enrolled in this Coursera Course, to learn this part.</LI> <LI>We will get more into detail on this part of the process down below.</LI>
</UL>
<h1>Let's follow that process with the puzzle from Ganesh's page:</h1>
<h2>1. Here is a puzzle I want to imitate</h2>
<blockquote class=LiBold> The average age of three boys is 15 years. If their ages are in the ratio 3:5:7, what is the age of the youngest boy?
</blockquote>
<UL> <LI>I found this puzzle at <a href=https://maths-tricks-puzzles.blogspot.com>maths-tricks-puzzles.blogspot.com</a></LI>
</ul>
<h2>2. This puzzle is probably in the public domain.</h2>
<UL> <LI>I did a <a href=https://bit.ly/PuzzleGoogleSearch>Google Search</a> and got 207 results, so this puzzle is almost certainly in the public domain ...</LI> <LI>But let's play it safe and rewrite it so we don't accidentally use something that is copyrighted.
</UL>
<h2>3. Rewrite the Puzzle or Problem into Your own Words</h2>
<blockquote class=LiBold> There are ____ people at a _________ meeting.<BR> Except for the youngest and the oldest, they all love ______ puzzles.<BR> Their average age is fifteen.<BR> Their ages have the relative ratio: __________.<BR> How old are the two members who will not solve this puzzle?<P> As you can see, all the blanks can contain random information. In addition, all sentences can have variations if desired.
</blockquote>
<h2>4. What information can be randomized</h2>
<OL> <LI>The number of the people at the event (3, 4, 5, 6, 7, 8, 9)</LI> <LI>The name of the group: (the 'Triple Nine Society'; Mensa; Intertel, the One in a Thousand Society, TOPS)</LI> <LI>The name of a restaurant or place you might eat lunch or dinner (Pizza Hut, Civic Park, Restaurant)</LI> <LI>Type of puzzle you like to solve (math, logic, word, algebra, geometry)</LI> <LI>Average age (to be calculated)</LI> <LI>Ratio of ages (to be calculated)</LI> <LI>The answers (to be calculated)
</ol>
<h2>5. Plan the program to create random puzzles (flowchart, etc.)</h2>
<Blockquote> I learned FORTRAN in 1969, and later learned COBOL, RPG and other languages, but I've been thinking in the old DOS-style BASIC since 1977. I've even dreamed about writing programs, even writing a four-dimensional maze program during a dream one night in the 1980's. (I got up, used that dreamt logic to create a 3D maze, and it worked in real life. Later, I did write the 4D version.) This paragraph is meant to help the reader realize that I took the Coursera course in order to learn Javascript. I already knew BASIC. <P> When I decided to use this for my Coursera project, I stole a puzzle from a friend of mine (with permission) and wrote a <a href=http://QB64.net>QB64.net</a> program to randomly create a few puzzles, to see how it worked. This process will will help me when I get to the point of rewriting the program in Javascript, because I'll already know the logic works. P> The process I went through to write that program is similar to the process you would use to write a program in Javascript, so let's outline the process of writing a program to create the puzzle above. NOTE that my original list of tasks was shorter, but as I tested the program, I found errors I needed to look out for.
</blockquote>
<P>
<OL> <LI>Define the output object (screen in BASIC, image or ??? in Javascript?)</LI> <LI>Be sure the program is random</LI> <LI>Set up storage arrays for ages and ratios</li> <LI>Pick a random Group Name</LI> <LI>Pick a random Restaurant or Place Name</LI> <LI>Pick a random Puzzle Type</LI> <LI>Pick a random number of people to attend the event</LI> <LI>Convert that number to a word for story-description</LI> <LI>Pick a random number to be GCF of all ages in the puzzle</LI> <LI>ERROR ALERT: Be sure # of people and random GCF do not share a common factor</LI> <LI>Generate all the ratios needed for the problem</LI> <LI>Multiply all ratios by the GCF to get all the ages for the problem</LI> <LI>Add up the ages and calculate the average age</LI> <LI>ERROR ALERT: Reject any set of ages where average is not an integer</LI> <LI>ERROR ALERT: Reject any set of ages with triplets, quads, etc.</LI> <LI>Convert ratio values into a ratio string for display</LI> <LI>Display the problem on screen or in window or inside image</li>
</ol>
<P> Here is the updated QB64 program that includes all of the above:
<P>
<PRE class=LiExam>
'COMMENT: (For best readability, expand your page width so that these two comment lines (with all the dashes --------------)
'-------: -----------------: appear full width, the indenting and program comments will be much easier to read as a result.)
'
DEFINT A-S ' All variables that start with A thru S are integers
DEFSTR T-Z ' All variables that start with T thru Z are strings
SCREEN _NEWIMAGE(1920, 1080, 256) ' set SCREEN to half of maximum 2880x1630 resolution
RANDOMIZE TIMER ' This uses seconds since midnight to randomize the random number generator
DIM age(9), ratio(9) ' define arrays to hold random values
' Next 3 lines are the DATA that is used by FUNCTION RandomW$ to pick random info to include in program
zg = "TNS,Triple 9 Society,Intertel,OATHS,One in 1000 Society,TOPS,Top One % Society,Brain Society,Mensa,"
zp = "Math,Number,Arithmetic,Maths,Mathematical,Arithmetical,Algebra,Algebraical,Numeric,"
zr = "Pizza Hut,Subway,Dominos,Wendys,McDonalds,Sonic,Shoneys,Dennys,Central Park,Burger King,Hardees,"
group = 0 ' First "group" is random. Choose specific group number with 1-9 after answer
DO ' DO all code until we press ESCape after seeing the answers bc = INT(RND * 3) * 8 + 24 ' Random function returns 24, 32 (blue) or 40 (red) background color IF bc < 30 THEN bc = 9 ' Change 24 to 9 (blue) background color (all reasonable dark choices) fc = INT(RND * 6) + 10 ' Random foreground color (all reasonable bright choices) COLOR fc, bc ' set foreground and background colors as randomly generated zGroup = RandomW$(zg, group) ' Pick a random group name (might not be in every puzzle generated) zPlace = RandomW$(zr, 0) ' Pick a random eating place (might not be in every puzzle generated) zPtype = RandomW$(zp, 0) ' Pick a random type of puzzle CLS ' Clear Screen, entire screen white DO ' DO all following statements WHILE final statements are true REDIM k(999) ' reDIM array that checks for too many of one age n = INT(RND * 7) + 3 ' How many people in the group zCount = CountWord$(n) ' Get word to use for number of people in puzzle DO: gcf = INT(RND * 4) + 2 ' Greatest Common Factor of their ages LOOP WHILE GCFactor(n, gcf) > 1 ' Do not allow the number of people and the GCF to share a common factor min = INT(RND * 9 + 5) ' Minimum age in group sum = 0 ' sum for calculating average later FOR a = 1 TO n - 1 ' generate ages for all except one person g = INT(min / gcf) * gcf + INT(RND * 9) ' start with the ratio of their ages ratio(a) = g ' and store that value as an individual ratio g = g * gcf: age(a) = g ' then multiply by the GCF to get the person's age sum = sum + age(a): 'PRINT age(a); ' add up the ages (PRINT was used during debugging to see all tries) NEXT ' do this for all 'N' people g = (sum + n) MOD n ' this is minimum possible age for last person in room WHILE g < min OR g MOD gcf ' WHILE that age is invalid g = g + n ' keep adding 'N' to that age until that age is divisible by 'GCF' WEND ' WEND: This is why we did not let 'N' and 'GCF' have a common factor age(n) = g: ratio(n) = g \ gcf ' store that last age and ratio into their arrays sum = sum + g: avg = sum / n ' and calculate the average age 'PRINT age(n); ":"; sum; avg; gcf ' (PRINT used during debugging to see calculated last age, sum, etc. z = "": EC = 0 ' Set up string to remember the relative ratios, and check for errors FOR i = 1 TO n ' FOR every person in the group FOR j = i + 1 TO n ' FOR every other other person in the group IF ratio(i) > ratio(j) THEN ' IF their ages are out of order SWAP ratio(i), ratio(j) ' SWAP the ratios SWAP age(i), age(j) ' SWAP the ages END IF ' end of IF block NEXT ' NEXT - at end of this loop, person 'I' has the correct age values g = age(i) ' this statement saves a few bytes of memory k(g) = k(g) + 1 ' Count how many of each age is in the sorted array IF k(g) > 2 THEN EC = 1 ' If there are more than 2 people of one age, generate an error code z = z + ":" + LTRIM$(STR$(ratio(i))) ' This string contains all the ratio values for later display NEXT ' NEXT 'this loop finishes work for sorting ages into order LOOP WHILE age(n) > 99 OR sum MOD n OR EC ' LOOP until no centennarians, average is valid, & there are no errors ' PROBLEM || Display puzzle including zGroup (group name), zPtype (Puz Type), PRINT ' PUZZLE || zPlace (restaurant/place), zCount (# of people), z (ratio) with ' PRINT || three different types of situation (meeting, lunch, dinner) ' SECTION || and three different questions that mean the same thing; and ' || give credit to the Coursera Homework development page: ptb = 40 tb = " º" + SPACE$(ptb - 3) + "º" PRINT " É"; STRING$(ptb - 3, 205); "»" ' 'Mathematical, 'Central Park, IF RND < .334 THEN PRINT " º There are "; zCount; " people at a"; TAB(ptb); "º" ' There are three people at a PRINT " º "; zGroup; " meeting."; TAB(ptb); "º" ' One in 1000 Society meeting. ELSE IF RND < .5 AND LEN(zGroup) < 12 AND LEN(zPlace) < 9 THEN PRINT " º "; Cap$(zCount); " "; zGroup; " members"; TAB(ptb); "º" ' Three One in 1000 Society members PRINT " º met at "; zPlace; " for lunch."; TAB(ptb); "º" ' met at Central Park for lunch. ELSE PRINT " º "; Cap$(zCount); " friends met for lunch"; TAB(ptb); "º" ' Three friends met for lunch PRINT " º at "; zPlace; " today."; TAB(ptb); "º" ' at Central Park today. END IF END IF PRINT tb ' º 12345678901234567890123456789012345 º IF RND < .5 THEN PRINT " º Except for the youngest and oldest,"; TAB(ptb); "º" ' Except for the youngest and oldest PRINT " º they all love "; zPtype; " puzzles."; TAB(ptb); "º" ' they all love mathematical puzzles. ELSE PRINT " º The youngest and oldest members"; TAB(ptb); "º" ' The youngest and oldest members PRINT " º do not enjoy "; zPtype; " puzzles."; TAB(ptb); "º" ' do not enjoy mathematical puzzles. END IF PRINT tb PRINT " º Their average age is "; CountWord$(avg); "."; TAB(ptb); "º" ' Their average age is seventy-seven. PRINT tb IF RND < .5 THEN PRINT " º Their ages have the relative ratio: º" ' Their ages have the relative ratio: ELSE PRINT " º The ratio between their ages is: º" ' The ratio between their ages is: PRINT " º "; z; TAB(ptb); "º" END IF PRINT tb SELECT CASE INT(RND * 3) CASE 0 PRINT " º How old are the two people who will º" PRINT " º just ask everyone their ages? º" CASE 1 PRINT " º What are the ages of the members º" PRINT " º who won't solve this puzzle? º" CASE 2 PRINT " º How old are the two people who are º" PRINT " º so woefully puzzle-challenged? º" END SELECT PRINT tb ' º 12345678901234567890123456789012345 º PRINT " º bit.ly/HowToCreateRandomPuzzlePages º" PRINT " ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ" PRINT INPUT$(1) ' Pause after displaying puzzle ' PRINT " Youngest:"; age(1); " Oldest:"; age(n) ' Display answers PRINT FOR i = 1 TO n: PRINT STR$(age(i));: NEXT ' Show all of the ages PRINT ": Sum"; sum; " GCF"; gcf ' Print sum and Greatest Common Factor z = INPUT$(1) ' Pause until (1-9 next group), (ESCape) or (any other key random group) group = VAL(z) ' If key pressed is 1-9, next puzzle will include group # that number
LOOP UNTIL z = CHR$(27) ' LOOP: keep generating new puzzles until ESC pressed twice
END ' END of main program
FUNCTION GCFactor (a, b)
FOR c = 1 TO a ' FOR every value of 'c' up to 'a' IF c * (a \ c) = a AND c * (b \ c) = b THEN d = c ' If A and B both divisible by C, then D is GCF of A and B
NEXT ' NEXT value of c
GCFactor = d ' RETURN the value of the greatest common factor
END FUNCTION ' NOTE: If you initialize 'd=1' change FOR loop to '= 2 to a'
FUNCTION CountWord$ (a)
z = "one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thir,four,fif,six,seven,eigh,nine,"
y = "twenty ,thirty ,forty ,fifty ,sixty ,seventy,eighty ,ninety"
w = "" ' W, the tens word, starts out blank
IF a > 19 THEN ' If a ten word is required for 20-something, etc. w = RTRIM$(MID$(y, INT(a / 10) * 8 - 15, 7)) ' W now contains the ten word a = a MOD 10 ' A now contains only the unit digit IF a THEN w = w + "-" ' If A is not zero, add a dash to the tens word
END IF ' End of TEN word IF block --> 'W' now contains ten word
FOR i = 1 TO a ' FOR thru loop until we get to 'A' value (loop skipped if A=0) k = INSTR(z, ",") ' Look for comma inside 'Z' string x = LEFT$(z, k - 1) ' X is equal to the word before the comma z = MID$(z, k + 1) ' Remove that word from beginning of the 'Z' string
NEXT ' NEXT until we get to A --> X now contains unit word (or ten-teen word)
IF a > 12 THEN x = x + "teen" ' This line saved 32 characters of data at cost of less length of code.s
CountWord$ = w + x ' RETURN the combined word for the original 'A' value
END FUNCTION ' END of FUNCTION CALL
</PRE>
<h2>6. Create Javascript to create the puzzle itself and display it.</h2>
<UL> <LI>This is the next part of my project to work on.</LI>
</UL>
</body>
</html>

A Pen by John - Script Codes CSS Codes

h1 {text-align:center;}
h2 {color:blue}
a {font-size:larger}
.LiBold {font-size:larger}
.LiExam {font-size:smaller}
A Pen by John - Script Codes
A Pen by John - Script Codes
Home Page Home
Developer John
Username RetiredPuzzleMathNerd
Uploaded November 16, 2022
Rating 3
Size 8,909 Kb
Views 14,168
Do you need developer help for A Pen by John?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

John (RetiredPuzzleMathNerd) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!