Lucky and even lucky numbers: Difference between revisions

m
trying to tidy up the task description
(J)
m (trying to tidy up the task description)
Line 1:
{{draft task}}
'''<small>Note that in the following explanation list indices are assumed to start at <code>''one</code>''.</small>'''
 
''';Definition of lucky numbers'''
''[[wp:Lucky number|Lucky numbers]]'' are positive integers that are formed by:
 
*# Form a list of all the positive odd integers > 0<br><math>1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39 ...</math>
''Lucky numbers'' are positive integers that are formed by:
:*# Note then returnReturn the secondfirst number from the list (which is '''31''').
 
*# <small>(Loop begins here)</small>
* Form a list of all the positive odd integers > 0<br><math>1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39 ...</math>
#* ReturnNote then return the firstsecond number from the list (which is '''13''').
:#* Discard every third, (as noted), number from the list to form the new list<br><math>1, 3, 7, 9, 13, 15, 19, 21, 25, 27, 31, 33, 37, 39, 43, 45, 49, 51, 55, 57 ...</math>
* (Loop begins here)
:*# <small>(Expanding the loop a few more times...)</small>
:* Note then return the second number from the list (which is '''3''').
#* Note then return the third number from the list (which is '''7''').
:* Discard every third, (as noted), number from the list to form the new list<br><math>1, 3, 7, 9, 13, 15, 19, 21, 25, 27, 31, 33, 37, 39, 43, 45, 49, 51, 55, 57 ...</math>
:#* Discard every 97<sup>th</sup>, (as noted), number from the list to form the new list<br><math>1, 3, 7, 9, 13, 15, 21, 25, 27, 31, 33, 37, 43, 45, 49, 51, 55, 57, 63, 67, 69, 73 ...</math>
:* <small>(Expanding the loop a few more times...)</small>
:#* Note then return the third4<sup>th</sup> number from the list (which is '''79''').
:#* Discard every 79<sup>th</sup>, (as noted), number from the list to form the new list<br><math>1, 3, 7, 9, 13, 15, 21, 25, 27, 31, 33, 37, 43, 45, 49, 51, 55, 57, 63, 67, 69, 73 ...</math>
:#* Note then returnTake the 45<sup>th</sup>, number from the list (which isi.e. '''913'''). Remove every 13<sup>th</sup>.
:#* Take the 76<sup>th</sup>, i.e. '''2115'''. Remove every 2115<sup>th</sup>.
:* Discard every 9<sup>th</sup>, (as noted), number from the list to form the new list<br><math>1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43, 45, 49, 51, 55, 63, 67, 69, 73 ...</math>
:#* Take the 57<sup>th</sup>, i.e. '''1321'''. Remove every 1321<sup>th</sup>.
:#* Take the 68<sup>th</sup>, i.e. '''1525'''. Remove every 1525<sup>th</sup>.
# <small>(Rule for the loop)</small>
:* Take the 7<sup>th</sup>, i.e. '''21'''. Remove every 21<sup>th</sup>.
:#* TakeNote the 8<math>n</math><sup>th</sup>, i.e.which '''25'''.is Remove every 25<supmath>thm</supmath>.
#* Remove every <math>m</math><sup>th</sup>.
:* ...
#* Increment <math>n</math>.
:* Take the n<sup>th</sup>, which is '''m'''. Remove every m<sup>th</sup>. Increment n
:* ...
 
<br>
'''Definition of even lucky numbers'''
 
''';Definition of even lucky numbers'''
This follows the same rules as the definition of lucky numbers above ''except for the very first step'':
*# Form a list of all the positive '''even''' integers > 0<br><math>2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40 ...</math>
*# Return the first number from the list (which is '''2''').
*# <small>(Loop begins here)</small>
:#* Note then return the second number from the list (which is '''4''').
:#* Discard every 4<sup>th</sup>, (as noted), number from the list to form the new list<br><math>2, 4, 6, 10, 12, 14, 18, 20, 22, 26, 28, 30, 34, 36, 38, 42, 44, 46, 50, 52 ...</math>
:*# <small>(Expanding the loop a few more times...)</small>
:#* Note then return the third number from the list (which is '''6''').
:#* Discard every 6<sup>th</sup>, (as noted), number from the list to form the new list<br><math>2, 4, 6, 10, 12, 18, 20, 22, 26, 28, 34, 36, 38, 42, 44, 50, 52, 54, 58, 60 ...</math>
:#* Take the 4<sup>th</sup>, i.e. '''10'''. Remove every 10<sup>th</sup>.
:#* Take the 5<sup>th</sup>, i.e. '''12'''. Remove every 12<sup>th</sup>.
# <small>(Rule for the loop)</small>
:* ...
:#* TakeNote the <math>n</math><sup>th</sup>, which is '''m'''. Remove every m<supmath>thm</supmath>. Increment n
#* Remove every <math>m</math><sup>th</sup>.
:* ...
#* Increment <math>n</math>.
 
'''task;Task requirements'''
* writeWrite one or two subroutines (functions) to generate ''lucky numbers'' and ''even lucky numbers''
* sinceWrite a command-line interface to allow selection of which kind of numbers and which number(s). Since input is from the command line, tests should be made for the common errors:
::** missing arguments
::** too many arguments
::** number (or numbers) aren't legal
::** misspelled argument ('''lucky''' or '''evenLucky''')
* The command line handling should:
** support mixed case handling of the (non-numeric) arguments
::** support forprinting a particular number
::** support forprinting a range of particular numbers by their index
::** support forprinting a range of numbers by their values
* The resulting list of numbers should be printed on a single line.
 
<br>The program should support the arguments:
'''task requirements'''
* write one or two subroutines (functions) to generate ''lucky numbers'' and ''even lucky numbers''
* which kind of numbers and which number(s) will be specified via the command line or a similar interface.
* since input is from the command line, tests should be made for the common errors
::* missing arguments
::* too many arguments
::* number (or numbers) aren't legal
::* misspelled argument ('''lucky''' or '''evenLucky''')
::* mixed case should be supported
::* support for a particular number
::* support for a range of particular numbers
::* support for a range of values
<br>The program should support the arguments:
<pre>
what is displayed (on a single line)
Line 74:
where |k| is the absolute value of k
</pre>
Demonstrate the program by:
Specifically:
* showshowing the first twenty ''lucky'' numbers
* showshowing the first twenty ''even lucky'' numbers
* showshowing all ''lucky'' numbers between 6,000 and 6,100 (inclusive)
* showshowing all ''even lucky'' numbers in the same range as above
* showshowing the 10,000<sup>th</sup> ''lucky'' number (extra credit)
* showshowing the 10,000<sup>th</sup> ''even lucky'' number (extra credit)
<br>
 
;See also:
Line 89 ⟶ 88:
* Sequence [https://oeis.org/A045954 A045954 even lucky numbers or ELN] on The On-Line Encyclopedia of Integer Sequences.
* Entry [http://mathworld.wolfram.com/LuckyNumber.html lucky numbers] on The Eric Weisstein's World of Mathematics.
* Wiki entry [http://en.wikipedia.org/wiki/Lucky_number lucky_number].
<br>
 
=={{header|J}}==
Anonymous user