Upvote Upvoted 31 Downvote Downvoted
1 2 3
help me with my coding hw
posted in Off Topic
31
#31
8 Frags +

Kudos to anyone who can identify this language without googling it.

hangman := function()
  local answer, badguesses, guess, i, nrguesses, secret, stream;

  secret := "recitative";
  answer := List([1 .. Length(secret)], x -> '*');
  ConvertToStringRep(answer);
  nrguesses := 7;
  badguesses := 0;
  stream := InputTextUser();

  while badguesses < nrguesses do
    Print("Guess a letter: \c");
    guess := ReadLine(stream)[1];

    if guess in secret then
      Print("Good guess \n");
      for i in PositionsProperty(secret, x -> x = guess) do
        answer[i] := guess;
      od;

    else 
      Print("Bad guess \n");
      badguesses := badguesses + 1;
    fi;

    Print(answer, "\n");
    if answer = secret then
      Print("You win!");
      return;
    fi;
  od;

  Print("You failed miserably. The word was ", secret, ".");
  return;

end;
Kudos to anyone who can identify this language without googling it.

[code]
hangman := function()
local answer, badguesses, guess, i, nrguesses, secret, stream;

secret := "recitative";
answer := List([1 .. Length(secret)], x -> '*');
ConvertToStringRep(answer);
nrguesses := 7;
badguesses := 0;
stream := InputTextUser();

while badguesses < nrguesses do
Print("Guess a letter: \c");
guess := ReadLine(stream)[1];

if guess in secret then
Print("Good guess \n");
for i in PositionsProperty(secret, x -> x = guess) do
answer[i] := guess;
od;

else
Print("Bad guess \n");
badguesses := badguesses + 1;
fi;

Print(answer, "\n");
if answer = secret then
Print("You win!");
return;
fi;
od;

Print("You failed miserably. The word was ", secret, ".");
return;

end;[/code]
32
#32
SizzlingStats
14 Frags +

I don't know C++, but here's a Ruby solution.
http://ideone.com/ZBHh4e

@secret = 'ayy'
@answer = '___'
@mistakes = 7

def fuck! ass
  @mistakes -= 1 if ass.each{|i| @answer[i] = @secret[i]}.empty?
end

def shit dick
  (0...@secret.length).select{|i| @secret[i] == dick}
end

def balls
  puts "Clue: #{@answer}\nGuess a letter:"
  gets[0]
end

fuck! shit balls while @answer != @secret && @mistakes > 0

puts @answer == @secret ? 'you win' : 'fuck you'
I don't know C++, but here's a Ruby solution.
http://ideone.com/ZBHh4e

[code]
@secret = 'ayy'
@answer = '___'
@mistakes = 7

def fuck! ass
@mistakes -= 1 if ass.each{|i| @answer[i] = @secret[i]}.empty?
end

def shit dick
(0...@secret.length).select{|i| @secret[i] == dick}
end

def balls
puts "Clue: #{@answer}\nGuess a letter:"
gets[0]
end

fuck! shit balls while @answer != @secret && @mistakes > 0

puts @answer == @secret ? 'you win' : 'fuck you'
[/code]
33
#33
SizzlingStats
10 Frags +
SimKudos to anyone who can identify this language without googling it.

lol if you search "ConvertToStringRep" this thread is on the front page of results

[quote=Sim]Kudos to anyone who can identify this language without googling it.
[/quote]

lol if you search "ConvertToStringRep" this thread is on the front page of results
34
#34
-5 Frags +

Can we get a machine language solition?

Can we get a machine language solition?
35
#35
-2 Frags +
SimKudos to anyone who can identify this language without googling it.
hangman := function()
  local answer, badguesses, guess, i, nrguesses, secret, stream;

  secret := "recitative";
  answer := List([1 .. Length(secret)], x -> '*');
  ConvertToStringRep(answer);
  nrguesses := 7;
  badguesses := 0;
  stream := InputTextUser();

  while badguesses < nrguesses do
    Print("Guess a letter: \c");
    guess := ReadLine(stream)[1];

    if guess in secret then
      Print("Good guess \n");
      for i in PositionsProperty(secret, x -> x = guess) do
        answer[i] := guess;
      od;

    else 
      Print("Bad guess \n");
      badguesses := badguesses + 1;
    fi;

    Print(answer, "\n");
    if answer = secret then
      Print("You win!");
      return;
    fi;
  od;

  Print("You failed miserably. The word was ", secret, ".");
  return;

end;

Mapleeeee

[quote=Sim]Kudos to anyone who can identify this language without googling it.

[code]
hangman := function()
local answer, badguesses, guess, i, nrguesses, secret, stream;

secret := "recitative";
answer := List([1 .. Length(secret)], x -> '*');
ConvertToStringRep(answer);
nrguesses := 7;
badguesses := 0;
stream := InputTextUser();

while badguesses < nrguesses do
Print("Guess a letter: \c");
guess := ReadLine(stream)[1];

if guess in secret then
Print("Good guess \n");
for i in PositionsProperty(secret, x -> x = guess) do
answer[i] := guess;
od;

else
Print("Bad guess \n");
badguesses := badguesses + 1;
fi;

Print(answer, "\n");
if answer = secret then
Print("You win!");
return;
fi;
od;

Print("You failed miserably. The word was ", secret, ".");
return;

end;[/code][/quote]

Mapleeeee
36
#36
6 Frags +
technosexSimKudos to anyone who can identify this language without googling it.
lol if you search "ConvertToStringRep" this thread is on the front page of results

It can't be an obscure language, it's one of the syntax highlighting styles in gedit!

diamond0wnerMapleeeee

Please, my life is a Maple-free zone.

[quote=technosex][quote=Sim]Kudos to anyone who can identify this language without googling it.
[/quote]

lol if you search "ConvertToStringRep" this thread is on the front page of results[/quote]

It can't be an obscure language, it's one of the syntax highlighting styles in gedit!


[quote=diamond0wner]
Mapleeeee[/quote]
Please, my life is a Maple-free zone.
37
#37
16 Frags +

I know C++, but here's a scheme solution.

(define maxincorrect 7)

(define (hasWon secret position)
	(= (string-length secret) position))

(define (hasLost incorrect)
	(= incorrect maxincorrect))

(define (currentGuess secret position)
	(string-append "Current guess: " (substring secret 0 position) "\n"))

(define (correctGuess secret position)
	(substring secret position (+ position 1)))

(define (play secret position incorrect)
	(cond
		((hasWon secret position) (display "you win! pootis!\n"))
		((hasLost incorrect) (display "you lost! dingus!\n"))

		(else ((display (currentGuess secret position))
			(display "Take a Guess: ")
			(if (string=? (correctGuess secret position) (read))
				((display "Correct guess!\n")
					(play secret (+ position 1) incorrect))
				((display "Incorrect guess!\n")
 					(play secret position (+ incorrect 1))))))))

(play "hi" 0 0)
I know C++, but here's a scheme solution.
[code](define maxincorrect 7)

(define (hasWon secret position)
(= (string-length secret) position))

(define (hasLost incorrect)
(= incorrect maxincorrect))

(define (currentGuess secret position)
(string-append "Current guess: " (substring secret 0 position) "\n"))

(define (correctGuess secret position)
(substring secret position (+ position 1)))

(define (play secret position incorrect)
(cond
((hasWon secret position) (display "you win! pootis!\n"))
((hasLost incorrect) (display "you lost! dingus!\n"))

(else ((display (currentGuess secret position))
(display "Take a Guess: ")
(if (string=? (correctGuess secret position) (read))
((display "Correct guess!\n")
(play secret (+ position 1) incorrect))
((display "Incorrect guess!\n")
(play secret position (+ incorrect 1))))))))

(play "hi" 0 0)
[/code]
38
#38
20 Frags +

haskell solution

secret = "opscodesucks"

hangman :: Int -> Char -> String -> (Int, String)
hangman tries guess word
  | guess `elem` word = (tries, filter (guess /=) word)
  | otherwise         = (tries-1, word)

printHangman :: String -> String -> String
printHangman hiddenChars [] = []
printHangman hiddenChars (x:xs)
  | x `elem` hiddenChars = '_' : printHangman hiddenChars xs
  | otherwise            = x : printHangman hiddenChars xs

playHangman :: String -> Int -> IO Bool
playHangman [] _           = do return True
playHangman _  0           = do return False
playHangman word tries = do
  putStrLn $ printHangman word secret
  putStrLn $ "Tries left: " ++ show tries
  putStr "Enter a letter: "
  guess <- getLine
  let (triesAfter, stillHidden) = hangman tries (head guess) word
  playHangman stillHidden triesAfter

main :: IO ()
main = do
  win <- playHangman secret 7
  if win then putStrLn "You win" else putStrLn "You lose"
haskell solution

[code]secret = "opscodesucks"

hangman :: Int -> Char -> String -> (Int, String)
hangman tries guess word
| guess `elem` word = (tries, filter (guess /=) word)
| otherwise = (tries-1, word)

printHangman :: String -> String -> String
printHangman hiddenChars [] = []
printHangman hiddenChars (x:xs)
| x `elem` hiddenChars = '_' : printHangman hiddenChars xs
| otherwise = x : printHangman hiddenChars xs

playHangman :: String -> Int -> IO Bool
playHangman [] _ = do return True
playHangman _ 0 = do return False
playHangman word tries = do
putStrLn $ printHangman word secret
putStrLn $ "Tries left: " ++ show tries
putStr "Enter a letter: "
guess <- getLine
let (triesAfter, stillHidden) = hangman tries (head guess) word
playHangman stillHidden triesAfter

main :: IO ()
main = do
win <- playHangman secret 7
if win then putStrLn "You win" else putStrLn "You lose"[/code]
39
#39
10 Frags +

I don't know C++ but heres a java solution

import java.util.Scanner;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

/**
 * The hangman class includes few methods connected with the hangman game Also includes game method that allows the user
 * to play a round of hangman
 *
 * 
 */
public class Hangman {
    static final Logger LOGGER = LoggerFactory.getLogger(ArrayProccesing.class);
    static Scanner scanner = new Scanner(System.in);

    /**
     * This method returns the capitalized version of the letter as a char. If the character is already a capital
     * letter, no changes are made.
     *
     * @param character
     *            the character that will be capitalized
     * @return capitalized character
     */
    static char capitalize(char character) {
        if (character >= 'a' && character <= 'z') {
            character -= 32;
        }
        return character;
    }

    /**
     * This method returns the capitalized version of a string as every non capital letter in the string is being
     * capitalized.
     *
     * @param str
     *            string that is going to be capitalized
     * @return capitalized string
     */
    static String capitalize(String str) {
        StringBuilder strBuilder = new StringBuilder(str);
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') {
                strBuilder.setCharAt(i, capitalize(str.charAt(i)));
            }
        }
        return strBuilder.toString();
    }

    /**
     * This method reveals a hidden character from a hangman word.
     *
     * @param originalWord
     *            full word e.g."Example"
     * @param unfinishedWord
     *            hidden word e.g."E _ _ _ _ _ E"
     * @param letter
     *            letter that will reveal in the unfinished word
     * @return new unfinished word with revealed letter
     */
    static String hangmanLetterReveal(String originalWord, String unfinishedWord, char letter) {
        StringBuilder stringBuilder = new StringBuilder(unfinishedWord);
        for (int i = 0; i < originalWord.length(); i++) {
            if (originalWord.charAt(i) == letter) {
                stringBuilder.setCharAt(i, letter);
            }
        }
        return stringBuilder.toString();
    }

    /**
     * Makes a string to a hidden string, showing only the first and the last letter
     *
     * @param secredWord
     *            full word e.g."Example"
     * @return encrypted word e.g."E _ _ _ _ _ E"
     */
    static String transferWordForHangman(String secredWord) {
        StringBuilder hangmanWordBuilder = new StringBuilder(secredWord);
        String hangmanWord;

        for (int i = 1; i < secredWord.length() - 1; i++) {
            hangmanWordBuilder.setCharAt(i, '_');
        }

        hangmanWord = hangmanWordBuilder.toString();
        hangmanWord = hangmanLetterReveal(secredWord, hangmanWordBuilder.toString(), secredWord.charAt(0));
        hangmanWord = hangmanLetterReveal(secredWord, hangmanWordBuilder.toString(),
                secredWord.charAt(secredWord.length() - 1));

        return hangmanWord;
    }

    /**
     * Print information about the current state of the game.
     *
     * @param round
     *            the number of the following round
     * @param seenWord
     *            the encrypted word that the player sees
     * @param usedLetters
     *            the letter that the player had already used
     * @param lives
     *            the number of the remaining lives
     */
    public static void printRoundInformation(int round, String seenWord, char[] usedLetters, int lives) {
        LOGGER.info(" ");
        LOGGER.info("Round {}:", round);
        LOGGER.info("Word to guess: {}", seenWord);
        LOGGER.info("Lives: {}", lives);
        LOGGER.info("Used letters: {}", String.valueOf(usedLetters));
    }

    /**
     * Check a given character if it is a letter or not using the ASCII table
     *
     * @param character
     *            that will be tested if it's a letter or not
     * @return true if the character is letter and false if it's not
     */
    public static boolean charIsLetter(char character) {
        return ((character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z'));
    }

    /**
     * Checks if given character is in a given string
     *
     * @param character
     *            that will be searched for
     * @param str
     *            the string that may have the character
     * @return true if the character is within the string, false if not.
     */
    public static boolean charIsInString(char character, String str) {
        for (int i = 0; i < str.length(); i++) {
            if (character == str.charAt(i)) {
                return true;
            }
        }
        return false;

    }

    /**
     * Plays a game of Hangman until the player have guessed the word or lost all his lives
     *
     * @param secredWord the word that the player will have to guess
     */
    public static void play(String secredWord) {
        int lives = 5;
        int round = 0;
        char[] usedLetters = new char[26];

        for (int i = 0; i < usedLetters.length; i++) {
            usedLetters[i] = ' ';
        }

        int numUsedLetters = 0;
        String seenWord;
        char chosenLetter;

        secredWord = capitalize(secredWord);
        seenWord = transferWordForHangman(secredWord);

        while (lives > 0 && !secredWord.equals(seenWord)) {
            round++;
            printRoundInformation(round, seenWord, usedLetters, lives);

            chosenLetter = ' ';
            while (!charIsLetter(chosenLetter)) {
                LOGGER.info("Guess a letter: ");
                chosenLetter = scanner.nextLine().charAt(0);
            }
            chosenLetter = capitalize(chosenLetter);
            usedLetters[numUsedLetters++] = chosenLetter;

            if (charIsInString(chosenLetter, secredWord)) {
                LOGGER.info("You guessed right!");
                seenWord = hangmanLetterReveal(secredWord, seenWord, chosenLetter);
            } else {
                LOGGER.info("You guessed wrong! You lose one of your life points.");
                lives--;
            }
        }

        if (lives <= 0) {
            LOGGER.info("You LOST!");
        } else if (secredWord.equals(seenWord)) {
            LOGGER.info("Congratulations! You WON!");
        }

    }

}
I don't know C++ but heres a java solution


[code]
import java.util.Scanner;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;



/**
* The hangman class includes few methods connected with the hangman game Also includes game method that allows the user
* to play a round of hangman
*
*
*/
public class Hangman {
static final Logger LOGGER = LoggerFactory.getLogger(ArrayProccesing.class);
static Scanner scanner = new Scanner(System.in);

/**
* This method returns the capitalized version of the letter as a char. If the character is already a capital
* letter, no changes are made.
*
* @param character
* the character that will be capitalized
* @return capitalized character
*/
static char capitalize(char character) {
if (character >= 'a' && character <= 'z') {
character -= 32;
}
return character;
}

/**
* This method returns the capitalized version of a string as every non capital letter in the string is being
* capitalized.
*
* @param str
* string that is going to be capitalized
* @return capitalized string
*/
static String capitalize(String str) {
StringBuilder strBuilder = new StringBuilder(str);
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') {
strBuilder.setCharAt(i, capitalize(str.charAt(i)));
}
}
return strBuilder.toString();
}

/**
* This method reveals a hidden character from a hangman word.
*
* @param originalWord
* full word e.g."Example"
* @param unfinishedWord
* hidden word e.g."E _ _ _ _ _ E"
* @param letter
* letter that will reveal in the unfinished word
* @return new unfinished word with revealed letter
*/
static String hangmanLetterReveal(String originalWord, String unfinishedWord, char letter) {
StringBuilder stringBuilder = new StringBuilder(unfinishedWord);
for (int i = 0; i < originalWord.length(); i++) {
if (originalWord.charAt(i) == letter) {
stringBuilder.setCharAt(i, letter);
}
}
return stringBuilder.toString();
}

/**
* Makes a string to a hidden string, showing only the first and the last letter
*
* @param secredWord
* full word e.g."Example"
* @return encrypted word e.g."E _ _ _ _ _ E"
*/
static String transferWordForHangman(String secredWord) {
StringBuilder hangmanWordBuilder = new StringBuilder(secredWord);
String hangmanWord;

for (int i = 1; i < secredWord.length() - 1; i++) {
hangmanWordBuilder.setCharAt(i, '_');
}

hangmanWord = hangmanWordBuilder.toString();
hangmanWord = hangmanLetterReveal(secredWord, hangmanWordBuilder.toString(), secredWord.charAt(0));
hangmanWord = hangmanLetterReveal(secredWord, hangmanWordBuilder.toString(),
secredWord.charAt(secredWord.length() - 1));

return hangmanWord;
}

/**
* Print information about the current state of the game.
*
* @param round
* the number of the following round
* @param seenWord
* the encrypted word that the player sees
* @param usedLetters
* the letter that the player had already used
* @param lives
* the number of the remaining lives
*/
public static void printRoundInformation(int round, String seenWord, char[] usedLetters, int lives) {
LOGGER.info(" ");
LOGGER.info("Round {}:", round);
LOGGER.info("Word to guess: {}", seenWord);
LOGGER.info("Lives: {}", lives);
LOGGER.info("Used letters: {}", String.valueOf(usedLetters));
}

/**
* Check a given character if it is a letter or not using the ASCII table
*
* @param character
* that will be tested if it's a letter or not
* @return true if the character is letter and false if it's not
*/
public static boolean charIsLetter(char character) {
return ((character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z'));
}

/**
* Checks if given character is in a given string
*
* @param character
* that will be searched for
* @param str
* the string that may have the character
* @return true if the character is within the string, false if not.
*/
public static boolean charIsInString(char character, String str) {
for (int i = 0; i < str.length(); i++) {
if (character == str.charAt(i)) {
return true;
}
}
return false;

}

/**
* Plays a game of Hangman until the player have guessed the word or lost all his lives
*
* @param secredWord the word that the player will have to guess
*/
public static void play(String secredWord) {
int lives = 5;
int round = 0;
char[] usedLetters = new char[26];

for (int i = 0; i < usedLetters.length; i++) {
usedLetters[i] = ' ';
}

int numUsedLetters = 0;
String seenWord;
char chosenLetter;

secredWord = capitalize(secredWord);
seenWord = transferWordForHangman(secredWord);

while (lives > 0 && !secredWord.equals(seenWord)) {
round++;
printRoundInformation(round, seenWord, usedLetters, lives);

chosenLetter = ' ';
while (!charIsLetter(chosenLetter)) {
LOGGER.info("Guess a letter: ");
chosenLetter = scanner.nextLine().charAt(0);
}
chosenLetter = capitalize(chosenLetter);
usedLetters[numUsedLetters++] = chosenLetter;

if (charIsInString(chosenLetter, secredWord)) {
LOGGER.info("You guessed right!");
seenWord = hangmanLetterReveal(secredWord, seenWord, chosenLetter);
} else {
LOGGER.info("You guessed wrong! You lose one of your life points.");
lives--;
}
}

if (lives <= 0) {
LOGGER.info("You LOST!");
} else if (secredWord.equals(seenWord)) {
LOGGER.info("Congratulations! You WON!");
}

}

}[/code]
40
#40
tf2pickup.org
3 Frags +

Waiting for brainfuck

Waiting for brainfuck
41
#41
-10 Frags +
Ond_kajahaskell solution

I made Haskell solution but I was too lazy to post it
xDDDd

[quote=Ond_kaja]haskell solution
[/quote]
I made Haskell solution but I was too lazy to post it
xDDDd
42
#42
0 Frags +
SimKudos to anyone who can identify this language without googling it.

Delphi, right? Or Object Pascal, same thing. Never learn this language, kids. It's horrible.

[quote=Sim]Kudos to anyone who can identify this language without googling it.

[/quote]

Delphi, right? Or Object Pascal, same thing. Never learn this language, kids. It's horrible.
43
#43
SizzlingStats
11 Frags +

I don't know C++, but here's an R solution.

secret = "penis"
count = 0
max_guesses = 7

while(TRUE){
  guess = as.character(readline('Guess letter: '))
  print(guess)
  if(grepl(guess, secret) && nchar(guess) == 1){
    print(paste0(guess, " was in the word!"))
    secret = gsub(guess, '', secret)
  }else{
    print("Not in word")
    count = count + 1
  }
  if(nchar(secret) == 0){
    print("ayy")
    break
  }
  if(count >= max_guesses){
    print("lmao")
    break
  }
}
I don't know C++, but here's an R solution.

[code]
secret = "penis"
count = 0
max_guesses = 7

while(TRUE){
guess = as.character(readline('Guess letter: '))
print(guess)
if(grepl(guess, secret) && nchar(guess) == 1){
print(paste0(guess, " was in the word!"))
secret = gsub(guess, '', secret)
}else{
print("Not in word")
count = count + 1
}
if(nchar(secret) == 0){
print("ayy")
break
}
if(count >= max_guesses){
print("lmao")
break
}
}
[/code]
44
#44
8 Frags +
Ye11owSimKudos to anyone who can identify this language without googling it.

Delphi, right? Or Object Pascal, same thing. Never learn this language, kids. It's horrible.

close, but i'm pretty sure it's a modern variant of ALGOL due to its use of the mathematical arrow operator & the "if-fi" and "do-od" blocks which are indicative of Dijkstra's guarded commands. i don't believe OO variants of Pascal are written around GCL.

i've never tried coding with a language that supports guarded commands though; i just know it from my principles of programming course.

EDIT: haha, was doing some more research on CAS's for a pedagogical project & i came across GAP which shares the same syntax as this. is it GAP?

[quote=Ye11ow][quote=Sim]Kudos to anyone who can identify this language without googling it.

[/quote]

Delphi, right? Or Object Pascal, same thing. Never learn this language, kids. It's horrible.[/quote]

close, but i'm pretty sure it's a modern variant of ALGOL due to its use of the mathematical arrow operator & the "if-fi" and "do-od" blocks which are indicative of Dijkstra's guarded commands. i don't believe OO variants of Pascal are written around GCL.

i've never tried coding with a language that supports guarded commands though; i just know it from my principles of programming course.

EDIT: haha, was doing some more research on CAS's for a pedagogical project & i came across GAP which shares the same syntax as this. is it GAP?
45
#45
6 Frags +
diamond0wnerCan we get a machine language solition?

mips is machine language

[quote=diamond0wner]Can we get a machine language solition?[/quote]

mips is machine language
46
#46
SizzlingStats
12 Frags +

I don't know C++, but here's a sh solution.

#!/bin/sh

sudo apt-get install -y gcc
wget -O hangman.c http://ideone.com/plain/nwIobI
gcc -std=c99 hangman.c -o hangman
./hangman
I don't know C++, but here's a sh solution.
[code]
#!/bin/sh

sudo apt-get install -y gcc
wget -O hangman.c http://ideone.com/plain/nwIobI
gcc -std=c99 hangman.c -o hangman
./hangman
[/code]
47
#47
3 Frags +
joshuawnYe11owSimKudos to anyone who can identify this language without googling it.

Delphi, right? Or Object Pascal, same thing. Never learn this language, kids. It's horrible.

close, but i'm pretty sure it's a modern variant of ALGOL due to its use of the mathematical arrow operator & the "if-fi" and "do-od" blocks which are indicative of Dijkstra's guarded commands. i don't believe OO variants of Pascal are written around GCL.

i've never tried coding with a language that supports guarded commands though; i just know it from my principles of programming course.

EDIT: haha, was doing some more research on CAS's for a pedagogical project & i came across GAP which shares the same syntax as this. is it GAP?

Well done, it is GAP.

[quote=joshuawn][quote=Ye11ow][quote=Sim]Kudos to anyone who can identify this language without googling it.

[/quote]

Delphi, right? Or Object Pascal, same thing. Never learn this language, kids. It's horrible.[/quote]

close, but i'm pretty sure it's a modern variant of ALGOL due to its use of the mathematical arrow operator & the "if-fi" and "do-od" blocks which are indicative of Dijkstra's guarded commands. i don't believe OO variants of Pascal are written around GCL.

i've never tried coding with a language that supports guarded commands though; i just know it from my principles of programming course.

EDIT: haha, was doing some more research on CAS's for a pedagogical project & i came across GAP which shares the same syntax as this. is it GAP?[/quote]

Well done, it is GAP.
48
#48
cp_process, cp_metalworks
6 Frags +

TECHNO AND SIZZLING YOU NEED TO STOP NOW!!

TECHNO AND SIZZLING YOU NEED TO STOP NOW!!
49
#49
4 Frags +

jordan. . .please stop harassing this poor 15 year old who cant read...
or code.....

jordan. . .please stop harassing this poor 15 year old who cant read...
or code.....
50
#50
9 Frags +

I have never been more proud of tf2 players in my life

I have never been more proud of tf2 players in my life
51
#51
44 Frags +

I don't know C++, but here's a LabVIEW solution:

http://i.imgur.com/L0yZahP.png

I don't know C++, but here's a LabVIEW solution:
[img]http://i.imgur.com/L0yZahP.png[/img]
52
#52
9 Frags +

I dont know C++, but someone's done Haskell already so I'll port my Haskell solution to Elm

{-
   import System.IO (hSetBuffering, hSetEcho, stdin, BufferMode(..))
   import Data.Char (toLower, isLower)

   main :: IO ()
   main = do hSetBuffering stdin NoBuffering
             hSetEcho stdin False
             hangman "supercalifragilisticexpialidocious" 7 ""

   hangman :: String -> Int -> String -> IO ()
   hangman secret tries gs =
       let hasLost = misses > tries
           -- read: all are (element of guesses) inside secret
           hasWon = all (`elem` gs) secret
           -- read: how many are (not element of secret) inside guesses
           misses = length $ filter (`notElem` secret) gs
           showGuesses = gs ++ replicate (tries - misses) '.'
           showSecret = map (\c -> if c `elem` gs then c else '_') secret
           showState =
               if hasWon then "You won! Word was " ++ secret
               else if hasLost then "You lost!"
               else showSecret ++ " " ++ showGuesses
           validateInput c = gs ++ (if isLower c && notElem c gs then [c] else [])
       in do -- all IO is done below
           putStrLn showState
           if hasLost || hasWon
               then return ()
               else hangman secret tries . validateInput . toLower =<< getChar
-}

module Main exposing (..)

{- elm-package install elm-lang/html elm-lang/keyboard && elm-reactor -}

import Html
import Html.App as Html
import Keyboard
import Char
import List
import String

secret =
    String.toList "supercalifragilisticexpialidocious"

tries =
    7

hasLost model =
    misses model > tries

hasWon model =
    List.all (\c -> List.member c model) secret

misses model =
    List.length <| List.filter (\c -> not <| List.member c secret) model

showGuesses model =
    String.fromList model ++ String.repeat (tries - misses model) "."

showSecret model =
    String.fromList <|
        List.map
            (\c ->
                if List.member c model then
                    c
                else
                    '_'
            )
            secret

showState model =
    if hasWon model then
        "You won! Word was " ++ String.fromList secret
    else if hasLost model then
        "You lost!"
    else
        showSecret model ++ " " ++ showGuesses model

main =
    Html.program
        { init = [] ! []
, view =
            \model ->
                Html.text <| showState model
        , update =
            \msg model ->
                if Char.isLower msg && not (List.member msg model) then
                    (model ++ [ msg ]) ! []
else
                    model ! []
, subscriptions =
            \model ->
                if hasWon model || hasLost model then
                    Sub.none
                else
                    (Keyboard.downs (Char.toLower << Char.fromCode))
        }

I was gonna try Prolog but I forgot I never bothered learning IO/user input in it :(

I dont know C++, but someone's done Haskell already so I'll port my Haskell solution to [url=http://elm-lang.org]Elm[/url]

[code]{-
import System.IO (hSetBuffering, hSetEcho, stdin, BufferMode(..))
import Data.Char (toLower, isLower)

main :: IO ()
main = do hSetBuffering stdin NoBuffering
hSetEcho stdin False
hangman "supercalifragilisticexpialidocious" 7 ""

hangman :: String -> Int -> String -> IO ()
hangman secret tries gs =
let hasLost = misses > tries
-- read: all are (element of guesses) inside secret
hasWon = all (`elem` gs) secret
-- read: how many are (not element of secret) inside guesses
misses = length $ filter (`notElem` secret) gs
showGuesses = gs ++ replicate (tries - misses) '.'
showSecret = map (\c -> if c `elem` gs then c else '_') secret
showState =
if hasWon then "You won! Word was " ++ secret
else if hasLost then "You lost!"
else showSecret ++ " " ++ showGuesses
validateInput c = gs ++ (if isLower c && notElem c gs then [c] else [])
in do -- all IO is done below
putStrLn showState
if hasLost || hasWon
then return ()
else hangman secret tries . validateInput . toLower =<< getChar
-}


module Main exposing (..)

{- elm-package install elm-lang/html elm-lang/keyboard && elm-reactor -}

import Html
import Html.App as Html
import Keyboard
import Char
import List
import String


secret =
String.toList "supercalifragilisticexpialidocious"


tries =
7


hasLost model =
misses model > tries


hasWon model =
List.all (\c -> List.member c model) secret


misses model =
List.length <| List.filter (\c -> not <| List.member c secret) model


showGuesses model =
String.fromList model ++ String.repeat (tries - misses model) "."


showSecret model =
String.fromList <|
List.map
(\c ->
if List.member c model then
c
else
'_'
)
secret


showState model =
if hasWon model then
"You won! Word was " ++ String.fromList secret
else if hasLost model then
"You lost!"
else
showSecret model ++ " " ++ showGuesses model


main =
Html.program
{ init = [] ! []
, view =
\model ->
Html.text <| showState model
, update =
\msg model ->
if Char.isLower msg && not (List.member msg model) then
(model ++ [ msg ]) ! []
else
model ! []
, subscriptions =
\model ->
if hasWon model || hasLost model then
Sub.none
else
(Keyboard.downs (Char.toLower << Char.fromCode))
}
[/code]
I was gonna try Prolog but I forgot I never bothered learning IO/user input in it :(
53
#53
10 Frags +

I know C++, so here's a Clojure solution.

(declare play)
(declare ask)

(def maxincorrect 7)
(def words ["meme" "rick" "derp" "hi"])

(defn guessCorrect [secret position incorrect]
(println "correct guess!")
  (play secret (+ position 1) incorrect))

(defn guessIncorrect [secret position incorrect]
(println "incorrect guess!")
  (play secret position (+ incorrect 1)))

(defn isCorrectGuess [secret position guess]
(= (subs secret position (+ position 1)) guess))

(defn ask [secret position incorrect]
(println (str "Current guess: " (subs secret 0 position)))
  (println (str "lives remaining: " (- maxincorrect incorrect)))
  (println "Enter your next guess.")
  (if (isCorrectGuess secret position (read-line))
    (guessCorrect secret position incorrect)
    (guessIncorrect secret position incorrect)))

(defn play [secret position incorrect]
(cond
    (= (count secret) position) (println "you won! a winrar is you!")
    (= incorrect maxincorrect) (println "you lost, what the frick?")
    :else (ask secret position incorrect)))

(play (rand-nth words) 0 0)
I know C++, so here's a Clojure solution.

[code]
(declare play)
(declare ask)

(def maxincorrect 7)
(def words ["meme" "rick" "derp" "hi"])

(defn guessCorrect [secret position incorrect]
(println "correct guess!")
(play secret (+ position 1) incorrect))

(defn guessIncorrect [secret position incorrect]
(println "incorrect guess!")
(play secret position (+ incorrect 1)))

(defn isCorrectGuess [secret position guess]
(= (subs secret position (+ position 1)) guess))

(defn ask [secret position incorrect]
(println (str "Current guess: " (subs secret 0 position)))
(println (str "lives remaining: " (- maxincorrect incorrect)))
(println "Enter your next guess.")
(if (isCorrectGuess secret position (read-line))
(guessCorrect secret position incorrect)
(guessIncorrect secret position incorrect)))

(defn play [secret position incorrect]
(cond
(= (count secret) position) (println "you won! a winrar is you!")
(= incorrect maxincorrect) (println "you lost, what the frick?")
:else (ask secret position incorrect)))

(play (rand-nth words) 0 0)

[/code]
54
#54
4 Frags +

Yo, so I agree that you should figure out most of this stuff on your own, but something that will help you get started fixing your code is that you're using logical connectors wrong repeatedly.

When you make phrases using && and ||, each statement joined by those evaluates separately. For example, if you write

int i = 5;

if(i == 3 || 4)
{
    cout << "I'm printing stuff!" << endl;
}

it will print out stuff even though i doesn't equal 3 or 4. That's because the 4 written after || is its own isolated boolean expression that evaluates to True. So, to see if i is 3 or 4, you'd need to write

if(i == 3 || i == 4)

Google "logical connectors c++" if you're still not totally sure how to use them.

Show Content
Sorry to break the chain of trolling.
Yo, so I agree that you should figure out most of this stuff on your own, but something that will help you get started fixing your code is that you're using logical connectors wrong repeatedly.

When you make phrases using && and ||, each statement joined by those evaluates separately. For example, if you write
[code]int i = 5;

if(i == 3 || 4)
{
cout << "I'm printing stuff!" << endl;
}[/code]
it will print out stuff even though i doesn't equal 3 or 4. That's because the 4 written after || is its own isolated boolean expression that evaluates to True. So, to see if i is 3 or 4, you'd need to write
[code]if(i == 3 || i == 4)[/code]
Google "logical connectors c++" if you're still not totally sure how to use them.

[spoiler]Sorry to break the chain of trolling.[/spoiler]
55
#55
SizzlingStats
4 Frags +
TechDudeI don't know C++, but here's a LabVIEW solution:

Good solution.

ScorpioUprisingTECHNO AND SIZZLING YOU NEED TO STOP NOW!!renojordan. . .please stop harassing this poor 15 year old who cant read...
or code.....

I don't kNOw C++, but here's a C++ s0luti0n.
http://ideone.com/IGp429

#include <stdio.h>

int main()
{
    const int lol[] = {10920, 11129};
    char secret[] = "hi";
    char answer[] = "__";
    int o_o = 2;

    for (int i = 0; i < 7; ++i)
    {
        printf("Enter a letter. %s\n", answer);
        int guess = getchar();
        getchar();

        if(!(lol[0] + guess*(guess - (lol[1]-lol[0]))))
        {
            answer[guess - secret[0]] = secret[guess - secret[0]];
            o_o -= 1;
        }
        else
        {
            printf("Letter not found, try again\n");
        }

        if (!o_o)
        {
            printf("You win\n");
            break;
        }
    }

    printf("The word was %s\n", secret);
    return 0;
}
[quote=TechDude]I don't know C++, but here's a LabVIEW solution:[/quote]
Good solution.

[quote=ScorpioUprising]TECHNO AND SIZZLING YOU NEED TO STOP NOW!![/quote]
[quote=reno]jordan. . .please stop harassing this poor 15 year old who cant read...
or code.....[/quote]

I don't k[u][b]NO[/b][/u]w C++, b[i]ut[/i] [b]here's[/b] a[s] C+[/s][u]+[/u][b][/b] [i]s0lu[/i]ti0[s]n[/s].
http://ideone.com/IGp429
[code]
#include <stdio.h>

int main()
{
const int lol[] = {10920, 11129};
char secret[] = "hi";
char answer[] = "__";
int o_o = 2;

for (int i = 0; i < 7; ++i)
{
printf("Enter a letter. %s\n", answer);
int guess = getchar();
getchar();

if(!(lol[0] + guess*(guess - (lol[1]-lol[0]))))
{
answer[guess - secret[0]] = secret[guess - secret[0]];
o_o -= 1;
}
else
{
printf("Letter not found, try again\n");
}

if (!o_o)
{
printf("You win\n");
break;
}
}

printf("The word was %s\n", secret);
return 0;
}
[/code]
56
#56
15 Frags +

I don't know C++, but here's a l1IIl1l solution.

Of course it runs, you piece of shit.

#include <stdio.h>

#define lI1lIlI "Enter a letter. %s\n"
#define l11IllI "__"
#define lIllili char
#define I1llI1l "hi"
#define lI111Il []
#define lI11l1I 0
#define l11l1II break
#define l1lll1I for
#define l1IIIl1 else
#define Ill1l1l "You win\n"
#define l11lIll =
#define lIIlI1l -=
#define l1ll1ll i
#define l1IIl11 10920
#define l1llll1 answer
#define l111l1l !
#define lI1ll1l 7
#define l1l11ll secret
#define lII1lII main()
#define ll1lIIl lol
#define lIllill getchar
#define l11llll -
#define l11IlI1 *
#define lIIl1lI printf
#define l11l1Il return
#define lIllI1l 1
#define Ill1l1I 11129
#define IllI1l1 const
#define l11l111 ++
#define l11l1l1 "The word was %s\n"
#define lIlIlI1 <
#define Ill1l11 2
#define l1Il1ll +
#define IlIl11I "Letter not found, try again\n"
#define IllI1ll guess
#define l1IIl1l int
#define lIll111 if
#define lIlllll ;

l1IIl1l lII1lII
{
    IllI1l1 l1IIl1l ll1lIIl lI111Il l11lIll {l1IIl11, Ill1l1I} lIlllll
    lIllili l1l11ll lI111Il l11lIll I1llI1l lIlllll
    lIllili l1llll1 lI111Il l11lIll l11IllI lIlllll
    l1IIl1l o_o l11lIll Ill1l11 lIlllll

    l1lll1I (l1IIl1l l1ll1ll l11lIll lI11l1I lIlllll l1ll1ll lIlIlI1 lI1ll1l lIlllll l11l111 l1ll1ll)
    {
        lIIl1lI(lI1lIlI, l1llll1) lIlllll
        l1IIl1l IllI1ll l11lIll lIllill() lIlllll
        lIllill() lIlllll

        lIll111(l111l1l(ll1lIIl[lI11l1I] l1Il1ll IllI1ll l11IlI1 (IllI1ll l11llll (ll1lIIl[lIllI1l] l11llll ll1lIIl[lI11l1I]))))
        {
            l1llll1[IllI1ll l11llll l1l11ll[lI11l1I]] l11lIll l1l11ll[IllI1ll l11llll l1l11ll[lI11l1I]] lIlllll
            o_o lIIlI1l lIllI1l lIlllll
        }
        l1IIIl1
        {
            lIIl1lI(IlIl11I) lIlllll
        }

        lIll111 (l111l1l o_o)
        {
            lIIl1lI(Ill1l1l) lIlllll
            l11l1II lIlllll
        }
    }

    lIIl1lI(l11l1l1, l1l11ll) lIlllll
    l11l1Il lI11l1I lIlllll
}
  
I don't know C++, but here's a l1IIl1l solution.

[url=http://ideone.com/hhPKET]Of course it runs, you piece of shit.[/url]
[code]#include <stdio.h>

#define lI1lIlI "Enter a letter. %s\n"
#define l11IllI "__"
#define lIllili char
#define I1llI1l "hi"
#define lI111Il []
#define lI11l1I 0
#define l11l1II break
#define l1lll1I for
#define l1IIIl1 else
#define Ill1l1l "You win\n"
#define l11lIll =
#define lIIlI1l -=
#define l1ll1ll i
#define l1IIl11 10920
#define l1llll1 answer
#define l111l1l !
#define lI1ll1l 7
#define l1l11ll secret
#define lII1lII main()
#define ll1lIIl lol
#define lIllill getchar
#define l11llll -
#define l11IlI1 *
#define lIIl1lI printf
#define l11l1Il return
#define lIllI1l 1
#define Ill1l1I 11129
#define IllI1l1 const
#define l11l111 ++
#define l11l1l1 "The word was %s\n"
#define lIlIlI1 <
#define Ill1l11 2
#define l1Il1ll +
#define IlIl11I "Letter not found, try again\n"
#define IllI1ll guess
#define l1IIl1l int
#define lIll111 if
#define lIlllll ;

l1IIl1l lII1lII
{
IllI1l1 l1IIl1l ll1lIIl lI111Il l11lIll {l1IIl11, Ill1l1I} lIlllll
lIllili l1l11ll lI111Il l11lIll I1llI1l lIlllll
lIllili l1llll1 lI111Il l11lIll l11IllI lIlllll
l1IIl1l o_o l11lIll Ill1l11 lIlllll

l1lll1I (l1IIl1l l1ll1ll l11lIll lI11l1I lIlllll l1ll1ll lIlIlI1 lI1ll1l lIlllll l11l111 l1ll1ll)
{
lIIl1lI(lI1lIlI, l1llll1) lIlllll
l1IIl1l IllI1ll l11lIll lIllill() lIlllll
lIllill() lIlllll

lIll111(l111l1l(ll1lIIl[lI11l1I] l1Il1ll IllI1ll l11IlI1 (IllI1ll l11llll (ll1lIIl[lIllI1l] l11llll ll1lIIl[lI11l1I]))))
{
l1llll1[IllI1ll l11llll l1l11ll[lI11l1I]] l11lIll l1l11ll[IllI1ll l11llll l1l11ll[lI11l1I]] lIlllll
o_o lIIlI1l lIllI1l lIlllll
}
l1IIIl1
{
lIIl1lI(IlIl11I) lIlllll
}

lIll111 (l111l1l o_o)
{
lIIl1lI(Ill1l1l) lIlllll
l11l1II lIlllll
}
}

lIIl1lI(l11l1l1, l1l11ll) lIlllll
l11l1Il lI11l1I lIlllll
}
[/code]
57
#57
6 Frags +

idk any programming languages so I started making a Turing machine to play hangman. It only supports the first 2 letters of the alphabet cus I got bored
http://morphett.info/turing/turing.html?8997edb47107670f68c770b461afd6aa

Unfortunately the secret and the guesses are on the same tape so you'll have to cover the secret with ur finger :D

idk any programming languages so I started making a [url=https://en.wikipedia.org/wiki/Turing_machine]Turing machine[/url] to play hangman. It only supports the first 2 letters of the alphabet cus I got bored
http://morphett.info/turing/turing.html?8997edb47107670f68c770b461afd6aa

Unfortunately the secret and the guesses are on the same tape so you'll have to cover the secret with ur finger :D
58
#58
-12 Frags +

I don't know C++, but here's a ᵖᵒᵒᵗᶦˢ solution.

#include <stdio.h>
big long coding numbers and dumb shit

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░▄▄▄▄▄▄▄░░░░░░░░░
░░░░░░░░░▄▀▀▀░░░░░░░▀▄░░░░░░░
░░░░░░░▄▀░░░░░░░░░░░░▀▄░░░░░░
░░░░░░▄▀░░░░░░░░░░▄▀▀▄▀▄░░░░░
░░░░▄▀░░░░░░░░░░▄▀░░██▄▀▄░░░░
░░░▄▀░░▄▀▀▀▄░░░░█░░░▀▀░█▀▄░░░
░░░█░░█▄▄░░░█░░░▀▄░░░░░▐░█░░░
░░▐▌░░█▀▀░░▄▀░░░░░▀▄▄▄▄▀░░█░░
░░▐▌░░█░░░▄▀░░░░░░░░░░░░░░█░░
░░▐▌░░░▀▀▀░░░░░░░░░░░░░░░░▐▌░
░░▐▌░░░░░░░░░░░░░░░▄░░░░░░▐▌░
░░▐▌░░░░░░░░░▄░░░░░█░░░░░░▐▌░
░░░█░░░░░░░░░▀█▄░░▄█░░░░░░▐▌░
░░░▐▌░░░░░░░░░░▀▀▀▀░░░░░░░▐▌░
░░░░█░░░░░░░░░░░░░░░░░░░░░█░░
░░░░▐▌▀▄░░░░░░░░░░░░░░░░░▐▌░░
░░░░░█░░▀░░░░░░░░░░░░░░░░▀░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
I don't know C++, but here's a ᵖᵒᵒᵗᶦˢ solution.

[quote]#include <stdio.h>
big long coding numbers and dumb shit

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░▄▄▄▄▄▄▄░░░░░░░░░
░░░░░░░░░▄▀▀▀░░░░░░░▀▄░░░░░░░
░░░░░░░▄▀░░░░░░░░░░░░▀▄░░░░░░
░░░░░░▄▀░░░░░░░░░░▄▀▀▄▀▄░░░░░
░░░░▄▀░░░░░░░░░░▄▀░░██▄▀▄░░░░
░░░▄▀░░▄▀▀▀▄░░░░█░░░▀▀░█▀▄░░░
░░░█░░█▄▄░░░█░░░▀▄░░░░░▐░█░░░
░░▐▌░░█▀▀░░▄▀░░░░░▀▄▄▄▄▀░░█░░
░░▐▌░░█░░░▄▀░░░░░░░░░░░░░░█░░
░░▐▌░░░▀▀▀░░░░░░░░░░░░░░░░▐▌░
░░▐▌░░░░░░░░░░░░░░░▄░░░░░░▐▌░
░░▐▌░░░░░░░░░▄░░░░░█░░░░░░▐▌░
░░░█░░░░░░░░░▀█▄░░▄█░░░░░░▐▌░
░░░▐▌░░░░░░░░░░▀▀▀▀░░░░░░░▐▌░
░░░░█░░░░░░░░░░░░░░░░░░░░░█░░
░░░░▐▌▀▄░░░░░░░░░░░░░░░░░▐▌░░
░░░░░█░░▀░░░░░░░░░░░░░░░░▀░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░[/quote]
59
#59
4 Frags +
TechDudeI don't know C++, but here's a LabVIEW solution:

Im physically and mentally weak lmao

[quote=TechDude]I don't know C++, but here's a LabVIEW solution:
[/quote]
Im physically and mentally weak lmao
60
#60
7 Frags +

I don't know C++, but here's a sketch of a pushdown automaton which accepts the language {xnx | x in English dictionary and 0 < n <= 26}

http://imgkk.com/i/pkyt.png

(it is a bona fide PDA since dictionaries are finite)

I don't know C++, but here's a sketch of a pushdown automaton which accepts the language {xnx | x in English dictionary and 0 < n <= 26}

http://imgkk.com/i/pkyt.png

(it is a bona fide PDA since dictionaries are finite)
1 2 3
Please sign in through STEAM to post a comment.