Author Topic: (Challenge) Time travel  (Read 5402 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(Challenge) Time travel
« on: March 02, 2005, 10:45:46 AM »
Write a program that returns the time traveled in the speed of light and the speed of sound given a distance in either miles or kilometers.

Pseudo code:
Code: [Select]

Enter distance (e.g. 100m or 100k):
- or -
Enter distance:
Is that [Miles Kilometers]:
distance / speed of light
distance / speed of sound
output
travel time at light =
travel time at sound =
TheSwamp.org  (serving the CAD community since 2003)

nivuahc

  • Guest
(Challenge) Time travel
« Reply #1 on: March 02, 2005, 11:39:22 AM »
Code: [Select]
(defun c:speed ( / )
  (setq user_distance (getreal "\nDistance to travel, in miles: "))
  (princ (strcat "\nTravel time at light speed = " (rtos (/ user_distance 299792458.0) 2 9) " seconds"))
  (princ (strcat "\nTravel time at speed of sound = " (rtos (/ user_distance 340.29) 2 9) " seconds"))
  (princ)
  )

nivuahc

  • Guest
(Challenge) Time travel
« Reply #2 on: March 02, 2005, 11:57:59 AM »
Code: [Select]
(defun c:speed ( / measurement_key user_distance)
  (setq measurement_key (strcase (getstring "\nWould you like to calculate for [M]iles or [K]ilometers? ")))
  (setq user_distance (getreal "\nDistance to travel: "))
  (cond
    ((= measurement_key "M")
     (princ (strcat "\nTravel time at light speed = " (rtos (/ user_distance 299792458.0) 2 9) " seconds"))
     (princ (strcat "\nTravel time at speed of sound = " (rtos (/ user_distance 340.29) 2 9) " seconds"))
     (princ))
    ((= measurement_key "K")
          (princ (strcat "\nTravel time at light speed = " (rtos (/ (* user_distance 0.62) 299792458.0) 2 9) " seconds"))
     (princ (strcat "\nTravel time at speed of sound = " (rtos (/ (* user_distance 0.62) 340.29) 2 9) " seconds"))
     (princ))
    ((t (princ "\nInvalid distance type. Select M or K at the prompt!") (c:speed)))
    )
  )



;; 1km = 0.62m
;; speed of light = 299792458.0 miles per second
;; speed of sound = 340.29 miles per second

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(Challenge) Time travel
« Reply #3 on: March 02, 2005, 12:05:42 PM »
;; speed of light = 299792458.0 miles per second

I do believe that's the speed of light in meters per second.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

nivuahc

  • Guest
(Challenge) Time travel
« Reply #4 on: March 02, 2005, 12:07:06 PM »
:oops: oops!

nivuahc

  • Guest
(Challenge) Time travel
« Reply #5 on: March 02, 2005, 12:17:06 PM »
Okay, my math is wrong, obviously, and I should check for the M or K before I ask for the distance.

That should be enough, however, for someone to either massacre or build on.  :moon:


Waddaya 'spect for a quickie?  :twisted:

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
(Challenge) Time travel
« Reply #6 on: March 02, 2005, 12:37:02 PM »
So i dont get it.

If i traveled 1hr and 120 miles how long would it have taken light and sound to travel that same distance?!  *Phew* Im lost.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

nivuahc

  • Guest
(Challenge) Time travel
« Reply #7 on: March 02, 2005, 12:39:40 PM »
The way I understood it is that

1. You have a distance to travel

2. How fast could you get there if you travelled at the speed of light?

3. How fast could you get there if you travelled at the speed of sound?


I might have misunderstood, of course (I mean, I assumed the m meant miles for goodness sake!).

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(Challenge) Time travel
« Reply #8 on: March 02, 2005, 01:29:01 PM »
Quote from: nivuahc
The way I understood it is that

1. You have a distance to travel

2. How fast could you get there if you travelled at the speed of light?

3. How fast could you get there if you travelled at the speed of sound?

you are correct.

for example to travel 100 miles at the speed of light it would take you 0.0005 seconds, approximately.
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(Challenge) Time travel
« Reply #9 on: March 02, 2005, 02:09:22 PM »
Light travels approximately one foot in a nano second; I always enjoyed that factoid.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Birdy

  • Guest
(Challenge) Time travel
« Reply #10 on: March 02, 2005, 02:41:12 PM »
:blink:
Slow day, eh?
You guys are to much.
 :)
c=3.0X10^8 meters/second (if I remember correctly)
aprox 186,000 miles/second

Sound varies, proportional to the density of the media. (=0 in space...
that's why "in space, nobody can hear you scream.")

aprox. 750 miles/hour in "dry" air at sea level.
FWIW

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(Challenge) Time travel
« Reply #11 on: March 02, 2005, 02:47:10 PM »
In addition to what Birdy said. For calculating the speed of sound you can use 1135.07947 feet per second or 774.98 miles per hour. That's in dry air at 75°f.

Source:http://hyperphysics.phy-astr.gsu.edu/hbase/sound/souspe.html
TheSwamp.org  (serving the CAD community since 2003)

Birdy

  • Guest
(Challenge) Time travel
« Reply #12 on: March 02, 2005, 03:38:17 PM »
meh. I forgot it's also temperature dependent.
been quite awhile.

ronjonp

  • Needs a day job
  • Posts: 7529
(Challenge) Time travel
« Reply #13 on: March 02, 2005, 04:37:42 PM »
Here is my spin off of Nivuahc first post:


Code: [Select]

(defun c:speed ( / u-lunits ltspd sndspd user_distance)
(setq u-lunits (getvar 'lunits))
(setvar 'lunits 2)


(if (not *defaultFILTER*)
  (setq *defaultFILTER* "Miles")
)
(initget 0 "Miles Kilometers")
(setq P
       (cond
((getkword
   (strcat
     "\n Calculate distance in (K)ilometers or (M)iles? <Hit Enter for "
     *defaultFILTER*
     ">: "
   )
 )
)
(*defaultFILTER*)
   )
)
(setq *defaultFILTER* P)



(cond ((= P "Miles")
       (setq prmpt "miles"
    ltspd  670616640
    sndspd 774.98
       )
      )
      ((= P "Kilometers")
       (setq prmpt "kilometers"
    ltspd  1079252865.88416
    sndspd 1247.209413
       )
      )
     )

(setq user_distance (getdist (strcat "\nPick or enter distance to travel in " prmpt " :")))
  (alert
  (strcat
"\nTime to travel " (rtos user_distance) " " prmpt " at the speed of light = "
"\n"  (rtos (* (/ user_distance ltspd) 3600) 2 11) " seconds"
"\n" (rtos (* (/ user_distance ltspd) 60) 2 11) " minutes"
"\n" (rtos (/ user_distance ltspd) 2 11) " hours"
"\n" (rtos (/ (/ user_distance ltspd) 24) 2 11) " days"
"\n"
"\nTime to travel " (rtos user_distance) " " prmpt " at the speed of sound = "
"\n"  (rtos (* (/ user_distance sndspd) 3600) 2 5) " seconds"
"\n" (rtos (* (/ user_distance sndspd) 60) 2 5) " minutes"
"\n" (rtos (/ user_distance sndspd) 2 5) " hours"
"\n" (rtos (/ (/ user_distance sndspd) 24) 2 5) " days"
)
)
(setvar 'lunits u-lunits)
)




I came to the conclusion....I'm a dork.  :lol:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(Challenge) Time travel
« Reply #14 on: March 03, 2005, 07:50:55 AM »
My stab at it.
Code: [Select]

(defun c:traveltimes (/ spOl spOs str dist)

  (setq spOl 186000.000 ; miles per second
        spOs 774.98     ; miles per hour
        )

  (textscr)

  (prompt "\nTo calcuate travel times enter a distance in")
  (prompt "\nmiles or kilometers. e.g.1000m(iles) or 1000k(ilometers)")

  (if
    (setq str (getstring T "\nEnter distance: "))
    (progn
      (setq str (strcase str T))
      (cond
        ((= (vl-string-position (ascii "m") str) (1- (strlen str)))
         (setq dist (atof (vl-string-right-trim "m" str)))
         (princ
           (strcat "Traveling @ the speed of light would take "
                   (rtos (/ dist spOl))
                   " seconds \n"
                   "Traveling @ the speed of sound would take "
                   (rtos (/ dist spos))
                   " hours \n"
                   )
           )
         )
        ((= (vl-string-position (ascii "k") str) (1- (strlen str)))
         (setq dist (atof (vl-string-right-trim "k" str)))
         (princ
           (strcat "Traveling @ the speed of light would take "
                   (rtos (/ (* dist 0.621) spOl))
                   " seconds \n"
                   "Traveling @ the speed of sound would take "
                   (rtos (/ (* dist 0.621) spos))
                   " hours"
                   )
           )
         )
        (T (prompt "You obviously can't follow instructions!!")
           (prompt "\nTry using 1000m or 1000k")
           )
        )
      )
    )
  (princ)
  )



Output
Code: [Select]

Command: traveltimes
To calcuate travel times enter a distance in
miles or kilometers. e.g.1000m(iles) or 1000k(ilometers)
Enter distance: 150000m
Traveling @ the speed of light would take 0.8065 seconds
Traveling @ the speed of sound would take 193.5534 hours
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(Challenge) Time travel
« Reply #15 on: March 03, 2005, 01:52:11 PM »
Here's a C++ version.

Code: [Select]

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main(int argc, char * argv[])
{
    // configure inline arguments
    if (argc != 2)
    {
cout << "Enter a number followed by either a 'm' for miles\n";
cout << "or a 'k' for kilometers.  Example 1000m\n";
cerr << "Usage: " << argv[0] << " number(m/k)\n";
exit(1);
    }

    string str(argv[1]);
    float spol = 186000.00;
    float spos = 774.98;
    int strl = (str.size() - 1);

    if (str.find("m") == strl)
    {
float dist = atof(str.c_str());
cout << "Traveling @ the speed of light would take \n";
cout << dist / spol << " seconds to travel " << dist;
cout << " miles." << endl;

cout << "\nTraveling @ the speed of sound would take \n";
cout << dist / spos << " hours to travel " << dist;
cout << " miles." << endl;
    }

    else if (str.find("k") == strl)
    {
float dist = atof(str.c_str());
cout << "\nTraveling @ the speed of light would take \n";
cout << (dist * 0.621) / spol << " seconds to travel " << dist;
cout << " kilometers." << endl;

cout << "\nTraveling @ the speed of sound would take \n";
cout << (dist * 0.621) / spos << " hours to travel " << dist;
cout << " kilometers." << endl;
    }

    else
cout << "\nSorry I don't understand this -> (" << str << ") input";

    return 0;
}


Output

Code: [Select]

D:\>traveltime 1500m
Traveling @ the speed of light would take
0.00806452 seconds to travel 1500 miles.

Traveling @ the speed of sound would take
1.93553 hours to travel 1500 miles.
TheSwamp.org  (serving the CAD community since 2003)

t-bear

  • Guest
(Challenge) Time travel
« Reply #16 on: March 03, 2005, 03:16:33 PM »
Just a little FYI.  Here's how long it'd take me to get home:
Quote
Enter distance: 45m
Traveling @ the speed of light would take 0.00024194 seconds
Traveling @ the speed of sound would take 0.05806601 hours

At the speed of "old Dodge pickup", it takes just under one hour......... :roll: