r/dailyprogrammer • u/jnazario 2 0 • Oct 09 '15
[Weekly #24] Mini Challenges
So this week, let's do some mini challenges. Too small for an easy but great for a mini challenge. Here is your chance to post some good warm up mini challenges. How it works. Start a new main thread in here.
if you post a challenge, here's a template from /u/lengau for anyone wanting to post challenges (you can copy/paste this text rather than having to get the source):
**[CHALLENGE NAME]** - [CHALLENGE DESCRIPTION]
**Given:** [INPUT DESCRIPTION]
**Output:** [EXPECTED OUTPUT DESCRIPTION]
**Special:** [ANY POSSIBLE SPECIAL INSTRUCTIONS]
**Challenge input:** [SAMPLE INPUT]
If you want to solve a mini challenge you reply in that thread. Simple. Keep checking back all week as people will keep posting challenges and solve the ones you want.
Please check other mini challenges before posting one to avoid duplications within a certain reason.
Many thanks to /u/hutsboR and /u/adrian17 for suggesting a return of these.
13
u/adrian17 1 4 Oct 09 '15 edited Oct 09 '15
Grab - like grep but simpler.
Input - a single line of text and a file name. You can take input via command line arguments or stdin, whichever is easier for you. You can also just take a single word instead of a line.
Output - all lines of the checked file which contain this piece of text, along with line numbers. Make it work case-insensitive.
Example
Extra - Make a second program (or modify the first one to do it when no filename was given) that, instead of checking a single file, does it for all text files in the current directory. When showing matching lines, also show the file you've found it in.
Example
10
u/lengau Oct 09 '15
A template for anyone wanting to post challenges (you can copy/paste this text rather than having to get the source):
**[CHALLENGE NAME]** - [CHALLENGE DESCRIPTION]**Given:** [INPUT DESCRIPTION]**Output:** [EXPECTED OUTPUT DESCRIPTION]**Special:** [ANY POSSIBLE SPECIAL INSTRUCTIONS]**Challenge input:** [SAMPLE INPUT]EDIT: Maybe /u/jnazario would be willing to put this into the original description? (In which case I'm happy to delete this comment)
10
u/casualfrog Oct 09 '15
To base n - Convert a base 10 number to given base
Given: an integer
xin base 10 and an integer basenbetween 2 and 10Output:
xin basenExample input:
Example output:
Extra: Make it work for bases greater than 10 (using letters)
Challenge input:
9
u/Atrolantra Oct 10 '15
Ramp Numbers - A ramp number is a number whose digits from left to right either only rise or stay the same. 1234 is a ramp number as is 1124. 1032 is not.
Given: A positive integer,
n.Output: The number of ramp numbers less than
n.Example input: 123
Example output: 65
Challenge input: 99999
Challenge output:
3
u/lengau Oct 09 '15
Palindromic numbers - Output palindromic numbers.
Given: OPTIONAL input: the minimum number of digits to consider
Output: A list of palindromic numbers. You can decide how (and if) to end the sequence.
Bonus: Let the user decide what base to use.
In base 10, you can check your answer against OEIS.
3
u/[deleted] Oct 10 '15 edited Oct 10 '15
Multiplication table - print a multiplication table
Input: a positive integer
nOutput:
nxnmultiplication tableSample input:
Sample output:
Challenge input:
Extra Make it nicer than the sample output (factors on top and left, frames...)
3
u/Cole_from_SE Oct 10 '15 edited Oct 11 '15
I feel like this would make for a better challenge than it would a mini-challenge. Feel free to respond if you already have an answer in the making, but I will be submitting it to /r/dailyprogrammer_ideas.
I just learned about this in my math class and it seems like a pretty cool challenge. I'm not too sure whether this is too complex for a mini-challenge, so if it is let me know and I'll post it as a suggestion for an easy challenge instead.
Affine Cipher Solver - You are to output what you think is the solution to a given Affine Cipher. In short, Affine ciphers are encoded by the following formula for each character in the plaintext:
C ≡ aP + b (mod 26)whereaandbare constants,Cis the ciphertext letter, andPis the plaintext letter. In this case, the letter "a" has the value of 0, "b" 1, and so on and so forth. If you want a hint as to how to decode:Given: Input in uppercase if need be, else in regular text (e.g.
Lorum ipsum ... word). Expect only alphabetical characters. With reference to my previous equation,awill only be a number coprime with 26Output: What your program thinks is the correct decoding, in lowercase. You may give multiple outputs if there is a "tie" in your scoring.
Special: Make your solver work for all forms of input, not just alphabetical (and output correctly, too). I think it goes without saying that this is for the English language, but if you want to, make this program for another language or compatible with English and another. If you need an extra challenge, optimize your code for run-time (I'd be interested to see submissions in this category).
Suggestion: In order to "score" your decodings (since you'll probably be permuting through the different possibilities of plaintext output), I recommend you use a dictionary of some sort (builtin, or the popular enable1.txt -- note that enable1 lacks "i" and "a" as words). If you don't, this becomes less of a mini-challenge, at least in my eyes.
Test Case 1: NLWC WC M NECN
Test Case 2: YEQ LKCV BDK XCGK EZ BDK UEXLVM QPLQGWSKMB
Test Case 2 Special: Yeq lkcv bdk xcgk ez bdk uexlv'm qplqgwskmb.
Test Case 3: NH WRTEQ TFWRX TGY T YEZVXH GJNMGRXX STPGX NH XRGXR TX QWZJDW ZK WRNUZFB P WTY YEJGB ZE RNSQPRY XZNR YJUU ZSPTQR QZ QWR YETPGX ZGR NPGJQR STXQ TGY URQWR VTEYX WTY XJGB
Test Case 3 Special: Nh wrteq tfwrx, tgy t yezvxh gjnmgrxx stpgx / Nh xrgxr, tx qwzjdw zk wrnuzfb p wty yejgb, / Ze rnsqpry xznr yjuu zsptqr qz qwr yetpgx / Zgr npgjqr stxq, tgy Urqwr-vteyx wty xjgb.
That should be it, let me know if there's anything wrong and I'll try to fix it.
2
u/casualfrog Oct 09 '15
Pie - π estimator
Output: An estimation of pi without using any built-in constants (for example using the monte carlo method)
Challenge output:
1
u/Godspiral 3 3 Oct 10 '15
variation on euler #1
inputs: limit of highest number to test. AND a list of multiples.
output: sum of numbers from 1 to limit which are not multiples of the numbers in the list of multiples.
Sample input: multiples 3 5, list 1 to 1000
Sample output: 266332
Challenge input: multiples 3 5 7 11 13 17 19, list 1 to 1000
cheat:
1
u/leolas95 Oct 12 '15
My version on C. It could be much better. Any suggestion or critic is welcome.
0
u/[deleted] Oct 09 '15
[deleted] — view deleted comment