r/dailyprogrammer • • Jul 20 '12
[7/18/2012] Challenge #79 [easy] (Counting in steps)
Write a function step_count(a, b, steps) that returns a list or array containing steps elements, counting from a to b in steps of an equal size. steps is a positive integer greater than or equal to 2, a and b are floating point numbers.
For example:
step_count(18.75, -22.00, 5)
==> [18.75, 8.5625, -1.625, -11.8125, -22.0]
step_count(-5.75, 12.00, 5)
==> [-5.75, -1.3125, 3.125, 7.5625, 12.0]
step_count(13.50, -20.75, 3)
==> [13.5, -3.625, -20.75]
step_count(9.75, 3.00, 9)
==> [9.75, 8.90625, 8.0625, 7.21875, 6.375, 5.53125, 4.6875, 3.84375, 3.0]
17
Upvotes
3
u/[deleted] Jul 20 '12
(I copied the wrong date for today's challenges... It's [7/20/2012] today! Whoops.)
4
u/semicolondash Jul 21 '12 edited Jul 22 '12
C++ Really nothing special here.
C#: (yeah one line)
3
u/akadeco Jul 21 '12
Ruby:
Python:
4
u/lawlrng 0 1 Jul 20 '12 edited Jul 21 '12
Another Python
Edit: I'm a goober.
2
u/sleepingsquirrel Jul 25 '12
J
examples:
1
u/pantera975 Jul 20 '12
PHP
1
u/ander1dw Jul 20 '12
Java:
1
u/Nurry Jul 20 '12
haskell:
1
u/5outh 1 0 Jul 20 '12 edited Jul 20 '12
2 lines of Haskell (could be truncated to 1):
stepCount 18.75 (-22.00) 5 outputs:
1
u/goldjerrygold_cs Jul 20 '12
Python:
1
u/grondo4 Jul 20 '12
C#
Output: 18.75 8.5625 -1.625 -11.8125 -22.0
Can be trimmed down A LOT
1
u/taterNuts Jul 20 '12
C#:
1
u/[deleted] Jul 20 '12
Python:
1
u/234324 Jul 20 '12
C
1
u/JCorkill Jul 20 '12
Java:
1
u/Eddonarth Jul 20 '12 edited Jul 22 '12
Java:
Output:
Edit: Thanks ander1dw
1
u/[deleted] Jul 20 '12
C++:
1
u/GZalpha Jul 20 '12
Python:
1
u/Erocs Jul 20 '12
Python 2.6
Output:
1
u/brenny87 Jul 21 '12
C#
1
u/[deleted] Jul 21 '12
Java:
1
u/manpages Jul 21 '12
Not very accurate function signature, though it was first time to stretch my C++ muscles in a while.
C++
1
u/Mysidic Jul 22 '12
Common LISP:
1
u/incf Jul 23 '12
Common Lisp:
1
u/SPxChairman 0 0 Jul 23 '12
Java: Probably could have been shorter, but I am kind of a newbie :D
1
u/[deleted] Jul 26 '12
C++:
1
u/Paanini Aug 02 '12
Using a For..loop in Python:
1
u/swarage 0 0 Aug 05 '12
this python code works relatively well (except that is prints 5 steps when asked for 3), however it is quite brute forced and is ugly:
1
u/robin-gvx 0 2 Aug 13 '12
1
u/SwimmingPastaDevil 0 0 Jul 20 '12 edited Jul 20 '12
Output:
Edit: 1-liner version
1
u/Scroph 0 0 Jul 20 '12 edited Jul 20 '12
D :
Hackish and overcomplicated code. I'm ashamed of myself.
1
u/liam_jm Jul 20 '12
Python:
0
u/404ram Jul 30 '12
Python - this solution might already have been there....but la!,this is mine
0
u/[deleted] Jul 20 '12
[deleted] — view deleted comment
1
u/[deleted] Jul 20 '12
[removed] — view removed comment