• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Ruby Challenge!

Scheduled Pinned Locked Moved Developers' Forum
26 Posts 8 Posters 2.9k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    RickW
    last edited by 28 Nov 2007, 23:45

    It's been a long time since there was a ruby challenge, so I thought I'd offer one.

    Kudos to the authors who can create a single-line "jukebox" that uses UI.play_sound(filename) to play all the sounds in the system sounds folder in sequence, with an indication of the file number and name. Each sound must be distinctly heard in its entirety without interruption from other system sounds or alerts. There is no penalty for using semicolons.

    The author who submits the shortest code will get extra kudos. πŸ˜„

    PM your solutions to me by noon GMT-6 Friday, 3 August 2007 for consideration.

    The length of the directory path will not be considered when checking the code length.

    RickW
    [www.smustard.com](http://www.smustard.com)

    1 Reply Last reply Reply Quote 0
    • T Offline
      todd burch
      last edited by 28 Nov 2007, 23:45

      Good challenge! Count me in.

      Todd

      1 Reply Last reply Reply Quote 0
      • K Offline
        Krisidious
        last edited by 28 Nov 2007, 23:46

        I'm going to make this sticky for 7 days...

        good luck all... can't wait to see what you come up with...

        By: Kristoff Rand
        Home DesignerUnique House Plans

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by 28 Nov 2007, 23:46

          Does SketchUp need to remain usable while the sounds are playing?

          Hi

          1 Reply Last reply Reply Quote 0
          • R Offline
            RickW
            last edited by 28 Nov 2007, 23:47

            I don't see that as a requirement, but if you want to implement it, you may get extra kudos.

            The song number and title may be indicated anywhere you like, but if you use popup boxes, remember they often 'ding' when they appear, and that sound must not interfere with the track being played.

            RickW
            [www.smustard.com](http://www.smustard.com)

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by 28 Nov 2007, 23:47

              It's the "without interruption from other system sounds or alerts" that's killing me.

              Hi

              1 Reply Last reply Reply Quote 0
              • R Offline
                RickW
                last edited by 28 Nov 2007, 23:47

                Yes, it's definitely a challenge...

                RickW
                [www.smustard.com](http://www.smustard.com)

                1 Reply Last reply Reply Quote 0
                • R Offline
                  RickW
                  last edited by 28 Nov 2007, 23:48

                  So far, we have three entries, all with distinct solutions. Only 3 days left to enter...

                  RickW
                  [www.smustard.com](http://www.smustard.com)

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    todd burch
                    last edited by 28 Nov 2007, 23:48

                    Well, count me out. Didn't get to it. Next time!

                    Todd

                    1 Reply Last reply Reply Quote 0
                    • R Offline
                      RickW
                      last edited by 28 Nov 2007, 23:49

                      Okay, here are the results, sorted by order of submission, path-coded for Windows XP:

                      @rickw said:

                      147 characters, 5 semicolons

                      (f=Dir["C;/Windows/Media/*.wav"]).sort!;i=0;t=UI.start_timer(3,true){puts "#{i}; #{f[i]}";UI.play_sound(f[i]);i+=1;UI.stop_timer(t) if i>=f.length}
                      

                      @unknownuser said:

                      110 characters, 5 semicolons

                      fn=0;d="c;/Windows/Media";Dir.foreach(d){|s| fn+=1;UI.play_sound(File.join(d,s));puts "#{fn}; #{s}";sleep(2)}
                      

                      @tig said:

                      114 characters, 2 semicolons

                      Dir.chdir(d="C;/WINDOWS/Media/");(c=Dir['*.wav']).each{|w|UI.play_sound(d+w);UI.inputbox([w],[c.index(w).to_s],d)}
                      > 
                      

                      @jim said:

                      258 characters, 18 semicolons

                      @f=Dir["c;/windows/media/*"];def b(i);io=open(i,"rb");io.pos=28;b=io.read(4);io.close;b.unpack("i")[0].to_f;end;def j;t=0;@f.each_with_index{|s,i|;UI.start_timer(t){;Sketchup.set_status_text"#{i+1};#{s}";UI.play_sound(s);};t+=(File.stat(s).size/b(s));};end;j
                      > 
                      

                      Kudos to Thicket for the shortest code!
                      Honorable mention to TIG for second-shortest by 4 characters.
                      Kudos to Jim for checking the filesize to get the delay time!
                      Kudos to TIG for a really clever way of presenting the track info and avoiding both sound overlaps and system sound intrusion!

                      Now, for the follow-up challenge:
                      Create the jukebox with less than 100 characters! Entries due by noon (GMT-6) on Monday, 6 August 2007. Short challenge, but the hard work's been done πŸ˜„

                      RickW
                      [www.smustard.com](http://www.smustard.com)

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        todd burch
                        last edited by 28 Nov 2007, 23:49

                        @rickw said:

                        Now, for the follow-up challenge:
                        Create the jukebox with less than 100 characters! Entries due by noon (GMT-6) on Monday, 6 August 2007. Short challenge, but the hard work's been done πŸ˜„

                        Here's mine:

                        iTunes

                        What do I win? πŸ˜†

                        1 Reply Last reply Reply Quote 0
                        • R Offline
                          RickW
                          last edited by 28 Nov 2007, 23:50

                          Good effort, but you didn't use the UI.play_sound(filename) method. πŸ˜†

                          I'm also a bit worried if you put your system sounds into iTunes πŸ˜‰

                          RickW
                          [www.smustard.com](http://www.smustard.com)

                          1 Reply Last reply Reply Quote 0
                          • J Offline
                            Jim
                            last edited by 28 Nov 2007, 23:51

                            I was curious about the behavior of UI.play_sound. On my system, window 2000 pro, I wrote the core of the challenge as follows:

                            
                            Dir["c;\winnt\media\*"].each {|s| UI.play_sound(s)}
                            
                            

                            This played all the sounds simultaneously. Is the behavior the same for everyone?

                            Hi

                            1 Reply Last reply Reply Quote 0
                            • R Offline
                              RickW
                              last edited by 28 Nov 2007, 23:51

                              That's what I got...

                              RickW
                              [www.smustard.com](http://www.smustard.com)

                              1 Reply Last reply Reply Quote 0
                              • R Offline
                                RickW
                                last edited by 28 Nov 2007, 23:52

                                Okay, round 2 is closed. TIG and I each got it down to 84 characters with the following code:

                                @tig said:

                                c=0;Dir["C:/WINDOWS/Media/*v"].each{|w|UI.play_sound w;UI.inputbox([w],["#{c+=1}"])}

                                @rickw said:

                                i=0;Dir["C:/WINDOWS/Media/*v"].each{|f|UI.play_sound f;puts"#{i+=1}: #{f}";sleep(3)}

                                I could have squeezed it to 83 by removing the space after the : in the puts statement, but decided against it.

                                Thanks to everyone who worked on this - it was a fun challenge, and we should do another one next month πŸ˜„

                                RickW
                                [www.smustard.com](http://www.smustard.com)

                                1 Reply Last reply Reply Quote 0
                                • R Offline
                                  RickW
                                  last edited by 28 Nov 2007, 23:52

                                  Too late for deadline, but a shorter (77 characters) solution:

                                  i=0;Dir["C:/WINDOWS/Media/*"].each{|f|UI.play_sound f;puts [i+=1,f];sleep(3)}

                                  If anyone can reduce it from here, please post and enlighten us all πŸ˜„

                                  RickW
                                  [www.smustard.com](http://www.smustard.com)

                                  1 Reply Last reply Reply Quote 0
                                  • daikuD Offline
                                    daiku
                                    last edited by 28 Nov 2007, 23:53

                                    OBFUSCATORS! You should be trying to make it MORE readable, not less! (switch to high, crackly voice) You young punks don't know how good you've got it! Why, back in my day, all we had was ones and zeros. And sometimes we didn't even have zeros, and we had to use the letter O!

                                    πŸ˜‰ πŸ˜‰ πŸ˜‰

                                    Clark Bremer
                                    http://www.northernlightstimberframing.com

                                    1 Reply Last reply Reply Quote 0
                                    • J Offline
                                      Jim
                                      last edited by 28 Nov 2007, 23:53

                                      @rickw said:

                                      Too late for deadline, but a shorter (77 characters) solution:

                                      i=0;Dir["C:/WINDOWS/Media/*"].each{|f|UI.play_sound f;puts [i+=1,f];sleep(3)}

                                      If anyone can reduce it from here, please post and enlighten us all πŸ˜„

                                      
                                      i=0;Dir["/WINDOWS/Media/*"].map{|f|UI.play_sound f;p i+=1,f;sleep 3}
                                      
                                      

                                      That would be 68? πŸ˜‰

                                      Hi

                                      1 Reply Last reply Reply Quote 0
                                      • R Offline
                                        RickW
                                        last edited by 28 Nov 2007, 23:54

                                        Nice job Jim! πŸ˜„

                                        Clark, that was too funny πŸ˜†

                                        RickW
                                        [www.smustard.com](http://www.smustard.com)

                                        1 Reply Last reply Reply Quote 0
                                        • TIGT Offline
                                          TIG Moderator
                                          last edited by 28 Nov 2007, 23:54

                                          Tweaking Jim's..

                                          i=0;Dir["/*/Media/*v"].map{|f|UI.play_sound f;p i+=1,f;sleep 3}
                                          

                                          That would be 63... AND it only plays wav files, not falling over on midi's etc... (62 otherwise)

                                          TIG

                                          1 Reply Last reply Reply Quote 0
                                          • 1
                                          • 2
                                          • 1 / 2
                                          1 / 2
                                          • First post
                                            1/26
                                            Last post
                                          Buy SketchPlus
                                          Buy SUbD
                                          Buy WrapR
                                          Buy eBook
                                          Buy Modelur
                                          Buy Vertex Tools
                                          Buy SketchCuisine
                                          Buy FormFonts

                                          Advertisement