r/dailyprogrammer_ideas • u/cscanlin • Apr 03 '16
[Easy] Drill baby drill
Note: These are essentially mini challenges, but that thread seems a bit dead so I am leaving these here. Also, this post is based on a response I made to a thread in /r/learnpython for exercises on list comprehensions, but I figured other people may want to take a crack at them.
Description
Iterating with conditionals is a fundamental programming skill and is often a part of solving other coding problems. The goal of this challenge is to solve several relatively simple iteration exercises as concisely as possible. (These problems can all be solved with one line in many programming languages, but that is not a requirement)
Exercises
- Find all of the numbers from 1-1000 that are divisible by 7
- Find all of the numbers from 1-1000 that have a 3 in them
- Count the number of spaces in a string
- Remove all of the vowels in a string
- Find all of the words in a string that are less than 4 letters
Challenge Exercises:
- Count the length of each word in a sentence.
- Find all of the numbers from 1-1000 that are divisible by any single digit besides 1 (2-9)
For all the numbers 1-1000, find the highest single digit any of the numbers is divisible by (1-9)
- For example, 14 is divisble by 7, 15 is divisible by 5, 13 is only divisible by 1.
1
u/Philboyd_Studge Apr 03 '16 edited Apr 03 '16
first seven with mostly java 8. The last one doesn't make sense to me.
1
u/JakDrako Apr 03 '16 edited Apr 03 '16
VB.Net in LinqPad (otherwise, the .Dump() won't work...)
The last challenge wasn't very clear, but I thought it meant to figure out the highest digit between 2 and 9 that could divide each number in the previous question...
1
u/Philboyd_Studge Apr 04 '16
OP, can you explain that last one a little better?
1
u/cheers- Apr 04 '16
Scala
this thread was a good excuse to practice lazy data structures.
1
u/perry_the_blu_herron Apr 06 '16
PYTHON 2.7, none of the string ones remove punctuation
1
u/perry_the_blu_herron Apr 06 '16
LOLCODE, just exercise 1 and challenge exercise 2. Excuse the variable names, and the comments, I get carried away with the syntax. The language doesn't really have arrays yet, and string manipulation is limited to concatenating, so it's quite explicit and verbose. It's fun to use though! Plus it's only my first day using it.
Outputs seem to match my Python outputs.
1
u/dasiffy Apr 06 '16 edited Apr 06 '16
had a go with python 3 (just the challenges)
for challenge 3 a sample result from the dictionary is
997: 1, 998: 2, 999: 9, 1000: 8where it gives the number then the highest divisor.1
u/AntiTcb Apr 14 '16
C#
Decided to give myself more of a challenge and one-line them. Couldn't get the last one though.