Programming Challenges - Page 9


Page 9 of 19 FirstFirst ... 5678910111213 ... LastLast
Results 121 to 135 of 279

Thread: Programming Challenges

  1. #121
    Join Date
    Jan 2003
    Location
    Seattle, Washington
    Posts
    337
    Explain how this works. Have fun

    #include <stdio.h>

    int main(t,_,a) char *a;
    {
    return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
    main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
    main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
    "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/#\
    ;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \
    q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;#
    \
    ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \
    iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
    ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n'
    ')# \
    }'+}##(!!/")
    :t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1)
    :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
    "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghirya"),a+1);
    }
    "Pick a number between 1 and 3. Your number is 42! Why? Because it is!"
    ~Brandon

  2. #122
    Join Date
    Jan 2001
    Location
    Somewhere in middle America
    Posts
    164
    Or this:
    Code:
    #!/usr/bin/perl
    my ($a,$b,$c,$d,$x,$z) = qw(100 3 0 $ 6bC z);
    my $s = $d . join $d , ((join undef, map ord , ((' '.$x.$b)=~/./g)) =~
    /./g);
    $_ = join undef , map { $a+=!($_%$b)&&$c++; $a+=($_>$c)&&$b;
                            $a+=($_==$c)&&$c; chr $a;  } (0..7);
    /(.)(.)(.)((.)(.))(.)(.)(.)/;
    eval "\$_ = \"$s!\\n\"";
    s;$z;, ;;
    print ucfirst;
    My Machine:
    Maytag SAV5905
    710 rpm Stainless Steel Drum
    Dual boot: Gentoo / Tide

  3. #123
    Join Date
    Sep 2001
    Location
    Just for kicks
    Posts
    1,831
    Originally posted by JCool451
    Explain how this works. Have fun

    #include <stdio.h>

    int main(t,_,a) char *a;
    {
    return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
    main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
    main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
    "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/#\
    ;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \
    q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;#
    \
    ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \
    iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
    ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n'
    ')# \
    }'+}##(!!/")
    :t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1)
    :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
    "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghirya"),a+1);
    }
    Can you please post that in the 'code' tag, I sure would like to see that properly indented.

    [edit] oh yea, I compiled it and it prints out the 12 days of Christmas
    "You cannot invade the mainland United States. There would be a rifle behind each blade of grass." --Admiral Yamamoto, 1941

  4. #124
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Ok, it's been a long time since a challenge has been posted. Here's one:

    1. Start with an array of all zeros, user defined length.
    2. Prompt user to input the number of 1s to distribute through this array, must be less then the length.
    3. Distribute the 1s over the array as evenly as possible.
    4. Display the array.

    Have fun!!
    if (i_forgot && this_is_about_code)
    language = c++;

  5. #125
    Join Date
    Dec 2000
    Location
    Glasgow, Scotland
    Posts
    4,361
    Originally posted by tecknophreak
    Ok, it's been a long time since a challenge has been posted. Here's one:

    1. Start with an array of all zeros, user defined length.
    2. Prompt user to input the number of 1s to distribute through this array, must be less then the length.
    3. Distribute the 1s over the array as evenly as possible.
    4. Display the array.

    Have fun!!
    Can I just clarify
    - the array is of a user defined length - so I need to include a means of him entering the length he wants?
    - When you say 'even' distibution, I am assuming you mean in a reasonably symmetrical pattern - ie 8 0s and then 4 1s would be 10101010 rather than 11110000, yes?
    mrBen "Carpe Aptenodytes"

    Linux User #216794

    My blog page

    3rd year running - get yourself to LugRadio Live 7th-8th July 2007, Wolverhampton, UK. The premier FLOSS community event.

  6. #126
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    PERFECT!!
    if (i_forgot && this_is_about_code)
    language = c++;

  7. #127
    Join Date
    Apr 2003
    Location
    UK
    Posts
    305
    Here is my effort to tecknophreak's recent challenge, its not perfect though. Depending on the numbers used you may end up with un-even speard of 1's over the array. For example array length = 20 and amount of ones = 11.

    Im almost certain its to do with integers used in the algorithm when they are divided and the result is less than 1 it does not round the value up, so it then uses the value 0.
    Attached Files Attached Files
    Last edited by ricstr; 11-29-2003 at 01:45 PM.

  8. #128
    Join Date
    Aug 2002
    Location
    Essex, UK
    Posts
    937
    If you want it to round up, just use ceil().
    Registered Linux User #325947

    Check out Feather Linux, my distro.
    (Yes, it's shameless self promotion, deal with it )

  9. #129
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,936
    Originally posted by o0zi
    If you want it to round up, just use ceil().
    And make sure that the argument to ceil() is a float or double, not an integer. In other words, this:

    Code:
    int x = 5, y = 22;
    
    printf("%lf\n", ceil(y/x));
    won't work, it'll print 4. The reason is that both x and y are integers, so the division is integer division, which always truncates the result. The result (4) is then passed to ceil(), which returns 4.0, which gets printed.

    The fix is to either make y a float or double, or cast one or both of x and y to either float or double before doing the division, like this:

    Code:
    int x = 5, y = 22;
    
    printf("%lf\n", ceil((double)y / x));
    More or less, anyway.

  10. #130

    Challenge! (basic)

    very basic, but fun. write a program that takes any file and write each line to the sound card.
    i was once trapped by windows, but linux set me free...

  11. #131
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,936
    Well, you didn't say what language, I guess...

    Code:
    #!/bin/sh
    
    if [ $# -ne 1 ] ; then
        echo "Usage:  $0 filename"
        exit 1
    fi
    
    cat $1 >/dev/dsp

  12. #132

    Challenge!

    write a program that converts an integer to hex.

    Language: Any
    i was once trapped by windows, but linux set me free...

  13. #133
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    ok.

    Code:
    #include <iostream>
    
    int main() {
        int i(5);
        std::cout << std::hex << i << std::endl;
    }
    if (i_forgot && this_is_about_code)
    language = c++;

  14. #134
    Join Date
    Jun 2003
    Posts
    173

    Array of Ones Problem

    I have found an interesting result while using Perl to program the Array with equally distributed ones. Because Perl doesn't have any preset data types, when dividing two integers it automatically uses the result as a float or double. So when I calculate the GAP it is stored as a float or double. Then when I calculate START and START += GAP it is also stored as a float or double. (Start += GAP calculates the location of the next 1) Perl allows me to keep the precision until I update the array and then it truncates START to an integer value to be used in the array index. What this means is that my code produces a perfectly symmetrical array, also known as a homophone, (word or number same forwards as backward). There are only two cases where this is not true, when LENGTH / NUMONES = 2 or LENGTH is even and NUMONES is odd.

    In C++ or Java you could keep the variables LENGTH, NUMONES, GAP, and INDEX or START as floats or doubles to keep the precision and then when updating the array at position INDEX or START cast INDEX or START as an integer value. This should result in the same output.

    This is a solution to the previous question about precision of integer division.

    I have posted my Perl Solution.

  15. #135
    Join Date
    Nov 2003
    Posts
    4
    Here is a holiday challege for you guys...someone write a quick duckhunt type program in c++ where your goal is to shoot santa ( or if youd like buddha, reindeer, etc...) make either the mouse or keyboard do the actual shooting, whatever you guys would like. lets just see if anyone has some holiday programming spirit.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •