Jump to content

tmont

Members
  • Posts

    474
  • Joined

  • Last visited

Blog Entries posted by tmont

  1. tmont
    So, at my office, we like to argue about programming concepts. Usually I bring them up as they relate to math, since I know more stupid little things about math than my co-workers, whereas they have a great deal more experience than me in just about everything else since they're all 30ish and have one foot in the grave. Anyway, here's a question (paraphrased) I posed to an interviewee:
     
     
    Sadly, the interviewee was... misfortunate, and couldn't solve this, even though I practically wrote the answer on the white board.
     
    An answer (in PHP):
     

    function truemod($num, $mod) { $return = $num % $mod; if ($return < 0) { $return += $mod; } return $return; }
     
    The follow-up to this (what I thought was a decidedly easy) question was going to be, "now do it without a conditional."
     
    An answer (in PHP):
     

    function truemod($num, $mod) { return ($mod + ($num % $mod)) % $mod; }
     
    We didn't quite get that far, however, since the interviewee gave up instead of translating "-5 + 7" (what I wrote on the board as I was trying to prod him into an answer) into a function.
     
    Anyway, I had run into this problem before, mainly when dealing with calendars, and had to hack my way to a solution. I brought it up to my coworkers, and what followed was a heated argument about whether "Tommy is wrong because -5 % 7 in Java is -5" (paraphrased). Since my coworker was slightly belligerent, and I found it kind of insulting, I gave him the mathematical answer, which is correct-ish, since I took group theory two and a half years ago and haven't used it since:
     
     
    However inaccurate that explanation was, they didn't really buy it, but I only wrote it up to be facetious, and wasn't really meant to be taken seriously.
     
    We ended up finding "bug" reports for both Java and PHP where people were complaining that the modulus operator wasn't accurate: it was returning negative numbers when that's not possible (for the very reasons that I so eloquently stated above). We eventually discovered the reason:
     
    Some languages truncate integer division toward zero, which means that, for example, 15/7 = 2 and -15/7 = -2. Java, PHP, JavaScript, C#, SQL and probably (I don't have a C compiler) C/C++ work this way. These are the languages in which -5 % 7 = -5. Other languages truncate toward negative infinity (i.e. they always take the floor), which means that 15/7 = 2 and -15/7 = -3. Perl, Python, Ruby, Lisp, Haskell and Lua all work this way. These are the languages in which -5 % 7 = 2.
     
    In conclusion, it was a stimulating exercise. Can anybody give examples of other languages and their modulus operators?
     
    Fun time!! Try it yourself! (No, I don't know Haskell; I learned enough of it in 10 minutes to install a compiler and run one command)
     

    PHP: <?php echo -5%7; ?> JavaScript : (why do I need a space there to be able to write "JavaScript" as one word?) alert(-5%7) Java: public class mod { public static void main(String [] args) { System.out.println(-5%7); } } C#: class mod { static void Main(string[] args) { System.Console.WriteLine(-5 % 7); } } SQL: SELECT -5%7 Ruby: puts -5%7 Perl/Python: print -5%7 Lua: io.write(-5%7); Lisp: (mod -5 7) Haskell: -5 `mod` 7
  2. tmont
    So, I've wanted to make something like this for a while, but didn't have the motivation/skills/intelligence to do so. I've been teaching myself PHP for the last couple months, and thought this could be a good outlet. Also, I may use a derivative of this thing for my senior project, which is something like "using ternary continued fractions to derive tuning ratios." It sounds more awesome (or maybe less) than it actually is.
     
    Anyway, what I've created is a keyboard (like a piano) of sorts that corresponds to the frequencies capable of being emitted by the 2600. Since these frequencies don't conform to any recognizable musical scale, basically any music written for the 2600 is a gross approximation of what'd you want. More details here.
     
    What this utility does is provide an easier way to compose music for the 2600. Agreed, it's not really all that useful, since composing music for the 2600 can be done without it. But, it does make it a little easier, since you'll be able to immediately hear your song, rather than code it up and run it on an emulator. No 2600 coding skillz are required; after all, I created it, and I'm an idiot.
     
    Sorry to all you fools who use Firefox or Opera, but this is IE only, for reasons that can only be described as mean-spirited. Well, that's not completely true. While it's true that every time I see a "Spread Firefox" button on a website I want to punch the webmaster in the face over the internet, that really had no bearing on not allowing Firefox users to use this thing. Read the FAQ on the page for more details. You'll also want to enable Javascript, or it will be quite useless.
     
    Link: http://tmont.kicks-ass.org/music/
     
    Enjoy. I'd be interested in hearing some comments (like if anyone can figure out how to use it). Most of your questions are probably answered in the FAQ.
     
    Oh, I almost forgot. Here's some sample songs that I made while testing it out (they aren't that cool, I was just testing stuff):
     
    test.mid
    test2.mid
    --test2 channel 1 data
    --test2 channel 2 data
    fun_with_modulation.mid
    --fun_with_modulation channel 1 data
    --fun_with_modulation channel 2 data
  3. tmont
    I took a music history class in college, and we had these listening tests where our professor would play 10-20 seconds of some song (usually opera, it was all 17th-18th century music), and we had to write down the composer, the genre, the title (usually Latin or Italian), the year it was composed, and some other stuff I can't remember. Anyway, one of the pieces was Gregorio Allegri's Miserere Mei, Deus, and I fell in love with it. It's purely choral, with a little chant.
     
    Anyway, since I now suddenly have a lot of time on my hands, I decided to spend a day or two to arrange this classic piece of Christian choral music for rock stars. Kind of. Mainly I just added counterpoint and drums. Take a listen:
     
    My version
    Original (from my class)
    It's even on YouTube (with score)
     
    My version was created via MIDI, so the voices might sound slightly corny.
  4. tmont
    Nothing's sexier than three ninjas in purple jumpsuits running real fast. If you don't believe me, then you should watch these:
    Ninja Gaiden in 13:49
    Ninja Gaiden II in 12:45
    Ninja Gaiden III in 16:08

  5. tmont
    So I finally figured out how to work this .jar crap, which makes java applications executable (i.e. running applets without an internet connection). They work on my machine, but I know very little about these .jar files and how they work. Can someone download these and tell me if they work? And if they don't, can you specify what happens, and what java stuff you have installed (jdk, platform, etc.)? Or, alternatively, if you know stuff, you can straight up tell me how these things work.
     
    Thanks a bundle.
     
    Hmmm, can't even attach them. Here's some so-fine links:
     
    Playfield Editor (22.3 KB)
    Map Editor (12 KB)
     
    All you have to do is download it, and then double click on it. Hopefully, a window will pop up that looks like one of these:
     

  6. tmont
    A little something I created with my birthday present. I find it intoxicating. Enjoy!
     
    Sadly, errors were found. Crap-o-cities to the rescue!
     
    Do it! (right click, save as, etc.)
  7. tmont
    I was working on an improved version of the sprite editor applet I made a while ago, which kind of sucked, but then I abandoned it several months ago. Since my last final is tomorrow, I won't have access to my school's server, so I figured I'd post this now before it's too late. Maybe I'll get it done during the summer (coding during the summer? ha!).
     
    Do it!
     
    I'd list the features and stuff, but I don't really remember anything. I think things are pretty self-explanatory, and everything (besides a few of the menu options) works. The only thing I didn't implement was the code generation (which might be the most useful part). Anyway, enjoy (or not).
     
    Actually, it looks flipping vertically doesn't work in some cases. Not sure why that is...
×
×
  • Create New...