Tutorial Challenges

Solve These First

The tutorial challenges are there to show new players how their submissions need to be formatted prior to posting them to the site. Prior to trying the other challenges on the site, we recommend you solve the Tutorial challenges first to set you up for success as you progress further.

Hello World

This has long been the first program any guide on programming uses to demonstrate the language. In RunCode, we have you submit this first to verify you understand the format that your submissions need to be in (and that you have a basic functional proficiency in your language.)

Interpreted (Scripting) Languages Must Include a Shebang

The shebang is an interpreter directive to a program loader that directs what interpreter program should be used to parse the rest of the script that follows.
For example, #!/bin/sh at the top of a shell script would indicate that /bin/sh should be used to interpret what follows.
The following examples demonstrate the correct way to submit a script for the languages we support:

Bourne-Again Shell (BASH)

hello_world.sh:
1
#!/bin/bash
2
echo "Hello, World!"
Copied!

Common Lisp

hello_world.lsp:
1
#!/usr/bin/env clisp
2
(print "Hello World")
Copied!

Nodejs

hello_world.js:
1
#!/usr/bin/env nodejs
2
console.log("Hello, World!");
Copied!

Perl 5

hello_world.pl:
1
#!/usr/bin/env perl
2
use strict;
3
use warnings;
4
print "Hello, World!\n";
Copied!

PHP

hello_world.php:
1
#!/usr/bin/php
2
<?php
3
echo "Hello, World!"
4
?>
Copied!

Python

hello_world.py:
1
#!/usr/bin/env python
2
print "Hello, World!"
Copied!

Python 3

hello_world.py:
1
#!/usr/bin/env python3
2
print("Hello, World!")
Copied!

Ruby

hello_world.rb:
1
#!/usr/bin/env ruby
2
puts "Hello, World!"
Copied!
hello_world_object_oriented.rb:
1
#!/usr/bin/env ruby
2
class HelloWorld
3
def initialize(name)
4
@name = name.capitalize
5
end
6
def sayHi
7
puts "Hello, #{@name}!"
8
end
9
end
10
11
hello = HelloWorld.new("World")
12
hello.sayHi
Copied!

Scala

hello_world.scala:
1
#!/usr/bin/env scala
2
object HelloWorld {
3
def main(args: Array[String]): Unit = {
4
println("Hello, World!")
5
}
6
}
Copied!

Compiled Language Submissions Must be Source Code (No Binaries)

Since compiled languages can’t be executed before being compiled (and because there is no interpreter involved), the shebang line is unnecessary. Instead, you can simply submit the source code for your solutions. They will be compiled and validated once they are received.
The following are examples of correct Hello World submissions for the compiled languages that we support:

C

hello_world.c:
1
#include <stdio.h>
2
3
int main()
4
{
5
printf("%s", "Hello, World!");
6
}
Copied!

C++

hello_world.cpp:
1
#include <iostream>
2
3
int main()
4
{
5
std::cout << "Hello, World!";
6
}
Copied!

Golang

hello_world.go:
1
package main
2
3
import "fmt"
4
5
func main() {
6
fmt.Println("Hello, World!")
7
}
Copied!

Haskell

hello_world.hs:
1
module Main where
2
3
main = putStrLn "Hello, World!"
Copied!

Argumentative

Argumentative asks you to print all of the arguments to your app from the command-line. This challenge does not provide you with the number of arguments you should expect. Instead, your solution should be able to print one-to-many arguments to the screen.
For example, in the shell script below, there are four arguments provided at the command-line.
1
$ ./your_app.sh one two three four
Copied!
The solution, should provide all four arguments not including argument 0 (the app name itself).
1
$ ./your_app.sh one two three four
2
one two three four
Copied!
Below are the solutions you should be able to provide to this tutorial challenge in any of the 14 languages you are using.

Bourn-Again Shell (BASH)

argumentative.sh:
1
#!/bin/bash
Copied!

Common Lisp

argumentative.lsp:
1
#!/usr/bin/env clisp
2
(loop for i in *args*
3
do (format t " ")
4
do (format t "~A" i)
5
)
Copied!

Nodejs

argumentative.js:
1
#!/usr/bin/env nodejs
2
process.argv.slice(2).forEach(function (val, index, array) {
3
process.stdout.write(val+" ");
4
});
5
console.log();
Copied!

Perl 5

argumentative.pl:
1
#!/usr/bin/env perl
2
use strict;
3
use warnings;
4
5
print "$_ " foreach @ARGV;
6
print "\n"
Copied!

PHP

argumentative.php:
1
#!/usr/bin/php
2
<?php
3
for($i = 1; $i < sizeof($argv); $i++) {
4
echo $argv[$i]." ";
5
}
6
echo "\n";
7
?>
Copied!

Python

argumentative.py:
1
#!/usr/bin/env python
2
import sys
3
print ' '.join(sys.argv[1:])
Copied!

Python 3

argumentative3.py:
1
#!/usr/bin/env python3
2
import sys
3
print(' '.join(sys.argv[1:]))
Copied!

Ruby

argumentative.rb:
1
#!/usr/bin/env ruby
2
puts ARGV.join(' ')
Copied!

Scala

argumentative.scala:
1
#!/usr/bin/env scala
2
object Argumentative {
3
def main(args: Array[String]): Unit = {
4
println(args.mkString(" "))
5
}
6
}
Copied!

Compiled Language Argumentative Solutions

The following are examples of correct Argumentative submissions for the compiled languages that we support:

C

argumentative.c:
1
#include <stdio.h>
2
3
int main(int argc, char *argv[])
4
{
5
int i = 0;
6
for(i = 1; i < argc; i++) {
7
printf("%s ", argv[i]);
8
}
9
printf("%s", "\n");
10
}
Copied!

C++

argumentative.cpp:
1
#include <iostream>
2
3
int main(int argc, char *argv[])
4
{
5
int i = 0;
6
for(i = 1; i < argc; i++) {
7
std::cout << argv[i] << " ";
8
}
9
std::cout << std::endl;
10
}
Copied!

Golang 1.10.2

argumentative.go:
1
package main
2
3
import "os"
4
import "fmt"
5
import "strings"
6
7
func main() {
8
argsWithoutProg := strings.Join(os.Args[1:], " ")
9
fmt.Println(argsWithoutProg)
10
}
Copied!

Haskell

argumentative.hs:
1
import System.Environment
2
import Data.List
3
4
main = do
5
args <- getArgs
6
putStrLn (intercalate " " args)
Copied!
Last modified 10mo ago