LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 05-10-2024, 08:19 AM   #1
BenisBrothers
LQ Newbie
 
Registered: Aug 2018
Posts: 4

Rep: Reputation: Disabled
Give me a programming challenge


I like to program in C, Tcl/Tk, BBC BASIC, and my own scripting language that I implemented in C.

I'd appreciate if you would give me some simple programming challenges that could be done in maybe a couple hours each.
 
Old 05-10-2024, 09:22 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
Go to Leetcode
 
Old 05-10-2024, 10:29 AM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,152
Blog Entries: 6

Rep: Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835
I have some legitimate challenges for you. If you are wanting to sprain your brain a little.

Make webkit2gtk work with youtube without core dumping.

Make Qt5/Qt6webengine answer query requests, so that you can get past the square of "Choose all squares with traffic lamps" without going around in circles infinitely.

Make a Python Tk/Tcl browser that has a javascript engine.

Recompile dillo so that it uses ssl3.


A simple challenge. Make it snow in a terminal. Like this for an example:
Code:
#!/usr/bin/bash

declare -A sf
declare -A lf

clear

l=$(($(tput lines) + 1))
c=$(($(tput cols) + 1))

move() {
    i="$1"
    if [ "${sf[$i]}" = "" ] || [ "${sf[$i]}" = "$l" ]; then
        sf[$i]=0
    elif [ "${lf[$i]}" != "" ]; then
        printf "\033[%s;%sH \033[0;0H" "${lf[$i]}" "$i"
    fi
    printf "\033[%s;%sH*\033[0;0H" "${sf[$i]}" "$i"

    lf[$i]="${sf[$i]}"
    sf[$i]="$((${sf[$i]} + 1))"
}

while :; do
    i=$(($RANDOM % $c))
    move "$i"
    for x in "${!lf[@]}"; do
        move "$x"
    done
    sleep 0.07
done
Make yours different. Then go from there.
 
Old 05-10-2024, 10:44 AM   #4
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,152
Blog Entries: 6

Rep: Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835
Oh, I've got one here. I won't post it. Make the snow flakes fall at different rates. Make the snow blow sideways every now and then. make the snow pile up at the bottom.
 
Old 05-11-2024, 06:01 PM   #5
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,918

Rep: Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035
How about this Armstrong numbers one from a few years back.

I also had a lot of fun solving this "circle of squares problem" also a few years back. Though that one ended up eating much more than a few hours by the time I'd finished.

Or, how about converting between decimal and Roman Numerals. That should be a nice quick one.

Last edited by GazL; 05-11-2024 at 06:03 PM.
 
Old 05-12-2024, 08:46 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
My favorite was the Eight Queens Puzzle. Find all of the positions on a standard chessboard where "8 Queens" can be positioned, but none of them can capture the other.

No fair(!) "Googling" the answer. (As is: "reading the entirety of(!) the WikiPedia article that I linked to!) If you resort to this, you are entirely missing the point. Instead: "read just page one," to understand the nature of the problem, then ponder how you would go about solving it.

This is a classic example where "a very optimal solution actually exists." But let it be up to you to find out what it is – entirely without help. (Let's just say that: "if you are thinking about 'eight nested loops' without thinking deeper," you are definitely doing it wrong.) The "right approach" will spit out all 92 solutions almost instantly. (With or without Python. The first solution I saw was in BASIC.)

Last edited by sundialsvcs; 05-12-2024 at 08:56 PM.
 
Old 05-13-2024, 02:10 AM   #7
gerard4143
Member
 
Registered: Jan 2008
Location: P.E.I. Canada
Posts: 32

Rep: Reputation: 4
Create a program that solves(shows the steps) of a 3x3 sliding puzzle. Note... Not all combinations of a 3x3 sliding puzzle can be solved. That's why I included a link to 3x3 puzzles that are solvable.

https://www.helpfulgames.com/subject...ng-puzzle.html

Create a Sudoku solver.

https://sudoku.com/

Last edited by gerard4143; 05-13-2024 at 02:22 AM.
 
Old 05-13-2024, 05:31 AM   #8
grumpyskeptic
Member
 
Registered: Apr 2016
Posts: 474

Rep: Reputation: Disabled
Please write a Thunar script that will verify all copying and moving to the disk, rather than just to the cache. See some of this thread -

https://www.linuxquestions.org/quest...1/#post6486633

The script would need to copy (or move) the file, then issue a sync command to get it written to disk, then verify that it matched the original file.

Currently Thunar only verifies that a file has been copied (or moved) to the cache, which is not much use.
 
Old 05-13-2024, 05:13 PM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
Back when the online game "Terracaching" was a thing, I encountered a Puzzle Terracache series which involved, among other things, "the mother of all Sudoku puzzles," and one of those "logic problems" with 21 statements. (Stuff like: "The man in the orange hat does not have a zebra as a pet.")

I had fun solving both of these using the (free and open source, "GNU") gprolog programming language, which features a "finite-domain (FD) problem solver" built in. For a geek like me, it was both great fun and very instructive to research and then learn how to use this tool to solve both kinds of problems. (And, to politely inform the cache owner that "statement #20 does not contribute to your logic problem and can be omitted.")

"Logic Programming" is a very interesting non-procedural programming discipline in which your "program" expresses the problem to be solved, not the way that the system will solve it.

Last edited by sundialsvcs; 05-13-2024 at 05:17 PM.
 
Old 05-13-2024, 05:54 PM   #10
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Write a C program, using no library calls, allocating no memory, using no temporary holding variables, to reverse a string in place.

Advanced: Sort a string into alphabetical, or numerical order, depending on the contents, all of one type, within the same original constraints. Or sort a mixed alphanumeric string placing numerals in order either before or after the alphabetically sorted characters.
 
Old 05-14-2024, 08:03 AM   #11
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
Quote:
Originally Posted by rtmistler View Post
Write a C program, using no library calls, allocating no memory, using no temporary holding variables, to reverse a string in place.
Okay, "you just stumped the teacher ..."
 
Old 05-14-2024, 08:22 AM   #12
EdGr
Senior Member
 
Registered: Dec 2010
Location: California, USA
Distribution: I run my own OS
Posts: 1,003

Rep: Reputation: 474Reputation: 474Reputation: 474Reputation: 474Reputation: 474
Write a program to print all permutations of the letters in a word.

Code:
% permute word
word
wodr
wrod
wrdo
wdor
wdro
owrd
owdr
orwd
ordw
odwr
odrw
rwod
rwdo
rowd
rodw
rdwo
rdow
dwor
dwro
dowr
dorw
drwo
drow
This program is 20-50 lines of code in most languages.
Ed
 
Old 05-14-2024, 02:07 PM   #13
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,152
Blog Entries: 6

Rep: Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835
Not sure that I can meet those requirements. Here is a start.
Quote:
to reverse a string in place.
Code:
#include <stdio.h>

void strRev(char *head) 
{
    if (!head) return;
    char *tail = head;
    while(*tail) ++tail;
    --tail;

    for(; head < tail; ++head, --tail) {
        char h = *head;
        *head = *tail;
        *tail = h;
    }
}

int main(int argc, char **argv)
{
    do {
        printf("%s > ",  argv[argc-1]);
        strRev(argv[argc-1]);
        printf("%s\n", argv[argc-1]);
    } while(--argc);

    return 0;
}

//gcc rev.c -o rev
Code:
gcc rev.c -o rev
./rev apple orange pear
pear > raep
orange > egnaro
apple > elppa
./rev > ver/.
 
Old 05-14-2024, 05:12 PM   #14
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Quote:
Originally Posted by teckk View Post
Not sure that I can meet those requirements. Here is a start.
Common need which I totally get, you wanted printf() to validate. You could however replace that with your own code but that's taking the intent too far. Similarly you could validate in a debugger, neeeing no output capability. Not specifically an instructor however I probably would guide students to validate but leave that out in a submitted solution, or have them first develop a replacement output logger tool and use that. Anyways great job! I hope the OP if still paying attention appreciates it.

And one interesting interpretation, because I would reverse the entire command line string, as opposed to each element, but no argument. I feel you get it and similarly could sort also. +100
 
Old 05-14-2024, 06:33 PM   #15
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,020

Rep: Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630Reputation: 3630
If you get really good can you recreate windows media center in a linux program?

I still use it for TV.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: The Fuduntu Programming Challenge LXer Syndicated Linux News 0 03-31-2011 10:11 PM
An esoteric programming challenge Bert Programming 0 03-22-2002 07:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 06:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration