Board Logo
« Search Results »

Welcome Guest. Please Login or Register.
Apr 24th, 2017, 3:52pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ


Search Results

Total results: 10


 1   JB Programming Discussions / Re: how many jumps  on: Today at 3:43pm
Started by zzz000abc | Post by bplus
Here is a version using iif function:
Code:
input "Jump height = ";up
input "Slide down  = ";down
input "Number of walls = ";nWalls
advance = up - down
for w = 1 to nWalls
    print "For wall ";w; : input ", enter height = ";wall
    remain = wall - up
    j = j + 1 + iif(remain > 0, int(remain/advance) + (remain mod advance <> 0), 0)
next
print "Total jumps = ";j

function iif(bool, tValue, fValue)
    if bool then iif = tValue else iif = fValue
end function
 

 
  Reply Quote Notify of replies

 2   JB Programming Discussions / Re: how many jumps  on: Today at 12:41pm
Started by zzz000abc | Post by zzz000abc
on Today at 12:01pm, bplus wrote:
I like this line!
Code:
 j=((hh-r)/(x-y))+(r<>0)+(h>=x) 


Inspired by Rod
from here [url=http://justbasic.conforums.com/index.cgi?board=code&action=display&num=1492436827][/url]
in reply #3
Quote:
I had to figure out why decimals weren't popping up

remainder is subtracted.
 
  Reply Quote Notify of replies

 3   JB Programming Discussions / Re: how many jumps  on: Today at 12:01pm
Started by zzz000abc | Post by bplus
Thanks for explanation for walls of 0 height. OK I can accept that. ;-))

I like this line!
Code:
j=((hh-r)/(x-y))+(r<>0)+(h>=x) 


I had to figure out why decimals weren't popping up.
 
  Reply Quote Notify of replies

 4   JB Programming Discussions / Re: how many jumps  on: Today at 02:23am
Started by zzz000abc | Post by zzz000abc
Quote:
Another problem, try this for input:

5 1 1 999999999999999


here is the solution Code:
input"values";v$
x=val(word$(v$,1))

y=val(word$(v$,2))

ind=val(word$(v$,3))
dim h(ind+1),a(ind+1)
print ind
for i=1 to ind
h(i)=val(word$(v$,i+3))
next
for i=1 to ind
j=0
h=h(i)
if h=0 then
j=1
else
if h>=x then hh=h-x else hh=h
r=hh mod (x-y)
j=((hh-r)/(x-y))+(r<>0)+(h>=x)
end if
a(i)=j
next
for i=1 to ind
print a(i),
kk=kk+a(i)
next
print
print "total jumps";kk
 


edit 1. zero height is also considered. for example you may have 11inch wall ie., wall of 0 ft height.
edit 2. on the other hand if there no wall at all then also we can say it's zero height wall but we should not enter this zero in input.if so there will be infinite walls of zero height. so when we enter zero for wall height we assume the case similar to one described in edit1.
 
  Reply Quote Notify of replies

 5   JB Programming Discussions / Re: how many jumps  on: Yesterday at 3:08pm
Started by zzz000abc | Post by bplus
Another problem, try this for input:

5 1 1 999999999999999
 
  Reply Quote Notify of replies

 6   JB Programming Discussions / Re: how many jumps  on: Yesterday at 1:44pm
Started by zzz000abc | Post by bplus
How about when the "walls" are negative in height, then they are ditches/rivers/moats the hero has to jump across them.

Make the jumps parabolic with dx and dy calculations involving gravity.
 
  Reply Quote Notify of replies

 7   JB Programming Discussions / Re: how many jumps  on: Yesterday at 1:41pm
Started by zzz000abc | Post by zzz000abc
Quote:
Error when wall height is 1

Now it works
Code:
input"values";v$
x=val(word$(v$,1))

y=val(word$(v$,2))

ind=val(word$(v$,3))
dim h(ind+1),a(ind+1)
print ind
for i=1 to ind
h(i)=val(word$(v$,i+3))
next
for i=1 to ind
j=0
while j*(x-y)<h(i)
if j<>0 and ((j*x)-((j-1)*y))>=h(i)then exit while
j=j+1
wend
a(i)=j
next
for i=1 to ind
print a(i),
k=k+a(i)
next
print
print "total jumps";k
 

 
  Reply Quote Notify of replies

 8   JB Programming Discussions / Re: how many jumps  on: Yesterday at 1:24pm
Started by zzz000abc | Post by zzz000abc
on Yesterday at 12:00pm, bplus wrote:
Well I hope y is always < x OR x > wall.

yes B+ you are right.
Quote:
Here is zzz000abc's code with more descriptive variable names and more wordy reporting

nice B+ ,actually I am thinking to make it a game using graphics.
It can be like this: thief should run trying to escape jumping over the walls ,user should shoot him arrows or with gun.

 
  Reply Quote Notify of replies

 9   JB Programming Discussions / Re: how many jumps  on: Yesterday at 12:47pm
Started by zzz000abc | Post by bplus
Here is zzz000abc's code with more descriptive variable names and more wordy reporting:
Code:
print "Enter all values seperated by spaces:"
print "jumpHeight slideDownDistance nWalls wallHeight1 wallHeight2 wallHeight3... "
input "> ";values$
upDistance = val(word$(values$,1))
downDistance = val(word$(values$,2))
nWalls = val(word$(values$,3))
dim wallHeights(nWalls+1),jumps(nWalls+1)
print "Number of walls ";nWalls
for i=1 to nWalls
   wallHeights(i)=val(word$(values$,i+3))
next
for i=1 to nWalls
    j=0
    while j*(upDistance-downDistance) < wallHeights(i)
        if ((j*upDistance)-((j-1)*downDistance)) >= wallHeights(i)then exit while
        j = j+1
    wend
    jumps(i) = j
next
for i=1 to nWalls
    print "For wall ";i;" the number of jumps is ";jumps(i)
    totJumps = totJumps + jumps(i)
next
print
print "Total jumps ";totJumps
 


Output:
Code:
Enter all values seperated by spaces:
jumpHeight slideDownDistance nWalls wallHeight1 wallHeight2 wallHeight3...
> 5 1 2 9 10
Number of walls 2
For wall 1 the number of jumps is 2
For wall 2 the number of jumps is 3

Total jumps 5
 


Error when wall height is 1:
Code:
Enter all values seperated by spaces:
jumpHeight slideDownDistance nWalls wallHeight1 wallHeight2 wallHeight3...
?5 1 1 1
Number of walls 1
For wall 1 the number of jumps is 0

Total jumps 0
 

 
  Reply Quote Notify of replies

 10   JB Programming Discussions / Re: how many jumps  on: Yesterday at 12:00pm
Started by zzz000abc | Post by bplus
Well I hope y is always < x OR x > wall. I predict (assuming x < wall) jumps equals int((wall - x) / (x-y)) + 1 if (x-y) divides (wall - x), if not, add one more jump .
 
  Reply Quote Notify of replies


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Just BASIC wiki
Wikispaces

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls