Page 5 of 6 FirstFirst ... 3456 LastLast
Results 101 to 125 of 142
Like Tree22Likes

Thread: The Code Marathon.

  1. #101
    -insert title here- Paradoxica's Avatar
    Join Date
    Jun 2014
    HSC
    2016
    Gender
    Male
    Location
    Outside reality
    Posts
    2,440
    Rep Power
    5

    Re: The Code Marathon.

    Quote Originally Posted by porcupinetree View Post
    Write a method/program which displays Pascal's triangle up to n rows, n a given positive integer.
    It was never stated we had to write out the integers themselves... Could also leave it in binomial coefficient notation...
    If I am a conic section, then my e = ∞

    Just so we don't have this discussion in the future, my definition of the natural numbers includes 0.

  2. #102
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,956
    Rep Power
    6

    Re: The Code Marathon.

    Java sucks. C for life
    Flop21 likes this.
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  3. #103
    Junior Member parad0xica's Avatar
    Join Date
    Mar 2016
    HSC
    N/A
    Gender
    Male
    Posts
    204
    Rep Power
    2

    Re: The Code Marathon.

    Question: write a program to count the number of words in a text file.
    Clue 1: 121 112
    Who am I?

    ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°)Clue 2

    Clue 0: Clockwise

    Clue 3: Are you watching closely? ∃ a clue every now and then
    Clue 4: 99 115
    Clue 5: |℘(S)| = 15^2 + 31

  4. #104
    Executive Member Rhinoz8142's Avatar
    Join Date
    Jul 2013
    HSC
    2014
    Uni Grad
    2018
    Gender
    Male
    Location
    Sydney
    Posts
    1,350
    Rep Power
    4

    Re: The Code Marathon.

    public static void main

    {
    count words;
    ++count
    }

    Quote Originally Posted by Oer View Post
    I am grateful for Rhino's existence

  5. #105
    Executive Member Rhinoz8142's Avatar
    Join Date
    Jul 2013
    HSC
    2014
    Uni Grad
    2018
    Gender
    Male
    Location
    Sydney
    Posts
    1,350
    Rep Power
    4

    Re: The Code Marathon.

    jks

    Quote Originally Posted by Oer View Post
    I am grateful for Rhino's existence

  6. #106
    The optimistic pessimist. FlyingKanga's Avatar
    Join Date
    Dec 2012
    HSC
    2015
    Gender
    Male
    Posts
    412
    Rep Power
    5

    Re: The Code Marathon.

    Quote Originally Posted by parad0xica View Post
    Question: write a program to count the number of words in a text file.
    Java:
    Code:
    import java.util.*;
    import java.io.*;
    public class wordCount {
    	public static void main(String[] args) {
    		File newFile = new File(args[0]);
    		int count = 0;
    		try {
    			Scanner scan = new Scanner(newFile);
    			while (scan.hasNext()) {
    				String word = scan.nextLine();
    				String[] words = word.split("\\s+");
    				count += words.length;
    			}
    		} catch(Exception err) {
    			System.out.println("Not found");
    		}
    
    		System.out.println("Total words: " + count);	
    
    		}
    	}

  7. #107
    Loquacious One Drsoccerball's Avatar
    Join Date
    May 2014
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,664
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by parad0xica View Post
    Question: write a program to count the number of words in a text file.
    C code :

    Code:
    #include <stdio.h>
    #define MAX_CHARACTERS 1000
    #define MAX_LINE 100
    
    int main(int argc, char *argv[]){
    	FILE *stream = fopen(argv[1], "r");
    
    	if(stream == NULL){
    		printf("The file %s doesn't exist.\n", argv[1]);
    		return 1;
    	}
    	char file[MAX_LINE][MAX_CHARACTERS];
    	int j = 0;
    	while(fgets(file[j], MAX_CHARACTERS, stream) != NULL){
    		j++;
    	}
    	int i = 0;
    	j = 0;
    	int character = 0;
    
    	while(file[j][i] != '\0'){
    		while(file[j][i] != '\0'){
    			if((file[j][i] >= 'a' && file[j][i] <= 'z') || (file[j][i] >= 'A' && file[j][i] <= 'Z')){
    				character++;
    			}
    			i++;
    		}
    		i = 0;
    		j++;
    	}
    	printf("The text file %s has %d characters.\n", argv[1],character);
    	fclose(stream);
    	return 0;
    }

  8. #108
    Loquacious One Drsoccerball's Avatar
    Join Date
    May 2014
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,664
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by porcupinetree View Post
    Write a method/program which displays Pascal's triangle up to n rows, n a given positive integer.
    Do this but with letters.
    ./triangle 3
    A
    BCB
    DEFED
    (Click reply to quote to see how the triangle should look)
    When the letter reaches Z loop around.

  9. #109
    Junior Member parad0xica's Avatar
    Join Date
    Mar 2016
    HSC
    N/A
    Gender
    Male
    Posts
    204
    Rep Power
    2

    Re: The Code Marathon.

    Quote Originally Posted by Drsoccerball View Post
    C code :

    Code:
    #include <stdio.h>
    #define MAX_CHARACTERS 1000
    #define MAX_LINE 100
    
    int main(int argc, char *argv[]){
    	FILE *stream = fopen(argv[1], "r");
    
    	if(stream == NULL){
    		printf("The file %s doesn't exist.\n", argv[1]);
    		return 1;
    	}
    	char file[MAX_LINE][MAX_CHARACTERS];
    	int j = 0;
    	while(fgets(file[j], MAX_CHARACTERS, stream) != NULL){
    		j++;
    	}
    	int i = 0;
    	j = 0;
    	int character = 0;
    
    	while(file[j][i] != '\0'){
    		while(file[j][i] != '\0'){
    			if((file[j][i] >= 'a' && file[j][i] <= 'z') || (file[j][i] >= 'A' && file[j][i] <= 'Z')){
    				character++;
    			}
    			i++;
    		}
    		i = 0;
    		j++;
    	}
    	printf("The text file %s has %d characters.\n", argv[1],character);
    	fclose(stream);
    	return 0;
    }
    My bad. I should have defined what a word means. A word is a string containing no spaces.

    "Mathematics is fun. Have a nice day, G." contains 8 words
    Clue 1: 121 112
    Who am I?

    ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°)Clue 2

    Clue 0: Clockwise

    Clue 3: Are you watching closely? ∃ a clue every now and then
    Clue 4: 99 115
    Clue 5: |℘(S)| = 15^2 + 31

  10. #110
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,956
    Rep Power
    6

    Re: The Code Marathon.

    Create a compiler that compiles a programming language you made up.
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  11. #111
    Loquacious One Drsoccerball's Avatar
    Join Date
    May 2014
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,664
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by parad0xica View Post
    My bad. I should have defined what a word means. A word is a string containing no spaces.

    "Mathematics is fun. Have a nice day, G." contains 8 words
    Im pretty sure my program does this? I accidentally wrote 'characters' instead of 'words' though.

    EDIT: brb

  12. #112
    Loquacious One Drsoccerball's Avatar
    Join Date
    May 2014
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,664
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by parad0xica View Post
    My bad. I should have defined what a word means. A word is a string containing no spaces.

    "Mathematics is fun. Have a nice day, G." contains 8 words
    My code assumes that only valid inputs are given :P.
    Code:
     
    #include <stdio.h>
    #include <ctype.h>
    #define MAX_CHARACTERS 1000
    #define MAX_LINE 100
    
    int main(int argc, char *argv[]){
    	FILE *stream = fopen(argv[1], "r");
    
    	if(stream == NULL){
    		printf("The file %s doesn't exist.\n", argv[1]);
    		return 1;
    	}
    	char file[MAX_LINE][MAX_CHARACTERS];
    	int j = 0;
    	while(fgets(file[j], MAX_CHARACTERS, stream) != NULL){
    		j++;
    	}
    	int i = 0;
    	j = 0;
    	int character = 0;
    
    	while(file[j][i] != '\0'){
    		while(file[j][i] != '\0'){
    			if(((file[j][i] >= 'a' && file[j][i] <= 'z') || (file[j][i] >= 'A' && file[j][i] <= 'Z'))){
    				if(isspace(file[j][i + 1]) != 0){
    					character++;
    				}
    			}
    			else if(((file[j][i - 1] >= 'a' && file[j][i - 1] <= 'z') || (file[j][i - 1] >= 'A' && file[j][i - 1] <= 'Z'))){
    				if(isspace(file[j][i + 1]) != 0){
    					character++;
    				}
    			}
    			i++;
    		}
    		i = 0;
    		j++;
    	}
    	printf("The text file %s has %d words.\n", argv[1],character);
    	fclose(stream);
    	return 0;
    }

  13. #113
    Junior Member parad0xica's Avatar
    Join Date
    Mar 2016
    HSC
    N/A
    Gender
    Male
    Posts
    204
    Rep Power
    2

    Re: The Code Marathon.

    That's better but it still fails for a text-file containing:

    Mathematics is fun. Have a nice day, G.

    Your program produces 7.
    Clue 1: 121 112
    Who am I?

    ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°)Clue 2

    Clue 0: Clockwise

    Clue 3: Are you watching closely? ∃ a clue every now and then
    Clue 4: 99 115
    Clue 5: |℘(S)| = 15^2 + 31

  14. #114
    Loquacious One Drsoccerball's Avatar
    Join Date
    May 2014
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,664
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by parad0xica View Post
    That's better but it still fails for a text-file containing:

    Mathematics is fun. Have a nice day, G.

    Your program produces 7.
    I don't want to abuse the if statements so ill leave my program broken :P

  15. #115
    The optimistic pessimist. FlyingKanga's Avatar
    Join Date
    Dec 2012
    HSC
    2015
    Gender
    Male
    Posts
    412
    Rep Power
    5

    Re: The Code Marathon.

    Quote Originally Posted by parad0xica View Post
    That's better but it still fails for a text-file containing:

    Mathematics is fun. Have a nice day, G.

    Your program produces 7.
    Mine works right? It just splits each word whenever there's a space in between. But then it'll have day, as a word .-.

  16. #116
    Junior Member parad0xica's Avatar
    Join Date
    Mar 2016
    HSC
    N/A
    Gender
    Male
    Posts
    204
    Rep Power
    2

    Re: The Code Marathon.

    Quote Originally Posted by FlyingKanga View Post
    Mine works right? It just splits each word whenever there's a space in between. But then it'll have day, as a word .-.
    seems right
    Clue 1: 121 112
    Who am I?

    ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°)Clue 2

    Clue 0: Clockwise

    Clue 3: Are you watching closely? ∃ a clue every now and then
    Clue 4: 99 115
    Clue 5: |℘(S)| = 15^2 + 31

  17. #117
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,956
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by i1337 View Post
    instructions not clear enough, accidentally created my own OS

    Sent via i1337OS
    me too thanks
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  18. #118
    Executive Member KingOfActing's Avatar
    Join Date
    Oct 2015
    HSC
    2016
    Gender
    Male
    Location
    Sydney
    Posts
    996
    Rep Power
    3

    Re: The Code Marathon.

    Quote Originally Posted by turntaker View Post
    Create a compiler that compiles a programming language you made up.
    low key want to do this

    I'll make brainfuck 2.0
    2015 HSC
    Mathematics 2U
    2016 HSC
    Advanced English, Drama, Maths 3U, Maths 4U, Music 2, Extension Music, Chemistry, Software Design & Development
    Currently studying
    Advanced Mathematics (Hons)/Computer Science @ UNSW (2017– )

  19. #119
    Supreme Member Flop21's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Female
    Posts
    2,850
    Rep Power
    5

    Re: The Code Marathon.

    bump
    2015 HSC: English Adv, Mathematics, Business Studies, Biology, Multimedia.

    HSC Biology Flashcards

  20. #120
    Executive Member KingOfActing's Avatar
    Join Date
    Oct 2015
    HSC
    2016
    Gender
    Male
    Location
    Sydney
    Posts
    996
    Rep Power
    3

    The Code Marathon.

    I'm not quite sure what you mean

    To do Key-Value mappings I'd just use a HashMap, why recreate the wheel? Also why the "no method" restriction? Do you mean no static methods or no methods at all? None at all means you can't even print anything... Unless you meant no creation of ADDITIONAL methods, in which case the following (awful) code would fit all the requirements:

    Code:
    public class Entry
    {
        public final K key;
        public final V value; 
    
        public Entry(K key, V value) {
            this.key = key;
            this.value = value;
        }
    }
    Then your "app" would have an array of these, it would cycle through them and compare keys to the input key, and once a match is found the value is printed.

    This implementation is not OO though. The key idea of OOP is that objects aren't just 'things' that hold data - objects are defined by behaviour and well, this object has none. not to mention it's completely inefficient - like I said, don't reinvent the wheel!

    Why am I not studying for my trial tomorrow?
    2015 HSC
    Mathematics 2U
    2016 HSC
    Advanced English, Drama, Maths 3U, Maths 4U, Music 2, Extension Music, Chemistry, Software Design & Development
    Currently studying
    Advanced Mathematics (Hons)/Computer Science @ UNSW (2017– )

  21. #121
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,956
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by KingOfActing View Post
    I'm not quite sure what you mean

    To do Key-Value mappings I'd just use a HashMap, why recreate the wheel? Also why the "no method" restriction? Do you mean no static methods or no methods at all? None at all means you can't even print anything... Unless you meant no creation of ADDITIONAL methods, in which case the following (awful) code would fit all the requirements:

    Code:
    public class Entry
    {
        public final K key;
        public final V value; 
    
        public Entry(K key, V value) {
            this.key = key;
            this.value = value;
        }
    }
    Then your "app" would have an array of these, it would cycle through them and compare keys to the input key, and once a match is found the value is printed.

    This implementation is not OO though. The key idea of OOP is that objects aren't just 'things' that hold data - objects are defined by behaviour and well, this object has none. not to mention it's completely inefficient - like I said, don't reinvent the wheel!

    Why am I not studying for my trial tomorrow?
    Create a program that does your trials for you.
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  22. #122
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,956
    Rep Power
    6

    Re: The Code Marathon.

    Yep, I agree with KoA. The whole idea of OOP is that classes are defined by the operations(methods) not their fields.
    Saying that no methods are allowed goes against the nature of OO.
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  23. #123
    Executive Member KingOfActing's Avatar
    Join Date
    Oct 2015
    HSC
    2016
    Gender
    Male
    Location
    Sydney
    Posts
    996
    Rep Power
    3

    Re: The Code Marathon.

    Quote Originally Posted by turntaker View Post
    Create a program that does your trials for you.
    Code:
    for(Trial trial : trials)
    {
        while(!trial.isTimeUp())
        {
            trial.getExamPaper().fill(new Random().nextBoolean() ? Writing.BULLSHIT : Writing.GOOD_CONTENT);
        }
    }
    System.giveUp();
    ThreeSciences likes this.
    2015 HSC
    Mathematics 2U
    2016 HSC
    Advanced English, Drama, Maths 3U, Maths 4U, Music 2, Extension Music, Chemistry, Software Design & Development
    Currently studying
    Advanced Mathematics (Hons)/Computer Science @ UNSW (2017– )

  24. #124
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,956
    Rep Power
    6

    Re: The Code Marathon.

    System.giveUp();

    lmao
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  25. #125
    Executive Member KingOfActing's Avatar
    Join Date
    Oct 2015
    HSC
    2016
    Gender
    Male
    Location
    Sydney
    Posts
    996
    Rep Power
    3

    Re: The Code Marathon.

    Quote Originally Posted by i1337 View Post
    You can use built in ones (obviously) but not custom made ones. In practice it'd be better using methods but I found it helped me understand it better doing it this way.

    (stupid justification I know lol, but it helped me)

    Ill clarify more when I get home
    But that's not object oriented - the whole point of the object oriented programming paradigm is to define objects that follow behaviours, such that the internals of the objects can be changed in any way without affecting the methods (behaviours) that define them. All the internal parts of an object should be kept private and inaccessible except for crucial parts.

    Anyway, since you say you can use built in methods:

    Code:
    Map<K,V> map = new HashMap<>();
    map.put(foo, bar); //placing entries in map
    System.out.println(map.get(foo)); //retrieving entries from map
    2015 HSC
    Mathematics 2U
    2016 HSC
    Advanced English, Drama, Maths 3U, Maths 4U, Music 2, Extension Music, Chemistry, Software Design & Development
    Currently studying
    Advanced Mathematics (Hons)/Computer Science @ UNSW (2017– )

Page 5 of 6 FirstFirst ... 3456 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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