Thread: New years challenge!

  1. #16
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by Tonto View Post
    This doesn't make any sense

    X = (X * K) MOD P

    X = 5, K = 2, P = 3

    Like what? Is that not a mathematical equation in the traditional sense?

    Rather a sequence X sub N = (X sub N-1 * K) MOD P?
    Its a clue, not the solution. But Ill elaborate a little more. There are conditions to the variables in that equation-

    P must be prime

    1 < K < P

    0 < X < P

    thus P must be greater than 2

  2. #17
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    OK, since im not getting very many entries, Ill remove the requirement for it to be in assembly, since I think this is the biggest barrier for most people.

  3. #18
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Not like a barrier although, but I was curious why in asm, and that too on a C++ forum?

  4. #19
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    As interesting as it is, I don't think people are taking this request seriously. That could also be the reason you aren't getting replies. I'm sure some of the grizzly people here still remember assembly, so that isn't the problem.

  5. #20
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Not like a barrier although, but I was curious why in asm, and that too on a C++ forum?
    C++ and C . . . and C#, in a way.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #21
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by citizen View Post
    I don't think people are taking this request seriously.
    Well, my contests tend to be fairly difficult, not the usual ' write a program using only macros and only use the letter S 3 times'. I could dumb them down, but then what would be the point. A contest is supposed to be challenging.

  7. #22
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by abachler View Post
    Well, my contests tend to be fairly difficult, not the usual ' write a program using only macros and only use the letter S 3 times'. I could dumb them down, but then what would be the point. A contest is supposed to be challenging.
    Do you have a solution?
    If so, could you answer the following questions about it?
    1. Can your method play any rhythm, or just one note per beat?
    2. Can your method play any diatonic tune (perhaps within a bounded note-range)?

  8. #23
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    My solution can play any rhythm. It can't however, do chords, or rests. (Although rests could easily be added if I am allowed a call to Sleep(), or perhaps one could play a tone outside of human hearing.)

    I thought abachler's challenge was a good one, even for cboard. Leave your programming comfort zones, and give it a try.
    Personally, I failed at getting nasm to assemble anything Win32 related. I finally gave up on that, and really bit the bullet, and sat down with gcc's assembler. (I greatly prefer Intel-like syntax over AT&T... oh well.) After much crashes, and me finally discovering that a semicolon doesn't actually comment a line (but doesn't give an errors...), I got one working. Although I'm still perplexed by some of the assembler that gcc generates, such as:
    Code:
    	movl	$0, %eax
    	addl	$15, %eax
    	addl	$15, %eax
    	shrl	$4, %eax
    	sall	$4, %eax
    Why not just precompute whatever that results in, and stuff it in eax...?

    My solution is attached. Should compile on Win32/x86.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  9. #24
    Registered User alreadyinuse's Avatar
    Join Date
    Dec 2007
    Posts
    12
    Quote Originally Posted by Cactus_Hugger View Post
    Personally, I failed at getting nasm to assemble anything Win32 related. I finally gave up on that, and really bit the bullet, and sat down with gcc's assembler. (I greatly prefer Intel-like syntax over AT&T... oh well.) After much crashes, and me finally discovering that a semicolon doesn't actually comment a line (but doesn't give an errors...), I got one working.....
    lol :-D

    have you tryed FASM ? It has a syntax very similar with nasm, a wonderful macros system (well, this is my opinion), some great library and include files....

  10. #25
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Unfortunately yours is not a solution to the original problem.
    You can't use a table of values. You have to calculate the next
    note and duration through some algorithm.
    That's what makes it difficult.

    As far as the assembly contortions go, what exactly was the C code
    that generated it? I don't see that in my "gcc -S" of simple program.

  11. #26
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Code:
    #include <stdio.h>
    
    int main()
    {
    	return 0;
    }
    Generates the assembly that I'm curious about, and posted above.
    EDIT: Ok, turning up optimizations to -O2 generates more sane assembly, and precomputes it. I just wondering why gcc is doing eax = ((0 + 15 + 15) >> 4) << 4 in the first place... (other than a call to _alloc and __main, eax is never used. Even then, I'm not sure if _alloc/__main use eax... don't know the calling convention.)

    Totally missed the table of values thing, so I guess not. Makes me wonder exactly how we're supposed to play a song, unless there is one specific Christmas tune that follow a mathematical equation...? Such as the one hinted earlier, but that gives values (way) too low to be audible frequencies, and durations too short to be more than a click - I'm obviously 'not getting it'. If it's pitches, relative to some starting pitch... then I need log() to make the conversion to frequency, again, breaking a rule.
    Last edited by Cactus_Hugger; 01-13-2008 at 10:09 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  12. #27
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You cant use a table of values. You have to calculate the next note and duration through some algorithm.
    My algorithm is fgetc()! -- or whatever you use in assembly.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #28
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    hehe, too bad it doesnt seem to work on my system :0

  14. #29
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    So when is this contest ending? (not that i want to participate im just curious as to how this is solved - alos looking forward to see abachlers solution )

  15. #30
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by abachler View Post
    hehe, too bad it doesnt seem to work on my system :0
    My example? It should compile with gcc ... what errors do you get? A simple "gcc -o music.exe music.s" is all that's needed. (Of course, you obviously need Windows.)
    Now... if you're using MSVC... well... no idea what its assembler is like.

    dwks: My understanding was that all you could use was Beep(), so fgetc() would be against the rules.

    I am also interested in abachler's solution.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Delete Files Older than 2 years
    By Dragoon_42 in forum C++ Programming
    Replies: 10
    Last Post: 05-17-2007, 04:13 PM
  2. Converting seconds to years, months etc...
    By ^xor in forum C Programming
    Replies: 7
    Last Post: 08-06-2005, 11:30 PM
  3. Where will programming be in 30 years ?
    By mrpickle in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 01-08-2004, 05:42 AM
  4. Requesting a challenge
    By RealityFusion in forum C++ Programming
    Replies: 8
    Last Post: 08-18-2003, 08:24 PM
  5. Video Games Industry. 5 years left.
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 12-10-2002, 10:52 PM