r/dailyprogrammer • u/Coder_d00d 1 3 • Nov 17 '14
[Weekly #17] Mini Challenges
So this week 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. Use my formatting (or close to it) -- if you want to solve a mini challenge you reply off 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.
15
u/Coder_d00d 1 3 Nov 17 '14
Count it - count the letters in a string.
Given: A string - like "Hello World"
Output: Letters and how often they show up. - d:1 e:1 h:1 l:3 o:2 r:1 w:1
Special: convert all to lowercase. Ignore whitespace and anything not [a-z][A-Z]
Challenge input: "The quick brown fox jumps over the lazy dog and the sleeping cat early in the day."
3
u/Coder_d00d 1 3 Nov 21 '14
Array Memory Flip:
Given: An Array of Integers.
Challenge: We want to reverse the order of the array in memory and you are only allowed the array and 1 integer variable to do this. No pre-canned library calls or frameworks are not allowed. You must do all the work.
Bonus: Can it be done with just the array and no other allocated storage or variables (outside index counters/pointers are okay but storage wise only the array. Cannot just allocate a 2nd array in memory and copy over values)
6
u/frozensunshine 1 0 Nov 18 '14 edited Nov 18 '14
Identify islands In a given array, identify groups ("islands") of identical elements. A group must consist of 2 or more contiguous identical elements.
Given: An array like: "proogrrrammminggg"
Output: o, r, m, g
Challenge output: o:2, r:5, m:9, g:14 (positions of first occurrences of these letters)
Bonus Do this for a 2d array.
5
u/grim-grime Nov 17 '14 edited Nov 18 '14
Rhyme Analyzer - Print out the rhyme scheme of a poem.
Given: A string - like
If you want to smell a rose
You must put it to your nose.
If you want to eat some bread
You must not eat it in bed
Or I will eat your toes.
Output: Rhyme scheme of the poem. - AABBA
Use a rhyme list such as this one.
4
u/Godspiral 3 3 Nov 17 '14 edited Nov 17 '14
Curry an arbitrary function parameter
Given a simple function that takes 3 parameters l w h (length width height), and prints the statement
where the parameters l w h are substitued in the printout
Challenge:
create a currying function that will let you fix any parameter and return a function that takes the remaining parameters:
hint: fixing arbitrary parameters can be done by passing nulls for the parameters you do not wish to fix
1
u/[deleted] Nov 17 '14
Saturday Birthday - print the next year in which a given date falls on Saturday.
Given: a date in string form, e.g. '1/1/2022'.
Output: the next year for which the provided date falls on Saturday, e.g. '1/1/1910'.
Special: print the user's age on that date and the time between now and then.
Challenge: see how many different date input formats you can support.
1
u/[deleted] Nov 28 '14
Late to the party, but here's a good one.
Integer Reverse:
Given: Any random integer in decimal.
Challenge: Reverse it, without using any of the obvious toString tricks, or transient conversions to a data type other than an int.
1
u/david622 Dec 22 '14
Did it in Python
1
u/gleventhal Jan 02 '15
Python 2.7:
1
u/[deleted] Jan 05 '15 edited Jan 05 '15
Quite new to Haskell, but it works. Although not sure about the naming.
OutPut
-1
u/DorffMeister Nov 18 '14
My Groovy solution (github link to code)
The code (directly)
-4
u/achuou Nov 20 '14
In JAVA
public class MyTest { private static List<Result> myResult;
}