Jump to content

The under 100 line challenge!

fletch to 99

who cares, put up a download i wanna see it

ok :P 

http://pastebin.com/ch6pH5Qn

 

gui was generated because i am lazy :D

 

just simple program that you can add profiles to and when you launch the game (Archlord Private server) it saves the login and you don't need to type it out.

Needs Update

Link to comment
Share on other sites

Link to post
Share on other sites

I wrote this small Error Correction "Library" for my Universtiy project a few years ago. http://pastebin.com/3tkqAkvN 

After minifying it by removing whitespace and comments, it's exactly 100 lines now...

Not technically a self contained program, but it is useful. It will encode your bits from a byte array using a convolutional encoder (http://en.wikipedia.org/wiki/Convolutional_code) and then you can pass received coded bits into the Viterbi decoder (http://en.wikipedia.org/wiki/Viterbi_algorithm) to retreive the original bytes... might even be possible to save some further space and then add a short main() {} function...

Does it count?

It's probably the most useful thing in this size-range that I have ever written...

Link to comment
Share on other sites

Link to post
Share on other sites

I take part in coding competitions that forces you to write efficient and robust code due to constraints.
I will post some previous work that I did. All solutions are correct and compile without errors. If you can't get it to run then quote me.
Hope you guys like :)
 
QUESTION 1:

Title: Grey Codes

Description

We are going to generate a sequence of integers in binary.

 

Start with the sequence:
0
1

 

Reflect it in the horizontal line, prepend a zero to the numbers in the top half and a one to the numbers on the bottom and you will get:
00
01
11
10

 

Repeat this again, and you will have 8 numbers (the corresponding decimal values are shown on the right):
000 --- Number 0
001 --- Number 1
011 --- Number 3
010 --- Number 2
110 --- Number 6
111 --- Number 7
101 --- Number 5
100 --- Number 4

 

These sequences are called Reflected Gray Codes for 1, 2 and 3 bits respectively.
A Gray Code for N bits is a sequence of 2^N different N-bit integers with the property that every two neighbouring integers differ in exactly one bit. A Reflected Gray Code is a Gray Code constructed in the way shown above.

Input specification
The first line of input gives the number of cases, T (at most 250000). T test cases follow. Each one is a line with 2 integers: N (1 <= N <= 30) and K (0 <= K < 2^N).

Output specification
For each test case, output the integer that appears in position K of the N-bit Reflected Gray Code.

Sample input
14
1 0
1 1
2 0
2 1
2 2
2 3
3 0
3 1
3 2
3 3
3 4
3 5
3 6
3 7

Sample output
0
1
0
1
3
2
0
1
3
2
6
7
5
4
 

Constraints:

Time limit (ms): 1000, Memory limit (kb): 131072, Output limit (mb): 64, Size limit (bytes): 100000

 

 

MySolution - C code

/*Description: Basically we use the XOR Gate method to convert our binary to             Grey Code.*/# include <stdio.h># include <stdlib.h> /*******Main**********/int main() {        int binaryNumber[100], greyCode[100], i=1, j, x, y=1, count=0, T, N, K;        scanf("%d", &T);        for(x=1; x<=T; x++)    {      scanf("%d %d", &N, &K);            //convert the decimal number to binary      while(count<=N)      {         binaryNumber[i++] = K % 2;         K = K / 2;         count++;      }            count=0;      binaryNumber[i] = 0;//set an extra 0 to fulfill the XOR checks below            //Convert to Grey Code using XOR Gate Method      for(j=1; j<i; j++)      {         if(binaryNumber[j] == 1 && binaryNumber[j+1] == 1) greyCode[y++] = 0;         else if(binaryNumber[j] == 0 && binaryNumber[j+1] == 0) greyCode[y++] = 0;         else if(binaryNumber[j] == 0 && binaryNumber[j+1] == 1) greyCode[y++] = 1;         else if(binaryNumber[j] == 1 && binaryNumber[j+1] == 0) greyCode[y++] = 1;      }          int decimal=0, binary, multiply=1, digit, k=0;      //convert to decimal        for(k=1; k<y; k++)        {                 binary = greyCode[k];                 digit = binary % 10;                 decimal = decimal + digit * multiply;                 binary = binary / 10;                 multiply = multiply * 2;        }                printf("%d\n", decimal);                  y=1;          i=1;     }    system("pause");    return 0;}

------------------------------------

     ~ Live Love Code ~

------------------------------------

Link to comment
Share on other sites

Link to post
Share on other sites

QUESTION 2:

Title: Pathfinding
 
Description
 
Bessie is stranded on a deserted Arctic island and wants to determine all the paths she might take to return to her pasture. She has tested her boat and knows she can travel from one island to another island in 1 unit of time if a route with proper currents connects the pair. She has experimented to create a map of the ocean with valid single-hop routes between each pair of the N (1 <= N <= 100) islands, conveniently numbered 1..N. The routes are one-way (unidirectional), owing to the way the currents push her boat in the ocean. It's possible that a pair of islands is connected by two routes that use different currents and thus provide a bidirectional connection. The map takes care to avoid specifying that a route exists between an island and itself. Given her starting location M (1 <= M <= N) and a representation of the map, help Bessie determine which islands are one 'hop' away, two 'hops' away, and so on. If Bessie can take multiple different paths to an island, consider only the path with the shortest distance. By way of example, below are N=4 islands with connectivity as shown (for this example, M=1):
 
       start--> 1-------->2
                     |            |
                     |            |
                    V           V
                    4<--------3
 
Bessie can visit island 1 in time 0 (since M = 1), islands 2 and 4 at time 1, and island 3 at time 2. The input for this task is a matrix C where the element at row r, column c is named C_rc (0 <= C_rc <= 1) and, if it has the value 1, means "Currents enable Bessie to travel directly from island r to island c in one time unit". Row C_r has N elements, respectively C_r1..C_rN, each one of which is 0 or 1.
Input specification
 
* Line 1: Two space-separated integers: N and M. * Lines 2..N+1: Line i+1 contains N space-separated integers: C_r.
Output specification
 
* Lines 1..*: Line i+1 contains the list of islands (in ascending numerical order) that Bessie can visit at time i. Do not include any lines of output after all reachable islands have been listed.
 
Sample input
 
4 1
0 1 0 1
0 0 1 0
0 0 0 1
0 0 0 0
 
Sample output
 
1
2 4
3
 
Constraints
 
Time limit (ms) 10000
Test limit (ms) 1000
Memory limit (kb) 125000
Output limit (mb) 64
Size limit (bytes) 100000
 
 
Solution - C++ Code
time   mem    size     lang
150     63     1839    C++
 
 
/*Description: I modified floyd warshall's algorithm to do this.*/# include <stdio.h># include <stdlib.h># define INF 99999void floyds(int[][110], int); int main () {        int N, M, oceanCurrent;    int i, j, k, adjMatrix[110][110];        scanf("%d%d", &N, &M);        //build ADJ Matrix    for(i=1; i<=N; i++)    {             for(j=1; j<=N; j++)             {                      scanf("%d", &oceanCurrent);                                            if(i == j) adjMatrix[i][j] = 0;                      else                      {                          if(oceanCurrent == 0) adjMatrix[i][j] = INF;                          else adjMatrix[i][j] = 1;                      }             }    }        //create shortest distance matrix    floyds(adjMatrix, N);        int count = 0;    //List of islands (in ascending numerical order) that Bessie can visitfor (i=0; i<=N; i++){  for (j=1; j<=N; j++)  {    if(adjMatrix[M][j] == i)    {                count++;                //printf("Count: %d\n", count);                if(count == 1) printf("%d", j);                if(count >= 2)                {                         if(j<=N) printf(" %d", j);                }    }  } if(i<N && count != 0) printf("\n");count = 0;}      system("pause");    return 0;} /***********FUCNTIONS***************************/ //Finds the minimum of two numbersint min(int a, int b){  if(a < b)      return a; else      return b;} //Implementation of Floyd Warshall's Algorithmvoid floyds(int adjMatrix[][110], int N){     int i,j,k;        for(k=1; k<=N ; k++)    {        for(i=1; i<=N; i++)        {            for(j=1; j<=N; j++)            {                  adjMatrix[i][j] = min(adjMatrix[i][j], adjMatrix[i][k] + adjMatrix[k][j] );            }        }    } }

------------------------------------

     ~ Live Love Code ~

------------------------------------

Link to comment
Share on other sites

Link to post
Share on other sites

-snip the grey code problem-

so... i don't see why it's necessary to do all the things you do in your code, if you can just do it in one line

int main() {    int T, N, K;    scanf("%d", &T);    for(x=1; x<=T; x++){        scanf("%d %d", &N, &K);        // XOR method?        printf("%d\n", K ^ (K / 2));    }    return 0;}
Link to comment
Share on other sites

Link to post
Share on other sites

-snip the pathfinding problem-

i gave this a shot, so here's my solution

#include <stdio.h>#define bool char#define node unsigned char#define true 1#define false 0int main () {    int N, M;    int i, j;    int NTV, NBV, tmp; // number of Nodes To Visit, Nodes Being Visited    bool existsCurrentFromiToj[100][100];    node a[100], b[100]; // two arrays to store lists of nodes    node *nodesBeingVisited = a, *nodesToVisit = b, *aux, currentNode;    bool isVisited[100] = {false};    scanf("%d%d", &N, &M);    // read the currents    for(i = 0; i < N; ++i)             for(j = 0; j < N; ++j){                      scanf("%d", &tmp);                      existsCurrentFromiToj[i][j] = (bool)tmp;             }    NTV = 1;    nodesToVisit[0] = M - 1; // zero-based instead of one-based    while(NTV > 0){ // as long as there are nodes to visit        // visit the nodes that were marked to be visited, and zero the list of nodes to be visited        aux = nodesBeingVisited;        nodesBeingVisited = nodesToVisit;        NBV = NTV;        nodesToVisit = aux;        NTV = 0;        for(i = 0; i < NBV; ++i){ // loop through them            currentNode = nodesBeingVisited[i];            printf("%d ", currentNode + 1); // visited!            for(j = 0; j < N; ++j) // look at all the currents leaving the node                if(existsCurrentFromiToj[ currentNode ][ j ] && !isVisited[ j ]){                    nodesToVisit[ NTV++ ] = j;                    isVisited[j] = true;                }        }        printf("\n"); // next distance    }    return 0;}
Link to comment
Share on other sites

Link to post
Share on other sites

 

so... i don't see why it's necessary to do all the things you do in your code, if you can just do it in one line

int main() {    int T, N, K;    scanf("%d", &T);    for(x=1; x<=T; x++){        scanf("%d %d", &N, &K);        // XOR method?        printf("%d\n", K ^ (K / 2));    }    return 0;}

 

GJ lol But at the time i coded that we had no idea that a mathematical formula like: K ^ (K / 2) could have been used.

------------------------------------

     ~ Live Love Code ~

------------------------------------

Link to comment
Share on other sites

Link to post
Share on other sites

GJ lol But at the time i coded that we had no idea that a mathematical formula like: K ^ (K / 2) could have been used.

oh i see

i didn't even know what the XOR method is, but googling it i found the formula

 

edit:

anyway, what your code does is exactly K ^ (K / 2)

Link to comment
Share on other sites

Link to post
Share on other sites

QEUSTION 3
 
Counting Diagonals
 
Description
 
Given an n-sided polygon is defined as the polygon diagonals all segments whose endpoints are any two vertices of the polygon that aren't adjacent. Two vertices in a polygon are adjacent if both delimiting one side. Your task is quite simple, given a number D of diagonals and a number V of vertices you must say whether a polygon composed of V vertices has D diagonal.
 
Input specification
Two integers D and V separated by one space. D = [0, 2^63-1] and V = [3, 2^31-1].
 
Output specification
If the polygon with V vertexes has D diagonals you should print "yes" without the quotes, in any other case print "no".
 
Sample input
2 4
 
Sample output
yes
 
System Constraints:
Time limit (ms) 10000
Test limit (ms) 1000
Memory limit (kb) 130000
Output limit (mb) 64
Size limit (bytes) 100000
 
Solution:
# include <stdio.h>int main () {     long long D, V;        scanf("%lld %lld", &D, &V);          if(V*(V-3LL)/2LL == D) printf("yes");     else printf("no");        return 0;}
 
@Ciccioo i used a formula here lol

------------------------------------

     ~ Live Love Code ~

------------------------------------

Link to comment
Share on other sites

Link to post
Share on other sites

Had a little fun with the diagonal problem

main(int argc, char** argv){    long long d = strtoll(argv[1], 0, 10);    long long v = strtoll(argv[2], 0, 10);    puts("No\0Yes"+!(v*(v-3)/2^d)*3);}

Compiles with warnings

main(i){for(;i<101;i++)printf("Fizz\n\0Fizzz\bBuzz\n\0%d\n"+(!(i%5)^!!(i%3)*3)*6,i);}

Link to comment
Share on other sites

Link to post
Share on other sites

So, this does not have any productive use (it's a command line game of Tic Tac Toe). It's written in C for Linux (developed on a RasPi)

It's not finished yet (you have to manually see who wins) and is probably not as efficient as it could be but I just started learning C last week.

Here's the link to it on my Pastebin

http://pastebin.com/mPE16FxU

 

Sorry if my English is a little wonky. As of writing this it's 02:30 AM and I'm no native speaker.

 

Grettings

-Marius

 

 

-EDIT

 

I made an updated version in C++ (it's 70 Lines long)

 

http://pastebin.com/B2f6tg66

 

It detects when a player wins.

btw I use arch

Link to comment
Share on other sites

Link to post
Share on other sites

Python program I wrote when first learning programming in that language that converts inputs between Binary, Decimal and Hexadecimal values So: Decimal to Hexadecimal, Decimal to Binary, Hexadecimal to Decimal, Hexadecimal to Binary, Binary to Hexadecimal, Binary to Decimal.
Program:



#1
def dec_to_hex():
    print ("Please enter a decimal number that you would like converted to hexadecimal :")
    decimal_input = int(input())
    hexadecimal_output_temp=(hex(int(decimal_input)))
    hexadecimal_output=hexadecimal_output_temp[2:]
    print ("The deciaml number", decimal_input,"is",hexadecimal_output, "in hexadecimal")
    
#2
def dec_to_bin():
    print ("Please enter a decimal number that you would like converted to a binary number :")
    decimal_input= int(input())
    binary_output_temp=bin(int(decimal_input))
    binary_output=binary_output_temp[2:]
    print ("The decimal number", decimal_input, "is", binary_output, "in binary")
    
#3
def hex_to_dec():
    print ("Please enter a hexadecimal number that you would like converted to a decimal number :")
    hexadecimal_input= input()
    decimal_output=int((hexadecimal_input),16)
    print ("The hexadecimal number", hexadecimal_input, "is", decimal_output, "in decimal" )
    
#4
def hex_to_bin():
    print ("Please enter a hexadecimal number that you would like converted to a binary number :")
    hexadecimal_input= input()
    decimal_output=int((hexadecimal_input),16)
    binary_output_temp=bin(int(decimal_output))
    binary_output=binary_output_temp[2:]
    print ("The hexadecimal number", hexadecimal_input, "is", binary_output, "in binary" )
    
#5
def bin_to_hex():
    print ("Please enter a bianry number that you would like converted to a hexadecimal number :")
    binary_input =input()
    hexadecimal_output_temp=hex(int(binary_input, 2))
    hexadecimal_output=hexadecimal_output_temp[2:]
    print ("The binary number", binary_input,"is",hexadecimal_output, "in hexadecimal")
    
#6
def bin_to_dec():
    print ("Please enter a bianry number that you would like converted to a decimal number :")
    binary_input = input()
    decimal_output=(int(binary_input, 2))
    print ("The binary number", binary_input,"is",decimal_output, "in decimal")
"""
Declaring the variables
"""
hexadecimal_input=("")
hexadecimal_output_temp=("")
hexadecimal_output=("")
binary_output_temp=("")
binary_output=("")
decimal_input=("")
decimal_output=("")
run_again=("Y")
 
"""
Main program
"""
print ("Welcome to Tomi's number converter.")
while run_again==("Y"):
    print ("1=Decimal to Hexadecimal")
    print ("2=Decimal to Binary")
    print ("3=Hexadecimal to Decimal")
    print ("4=Hexadecimal to Binary")
    print ("5=Binary to Hexadecimal")
    print ("6=Binary to Decimal")
    option_chosen=int(input("Please choose an option from the list above: "))
    if option_chosen == 1:
        dec_to_hex()
    elif option_chosen == 2:
        dec_to_bin()
    elif option_chosen == 3:
        hex_to_dec()
    elif option_chosen == 4:
        hex_to_bin()
    elif option_chosen == 5:
        bin_to_hex()
    elif option_chosen == 6:
        bin_to_dec()
    run_again=input("Run again? Y/N ").upper()
print ("Thank you for using my number converter")

Link to comment
Share on other sites

Link to post
Share on other sites

I ported my C FizzBuzz solution to an x86 bootloader. Right at 100 lines. Using 165 out of 512 bytes available.

 

Currently working on a version that writes directly to the VGA controller instead of using the BIOS interrupt 10h.

 

If you aren't familiar with FizzBuzz http://c2.com/cgi/wiki?FizzBuzzTest

 

 

Nicely colored source http://pastebin.com/gkPzHFJN

 

 BITS 16 boot:    cli       mov ax, 07C0h    mov ds, ax    mov gs, ax    mov fs, ax    mov es, ax       mov ax, 07E0h    mov ss, ax    mov bp, ax    mov sp, 0FFh       sti  ;;;;;;;;;;;;;;; main(i){for(;i<101;i++)printf("Fizz\n\0Fizzz\bBuzz\n\0%d\n"+(!(i%5)^!!(i%3)*3)*6,i);} fizzbuzz:               ;(!(i%5)^!!(i%3)*3)*6    xor ax, ax       mov al, byte [i]   ;i%5    mov dl, 05h    div byte dl               test ah, 07h        ;!    pushf    pop cx    and cx, 40h    shr cx, 06h       xor ah, ah    mov al, byte [i]    ;i%3    mov dl, 03h    div byte dl     test byte ah, 03h   ;!!    push cx    pushf    pop cx    and cx, 40h    shr cx, 06h    xor cx, 01h    mov al, cl    pop cx       mov dx, 03h         ;*3    mul dx    xor al, cl          ;^    mov dl, 07h             ;*7 instead of 6 for extra char byte CrLf    mul dl       cmp al, 15h    xchg bl, al    jnz  do_print       mov al, byte [i]            ;int to ascii    mov dl, 0Ah    div byte dl    add al, 30h    add ah, 30h    lea si, [bx + fbf]    mov [si], ax   do_print:    lea si, [bx + fbf]            mov cl, 01h         ;repeat char count    call print_string              inc byte [i]    cmp byte [i], 65h    jnz fizzbuzz       cli    hlt       i db 01h    fbf db 'Fizz',13,10,0,'Fizzz',0x8,0x7,'Buzz',13,10,0, 0,0,13,10,0 print_string:                   ; Routine: output string in SI to screen    mov ah, 0Eh             ; int 10h 'print char' function .repeat:    lodsb                   ; Get character from string    cmp al, 0    je .done                ; If char is zero, end of string    int 10h                 ; Otherwise, print it    jmp .repeat .done:    ret         times 510-($-$$) db 0   ; Pad remainder of boot sector with 0s    dw 0xAA55               ; The standard PC boot signature       times 1024*1024 db 0       ;for Bochs

 

Running in the Bochs x86 emulator

OqhJWek.jpg

main(i){for(;i<101;i++)printf("Fizz\n\0Fizzz\bBuzz\n\0%d\n"+(!(i%5)^!!(i%3)*3)*6,i);}

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Line of Sight Propagation calculator. might not work right.

<title>Line of Sight Propagation calculator</title><script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script><script>function calculate(){    var height = $('#in').val();    var response = 3.57*(Math.sqrt(height));    response = Math.round(response*10000)/10000    $('#out').text(response+" Kilometres");    return response;}setInterval(function(){calculate();},50);</script>IN:<input type="number" id="in"></input>Meters<div id="out">0 Kilometres</div>
Link to comment
Share on other sites

Link to post
Share on other sites

Line of Sight Propagation calculator

-snip-

can't help commenting about this:

could just be

jQuery makes people used to weird ugly syntax :(

setInterval(function(){calculate();},50);
setInterval(calculate, 50);
Link to comment
Share on other sites

Link to post
Share on other sites

  • 3 weeks later...

Not sure if this thread has any specific language, but I don't think it does. Here's a really quick quadratic solver I wrote up, calculates roots of desired quadratic equation after inputting a, b and c values.

public class SafeQuadraticSolver {     public static void main(String[] args) {                double a = Double.parseDouble(args[0]);        double b = Double.parseDouble(args[1]);        double c = Double.parseDouble(args[2]);                double discriminant = b*b-(4*a*c);                if (discriminant < 0) {            System.out.println("Equation is not solvable for real x. This equation has                               only imaginary roots (performing square root of a negative number)");        } else if (a == 0) {            System.out.println("A = 0. Cannot solve equation as we cannot divide by 0.");        } else {            System.out.println("First root: " + (-b + Math.sqrt(discriminant))/2*a);            System.out.println("Second root: " + (-b - Math.sqrt(discriminant))/2*a);        }                }  

"The only person you are destined to become is the person you decide to be."


CPU: Intel i5 4690K - Motherboard: Asus Maximus VII Ranger - RAM: Corsair Vengeance LP - 2x4GB @ 1866Mhz - GPU: MSI Twin Frozr GTX 770 4GB - CPU Cooler: Be Quiet! Dark Rock Pro 3 CPU Cooler - PSU: EVGA SuperNova G2 750W - Storage: Seagate Barracuda 2TB HDD- Case: Fractal Design Define R4 Windowed (with Red AKASA Led Strips) - Display: Benq GL2460HM 24" Monitor

Link to comment
Share on other sites

Link to post
Share on other sites

  • 3 weeks later...

Apologies for the earlier post. Feel so stupid. Anyways, here you go. lmk if errors still occur. 

//Rock beats scissors//Scissors beats paper//Paper beats rock    // use Math.random() to call a random numbervar rpsGame = function(choice1, choice2){    if(choice1===choice2)    {        return "The result is a tie!";    }    else if(choice1==="rock")    {        if(choice2==="scissors")        return "User Wins!";        else if(choice2==="paper")        return "AI Wins!";    }    else if(choice1==="paper")    {        if(choice2==="rock")        {            return "User Wins!";        }         else if(choice2==="scissors")        return "AI Wins!";    }    else if(choice1==="scissors")    {        if(choice2==="paper")        {            return "User Wins!";        }         else if(choice2==="rock")        return "AI Wins!";    }};var user;var aiScore=0;var userScore=0;var numRounds = 0; //Default is zerovar numRounds = prompt("Enter number of rounds: ");while(numRounds != 0){    var user = prompt("Rock Paper or Scissors: ");    //generate choice2    var ai = Math.random();    if (ai < 0.33) {        ai = "rock";    } else if(ai <= 0.66) {        ai = "paper";    } else {        ai = "scissors";    }                     if(rpsGame(user,ai)==="AI Wins!")    {        aiScore++;    }    else if(rpsGame(user,ai)==="User Wins!")    {        userScore++;    }    rpsGame(user,ai);    console.log("User Choice: " + user + "\t" +  "AI Choice: " + ai);    console.log("User Score: " + userScore+ "\n" + "AI Score: " + aiScore);    console.log(rpsGame(user, ai));numRounds--;}
Link to comment
Share on other sites

Link to post
Share on other sites

 

A tic tac toe game in Java. It's been made before but eh' I figure why not.

 

but is it not a Rock, Paper, Scissors game?

btw I use arch

Link to comment
Share on other sites

Link to post
Share on other sites

A tic tac toe game in Java. It's been made before but eh' I figure why not.

to to be overly critique, but...

- it's not tic-tac-toe

- it's not java

- it doesn't work (not correctly, at least)

Link to comment
Share on other sites

Link to post
Share on other sites

I feel so stupid... JavaScript not Java & Rock Paper Scissors not TicTacToe.

 

Reposting in a bit.

Link to comment
Share on other sites

Link to post
Share on other sites

import randomimport msvcrt as mnumber = random.randint(1, 1000)guesses = 0while guesses < 10:guess = int(raw_input("Enter an integer from 1 to 1,000: "))guesses +=1print "this is your %d guess" %guessesif guess < number:print "guess is low"elif guess > number:print "guess is high"elif guess == number:breakif guess == number:guesses = str(guesses)print "You guess it in : ", guesses + " guesses"if guess == number:guesses = str(guesses)print "You guess it in : ", guesses + " guesses"if guess != number:number = str(number)print "The secret number was", numberprint "Press any key to exit ..."m.getch()

@xXxYOLOxSWAGxXx_420BlazeIt helped me do the Press any key to exit ... part

 

EDIT: Yes... this is Python

Link to comment
Share on other sites

Link to post
Share on other sites

 

Apologies for the earlier post. Feel so stupid. Anyways, here you go. lmk if errors still occur. 

//Rock beats scissors//Scissors beats paper//Paper beats rock    // use Math.random() to call a random numbervar rpsGame = function(choice1, choice2){    if(choice1===choice2)    {        return "The result is a tie!";    }    else if(choice1==="rock")    {        if(choice2==="scissors")        return "User Wins!";        else if(choice2==="paper")        return "AI Wins!";    }    else if(choice1==="paper")    {        if(choice2==="rock")        {            return "User Wins!";        }         else if(choice2==="scissors")        return "AI Wins!";    }    else if(choice1==="scissors")    {        if(choice2==="paper")        {            return "User Wins!";        }         else if(choice2==="rock")        return "AI Wins!";    }};var user;var aiScore=0;var userScore=0;var numRounds = 0; //Default is zerovar numRounds = prompt("Enter number of rounds: ");while(numRounds != 0){    var user = prompt("Rock Paper or Scissors: ");    //generate choice2    var ai = Math.random();    if (ai < 0.33) {        ai = "rock";    } else if(ai <= 0.66) {        ai = "paper";    } else {        ai = "scissors";    }                     if(rpsGame(user,ai)==="AI Wins!")    {        aiScore++;    }    else if(rpsGame(user,ai)==="User Wins!")    {        userScore++;    }    rpsGame(user,ai);    console.log("User Choice: " + user + "\t" +  "AI Choice: " + ai);    console.log("User Score: " + userScore+ "\n" + "AI Score: " + aiScore);    console.log(rpsGame(user, ai));numRounds--;}

What language is that is it Java, Javascript or am I way off hahaha

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

If this really large texture is cheating I can make some room and generate it in code I guess but here it is. A tic tac toe game where you go up against a cp.

 

The forum scrunches the code up so here is the pastebin to show its less than 100 lines.

http://pastebin.com/HYLrw5XR

 

#include <time.h>#include <string>#include <gl\glut.h>unsigned char gameSpriteO[768] = {0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,255,255,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,255,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,255,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,0,0,0,0,0};unsigned char gameSpriteX[768] = {255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255};unsigned char gameBoard[9408] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,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255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,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0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};int window, mouseButton, mouseClickState, mouseX, mouseY, cpFirstTurn = 1, boardPos = 0, spotIsTaken = 0, whosTurnIsIt = 0, oBlockedYou = 0, timesYouWon = 0;GLuint gameSpriteOTextureId, gameSpriteXTextureId, gameBoardTextureId;int xSAndOs[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };char formatBuf[512];void DrawTexture(int textureId, float x, float y, float width, float height) {	glBindTexture(GL_TEXTURE_2D, textureId);	glBegin(GL_QUADS);	glTexCoord2f(0, 0); glVertex3f(x, y + height, 0); glTexCoord2f(1, 0); glVertex3f(x + width, y + height, 0); // bottom left | bottom right	glTexCoord2f(1, 1); glVertex3f(x + width, y, 0);  glTexCoord2f(0, 1); glVertex3f(x, y, 0); // top right | top left	glEnd();}void MakeTexture(unsigned char* textureData, int textureWidth, int textureHeight, GLuint *outTextureId) {	glGenTextures(1, outTextureId); glBindTexture(GL_TEXTURE_2D, *outTextureId); // init texture stuff	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, textureHeight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, textureData); // generate texture	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // no texture blending}void Reset(char *whoWon) {	sprintf(formatBuf, "%s - %d Times Won\n", whoWon, timesYouWon); glutSetWindowTitle(formatBuf); // Set window message	Sleep(1000); // wait a moment	for (int i = 0; i < 9; i++) xSAndOs[i] = 0; whosTurnIsIt = 0; // clear game board}void DrawGLScene() {	glutReshapeWindow(640, 480); // so I dont have to do any more math	if ((xSAndOs[0] == 1 && xSAndOs[1] == 1 && xSAndOs[2] == 1) || (xSAndOs[3] == 1 && xSAndOs[4] == 1 && xSAndOs[5] == 1) || (xSAndOs[6] == 1 && xSAndOs[7] == 1 && xSAndOs[8] == 1) || (xSAndOs[0] == 1 && xSAndOs[3] == 1 && xSAndOs[6] == 1) || (xSAndOs[1] == 1 && xSAndOs[4] == 1 && xSAndOs[7] == 1) || (xSAndOs[2] == 1 && xSAndOs[5] == 1 && xSAndOs[8] == 1) || (xSAndOs[0] == 1 && xSAndOs[4] == 1 && xSAndOs[8] == 1) || (xSAndOs[2] == 1 && xSAndOs[4] == 1 && xSAndOs[6] == 1)){		timesYouWon++; Reset("X Won"); }	else if ((xSAndOs[0] == 2 && xSAndOs[1] == 2 && xSAndOs[2] == 2) || (xSAndOs[3] == 2 && xSAndOs[4] == 2 && xSAndOs[5] == 2) || (xSAndOs[6] == 2 && xSAndOs[7] == 2 && xSAndOs[8] == 2) || (xSAndOs[0] == 2 && xSAndOs[3] == 2 && xSAndOs[6] == 2) || (xSAndOs[1] == 2 && xSAndOs[4] == 2 && xSAndOs[7] == 2) || (xSAndOs[2] == 2 && xSAndOs[5] == 2 && xSAndOs[8] == 2) || (xSAndOs[0] == 2 && xSAndOs[4] == 2 && xSAndOs[8] == 2) || (xSAndOs[2] == 2 && xSAndOs[4] == 2 && xSAndOs[6] == 2))		Reset("O Won");	else if (xSAndOs[0] != 0 && xSAndOs[1] != 0 && xSAndOs[2] != 0 &&  xSAndOs[3] != 0 && xSAndOs[4] != 0 && xSAndOs[5] != 0 &&  xSAndOs[6] != 0 && xSAndOs[7] != 0 && xSAndOs[8] != 0 )		Reset("Draw");	if (whosTurnIsIt == 1) { // cps turn		oBlockedYou = 0;		for (int i = 0; i < 9; i += 3) { // check horizontal			if (xSAndOs[i] == 1 && xSAndOs[i + 1] == 1 && xSAndOs[i + 2] == 0) {				oBlockedYou = 1, boardPos = i + 2; break; }			else if (xSAndOs[i] == 1 && xSAndOs[i + 1] == 0 && xSAndOs[i + 2] == 1) {				oBlockedYou = 1, boardPos = i + 1; break; }			else if (xSAndOs[i] == 0 && xSAndOs[i + 1] == 1 && xSAndOs[i + 2] == 1) {				oBlockedYou = 1, boardPos = i; break; }		}		for (int i = 0; i < 3; i++) { // check vertical			if (xSAndOs[i] == 1 && xSAndOs[i + 3] == 1 && xSAndOs[i + 6] == 0) {				oBlockedYou = 1, boardPos = i + 6; break; }			else if (xSAndOs[i] == 1 && xSAndOs[i + 3] == 0 && xSAndOs[i + 6] == 1) {				oBlockedYou = 1, boardPos = i + 3; break; }			else if (xSAndOs[i] == 0 && xSAndOs[i + 3] == 1 && xSAndOs[i + 6] == 1) {				oBlockedYou = 1, boardPos = i; break; }		}		if (xSAndOs[0] == 1 && xSAndOs[4] == 1 && xSAndOs[8] == 0) // check diagonal			oBlockedYou = 1, boardPos = 8;		else if (xSAndOs[0] == 1 && xSAndOs[4] == 0 && xSAndOs[8] == 1)			oBlockedYou = 1, boardPos = 4;		else if (xSAndOs[0] == 0 && xSAndOs[4] == 1 && xSAndOs[8] == 1)			oBlockedYou = 1, boardPos = 0;		if (xSAndOs[2] == 1 && xSAndOs[4] == 1 && xSAndOs[6] == 0)			oBlockedYou = 1, boardPos = 6;		else if (xSAndOs[2] == 1 && xSAndOs[4] == 0 && xSAndOs[6] == 1)			oBlockedYou = 1, boardPos = 4;		else if (xSAndOs[2] == 0 && xSAndOs[4] == 1 && xSAndOs[6] == 1)			oBlockedYou = 1, boardPos = 2;			if (!oBlockedYou)			do {				spotIsTaken = xSAndOs[(boardPos = (rand() % 9))] != 0;			} while (spotIsTaken);		xSAndOs[boardPos] = 2;		whosTurnIsIt = !whosTurnIsIt;	}	else if (!whosTurnIsIt && !mouseButton && mouseClickState) // our turn		if (xSAndOs[(mouseX / 200) + ((mouseY / 150) * 3)] == 0) {			xSAndOs[(mouseX / 200) + ((mouseY / 150) * 3)] = (whosTurnIsIt + 1);			whosTurnIsIt = !whosTurnIsIt;		}	DrawTexture(gameBoardTextureId, 0, 0, 56, 56);	for (int y = 0; y < 3; y++)		for (int x = 0; x < 3; x++)			if (xSAndOs[x + (y * 3)])				DrawTexture(xSAndOs[x + (y * 3)], ((56 / 3) * x) + (x + 1), ((56 / 3) * y) + (y + 1), 16, 16);	glutSwapBuffers();	mouseButton = 0, mouseClickState = 0, mouseX = 0, mouseY = 0;}void MouseEvent(int button, int state, int x, int y) { mouseButton = button, mouseClickState = state, mouseX = x, mouseY = y; }void main(int argc, char **argv)  {	glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA); glutInitWindowSize(640, 480); // inits	window = glutCreateWindow("Gl Tic Tac Toe"); // window creation	glutDisplayFunc(&DrawGLScene); glutIdleFunc(&DrawGLScene); glutMouseFunc(&MouseEvent); // glut events	MakeTexture(gameSpriteX, 16, 16, &gameSpriteXTextureId); MakeTexture(gameSpriteO, 16, 16, &gameSpriteOTextureId); MakeTexture(gameBoard, 56, 56, &gameBoardTextureId); // make textures	glMatrixMode(GL_PROJECTION); glOrtho(0.0f, 56, 56, 0.0f, 0.0f, 1); glMatrixMode(GL_MODELVIEW); // viewport setup	glEnable(GL_TEXTURE_2D); srand(time(0)); // enable textures and seeding random numbers	glutMainLoop(); // start glut main loop} 

a

Link to comment
Share on other sites

Link to post
Share on other sites

 

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            double VAT;
            double markUp;
            double trueVAT;
            double trueMarkUp;
            double startingPrice;
            double salePrice;
            bool input = true;
            string response = null;
            while (input == true)
            {
 
                Console.Write("Enter item price here: ");
                startingPrice = Convert.ToDouble(Console.ReadLine());
                Console.Write("Enter markup percentage on item here: ");
                markUp = Convert.ToDouble(Console.ReadLine());
                Console.Write("Is VAT applicable? Y/N: ");
                response = Console.ReadLine();
                if (response == "Y" || response == "y")
                {
                    Console.Write("Enter VAT percentage here: ");
                    VAT = Convert.ToDouble(Console.ReadLine());
                }
                else
                {
                    VAT = 0;
                }
                trueVAT = (VAT / 100) + 1;
                trueMarkUp = (markUp / 100) + 1;
                salePrice = (startingPrice * trueMarkUp) * trueVAT;
                Console.WriteLine("Your buying price is £{0}, and your sale price is £{1}", startingPrice, salePrice);
                Console.WriteLine("Calculate another item? Y/N: ");
                string addNew = "y";
                if (addNew == "Y" || response == "y")
                {
                    input = true;
                }
                else
                {
                    input = false;
                }
            }
        }
    }
}

Calculates a final price based on purchase price, markup and VAT.

 

:)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×