C14008: Introduction to Being a Code Ninja in Julia

Christian decided he didn't want to teach the class today (or ever), so I have included this picture of him for your reference:

Lesson 1: The Basics

Motivation: Why study Julia?

There's a couple reasons we have identified to motivate studying Julia.

  1. Julia is fast. It offers a notable speed improvement from interpreted languages like Python.
  2. Julia is intuitive. It's familiar to languages you might have dealt with before and its syntax is easy to pick up and learn.
  3. Julia is predictable. You can define types (that are actually enforced, cough cough... Python), and the language operates off of a set of base functions that can be modified or extended through multiple dispatch.
  4. Julia is the future. It's flexible and fun to write. There's a growing programmer community around the language. It can be integrated into other languages and other languages can be integrated into Julia. Expect to see at as part of more projects in the future.

Speaking of Julia being fast...

Let's try and solve a really big problem with Julia, such as this one from Project Euler Problem 99!

Here's the problem restated.

Comparing two numbers written in index form like $2^{11}$ and $3^{7}$ is not difficult, as any calculator would confirm that $2^{11} = 2048 < 3^7 = 2187$.

However, confirming that $$632382^{518061} > 519432^{525806}$$ would be much more difficult, as both numbers contain over three million digits.

Using base_exp.txt (right click and 'Save Link/Target As...'), a 22K text file containing one thousand lines with a base/exponent pair on each line, determine which line number has the greatest numerical value.

NOTE: The first two lines in the file represent the numbers in the example given above.

In [7]:
# I'll write my solution here
text_lines = readlines("p099_base_exp.txt")
split_lines = split.(text_lines, ",")
numbers_lines = map(line -> parse.(BigInt, line), split_lines)

largest = BigInt(0)

for count in 1:1000
    if (new_num = log(numbers_lines[count][1])*numbers_lines[count][2]) > largest
        largest = new_num
        println(count)
    end
end
1
2
3
5
6
8
21
92
110
172
709

So let's get started!

Hello World

Of course, we have to start with a Hello World example. Julia actually has two types of print statements, print() and println(). println() adds a newline character after the arguments. They can take multiple arguments too, like println("Hello", " ", "World"). Here's an example:

In [8]:
println("Hello Julia!")
Hello Julia!

Strings and comments in Julia

Unlike Python, strings in Julia have double quotes "like this", while there is a special character type for characters if you use single quotes like this: 'a' 'b' and 'c'. For multiline strings, you can use triple quotes, demonstrated below.

Comments are the same as Python, with the hash character # for a single line comment. Unlike Python, Julia can do multiline comments. #= starts a multiline comment and =# ends a multiline comment.

Also like Python, we can use the builtin function typeof() to tell us which type the variables are.

In [ ]:
# Some strings
println("Hello World!")
println(typeof("Hello World!"))

println()

# Some characters
println('a', 'b', 'c')
println(typeof('a'))

println()

# A multiline string
println("""
Hi I'm a multiline String.
I have multiple lines!
""")

# Some comments
#=
Hi I'm a multiline comment
=#

Variables in Julia

Variables in Julia look like variables in any other language you might be used to. Let's set the variable 🤠 equal to "yeehaw!". That's right! Julia has native Unicode support, so you can make your variables emojis. We'll see later that Unicode operators like and are actual operations in Julia.

In [9]:
# Unicode variables
🤠 = "yeehaw!"

println(🤠)
yeehaw!

We can actually reference Julia code inside of our variables if we want to through a process called string interpolation. We use the dollar sign to do this. If we want to reference a variable, we can put $variable_name inside of a string.

If we want to type an expression, we can instead write $(5 + 5) in the string.

In [10]:
# String replacement
println("The cowboy goes $🤠")
println("5 + 5 is equal to $(5 + 5)")
The cowboy goes yeehaw!
5 + 5 is equal to 10

Operators in Julia

Julia supports all the operators you would expect.

In [13]:
x = 5
y = 5

# operators in Julia, add, sub, mult, div, pow, mod
addition = x + y
subtraction = x - y
multiplication = x * y
division = x/y
@assert typeof(division) == Float64 # division will be a float (decimal), despite x and y being integers

power = x ^ y
modulous = x % y

# rationals
rational = x//y
Out[13]:
1//1

Some operators don't strictly apply to numbers. For example, we can use the * and ^ operators on strings to preform various functions.

In [14]:
s1 = "Road work ahead? "
s2 = "Uh yeah, I sure hope it does."

# * can be used to concatenate these two strings
println(s1 * s2)

# the ^ also has a function, I'll leave it up to y'all to figure out when this would ever come in handy.
println(s2 ^ 5)
Road work ahead? Uh yeah, I sure hope it does.
Uh yeah, I sure hope it does.Uh yeah, I sure hope it does.Uh yeah, I sure hope it does.Uh yeah, I sure hope it does.Uh yeah, I sure hope it does.

The equality operator can be used in some special ways, such as assigning two values to the same variable. You can also assign two variables at the same time, with this tuple syntax.

In [15]:
# double assignment and tuple assignment
a = b = 10
c, d = 15, 20

print("a is $(a), b is $(b), c is $(c), and d is $(d)")
a is 10, b is 10, c is 15, and d is 20

Datatypes in Julia

Basic data types

Julia has most of the data types you have run across in different languages, plus some. The types are capitalized and sometimes have a number after them to represent the number of bits stored (Int64 is a 64 bit integer), however when referencing a type you will be able to get away without the number (just Int). When defining a variable, Julia does a very good job of determining what type of variable you want and automatically assigns a type to it for you. This is great, but it does mean you need to be careful about type errors arising in your code.

In [16]:
integer = 15 # My (Christian's) baseball number
# Will return "Int64"
println(typeof(integer))
Int64
In [17]:
float = 15.0 # A float is any number with a decimal in it.
# Returns "Float64"
println(typeof(float))
Float64
In [18]:
boolean = true # Notice that "true" is NOT capitalized
println(typeof(boolean))
Bool
In [19]:
char = 'e' # Notice the use of single quotes
println(typeof(char))
Char
In [22]:
complex_num = 15.2im # im is tied to the imaginary number i
println(typeof(complex_num)) # no more coding an extra if statement into your quadratic formula function to account for imaginary numbers!
Complex{Float64}
In [23]:
big = 68^476
println(typeof(big))
println(big)
Int64
0

Woah, that last one didn't work. It took our big variable and stored it as zero since the number was too large. Sometimes this will happen. Thankfully there are other datatypes to help deal with these fringe cases, like BigInt (a datatype that can store infinitely many digits). Julia will not automatically convert to this datatype, however, so you must do it yourself (#DIY) using the convert function. To convert from one type to another try convert(type, var). So in our case:

In [24]:
big = convert(BigInt, 68)^convert(BigInt,476)
println(typeof(big))
println(big)
BigInt
188036625248407132637222801527003252485547364886698418367698846937835206600048396133299947551429864654002237724234967482696308604511429691655876558993741342143051304130422777813294692657318463042134646529962059220020009694425077713314814178259050251695531027516644578937869017528744234757342763465310155761945112066829963430090848777880784103593277502962793601342170439209960927208043893939010943524320341855852009795542244722468977890043809231124117195123169604331192956692165663968388567440792005137409124389239516272281213885273004453027181981676839128911763134961725641689477739193590005661738148476078712938480089697257500003106303686326823806534698672765539510988709457076536430484916728549530769378563887241799571291100547019182880210358932010817376273744455474297391612051295309669057613355574534556405577450519770558960226809111091366897057669707386814283829477376

Bigboy Datatypes

Obviously you have your ints and your chars, but Julia also provides larger datatypes. Today we will cover dictionary, tuples, and arrays.

Dictionarys

Like Python and Java (and also probably every other language), dictionaries are essentially an unordered list that maps unique keys to values. To create a dictionary in Julia, use the function Dict.

In [25]:
mbmbam = Dict("Oldest Brother" => "Justin McElroy", "Middlest Brother" => "Travis McElroy", "Sweet Baby Brother" => "Griffin McElroy")
Out[25]:
Dict{String,String} with 3 entries:
  "Sweet Baby Brother" => "Griffin McElroy"
  "Oldest Brother"     => "Justin McElroy"
  "Middlest Brother"   => "Travis McElroy"

Notice the use of => instead of a : to assign a value to a key. The syntax to access a value, change a value, and add a key-value pair is the same as it is in Python or Java.

In [26]:
# Acessing a value
println(mbmbam["Middlest Brother"])

# Changing a value
mbmbam["Oldest Brother"] = "Justin 'Juice' McElroy"

# Adding a key-value pair
mbmbam["30 Under 30 Media Luminary"] = "Griffin McElroy"

println(mbmbam)
Travis McElroy
Dict("30 Under 30 Media Luminary" => "Griffin McElroy","Sweet Baby Brother" => "Griffin McElroy","Oldest Brother" => "Justin 'Juice' McElroy","Middlest Brother" => "Travis McElroy")

We can assign two unique keys to the same value (ie. Griffin McElroy is both our sweet baby brother AND our 30 under 30 media luminary), but every key must be unique. This is the same behavior in Python and many other languages.

Tuples

Tuples are basically an ordered collection of elements. Their most common application in my experience is as coordinates or an index for a higher dimensional array (we will get to this later). To create one, simply enclose data in parentheses.

In [27]:
fish = ("One Fish", "Two Fish", "Red Fish", "Blue Fish")
Out[27]:
("One Fish", "Two Fish", "Red Fish", "Blue Fish")

To access an element in the tuple, we would (again) do it simililarly to Python or Java (using brackets) except one major difference. Julia is a one indexed language. This means that in order to access the first element in the tuple we would need to write fish[1] NOT fish[0]. It seems like it would be incredibly annoying to adjust to this, but in my experience it isn't that bad.

In [28]:
# Prints "Red Fish"
println(fish[3])

# Throws bounds error
println(fish[0])
Red Fish
BoundsError: attempt to access ("One Fish", "Two Fish", "Red Fish", "Blue Fish")
  at index [0]

Stacktrace:
 [1] getindex(::Tuple, ::Int64) at ./tuple.jl:24
 [2] top-level scope at In[28]:3

Missing dictionaries? Well miss no more because we can do a very similar thing using named tuples. With named tuples you can assign a variable to each item in the tuple via a =. To access an element of this named tuple, we use a . followed by the variable name.

In [29]:
fishNames = (oneFish = "Ava", twoFish = "Browne", redFish = "Carmen", blueFish = "Daniel")
println(fishNames.twoFish)

# Accessing by index still works, though
println(fishNames[1])
Browne
Ava

Arrays

Although they may be considered one of the simpler datatypes in other languages, Julia is built to handle complex arrays, and what we cover today will only being to scratch the surface. In linear algebra, there are things called matrices, which are like 2-D arrays for math. A 1-D matrix (only one column) is called a vector, and are the type of arrays you are probably most comfortable with. There will be a more in depth crash course on linear algebra on a future date, so don't worry if you don't know much about matrices yet. We will start with vectors (1D arrays). There are several ways to make arrays, we will start with the simplest.

In [30]:
staff = ["Spongebob", "Squidward", "Mr. Krabs"]
Out[30]:
3-element Array{String,1}:
 "Spongebob"
 "Squidward"
 "Mr. Krabs"

Notice how the type is Array{String, 1}. This tells us this is a 1 dimensional array of Strings. If we were to add an element that is not a string, say the number 15, we would see the type is Array{Any, 1} (you can try it on your own if you don't trust me). Let's access the first element, we can do so just as we do with a tuple.

In [32]:
staff[3]
Out[32]:
"Mr. Krabs"

The main two functions used with arrays are pop! and push!. The ! denotes that calling the function will change the array it is called on. pop! returns the last element in the array while removing it from the array. push! adds an element to the end of the array.

In [33]:
staff = ["Spongebob", "Squidward", "Mr. Krabs"] # reset the array
# pop! the array
pop!(staff)
println(staff) # see how the array has changed

push!(staff, "Mr. Krabs") #push!(array name, element to add)
println(staff) # added Mr. Krabs back to the end of the array.
["Spongebob", "Squidward"]
["Spongebob", "Squidward", "Mr. Krabs"]

Now, let's talk about the other ways to initialize arrays, ones that support higher dimensions. We can initialize an undefined array by using Array{T,N}(undef,x,y,...,z) where T denotes the type of the array, N denotes the dimensions, and x,y,...,z represent the size. So for example, if we want a 2 dimensional array of strings with a size 3x4, we do:

In [34]:
nums = Array{String,2}(undef, 3,4)
Out[34]:
3×4 Array{String,2}:
 #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef

There are other tricks too. We will see two of them here and will get to another (my favorite one) in the for loop section.

In [35]:
# 3x4 matrix filled with random values between 0 and 1
rand(3,4)
Out[35]:
3×4 Array{Float64,2}:
 0.970278   0.365292  0.57689    0.865391
 0.0301001  0.345353  0.0958836  0.540887
 0.0994154  0.976874  0.451911   0.9133
In [36]:
# 3x4 matrix of zeros
zeros(3,4)
Out[36]:
3×4 Array{Float64,2}:
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

There are so many ways to initialize and create arrays because Julia is built around matrix manipulation. We will get to cooler functions and applications later, but feel free to do some research on your own, especially during the Euler problems (Hint: if you "wish" a function that manipulated an array in a certain way existed, chances are it does, you just need to find it).

Conditionals

Julia has if statements. They are structured like this:

In [38]:
x = 15
y = 15

if x > y
    println("$x is greater than $y")
else
    println("$x is equal to $y")
end
15 is equal to 15
In [39]:
x > y ? println("$x is greater than $y") : println("$x is equal to $y")
15 is equal to 15

Some major takeaways. First, unlike Python, there is no : after the ifs, elseifs or elses. This takes some getting used to. Secondly, to end the conditional, we write end. This will go for loops and functions as well. Julia also supports the ternary operator. I love the way it looks but it is kind of difficult to use and read, so I do not recommend using it most of the time. Below, we check if the thing before the ? is true, and if it is, we do the thing to the right of the ?. If not, we do the thing to the right of the :.

In [40]:
a = true
a ? println("a is true") : println("a is false")
a is true

Logic

Julia contains mostly the same logic syntax as Java. && denotes and, which only is true if both things on either side of the conditional are true. || denotes or, which is true if one or both things on either side of the conditional are true. ! denotes not, which makes a true statement false and a false statement true. && has a higher precedence in the order of operations than || but if you are worried about messing up the order, feel free to use parentheses to denote precedence. It is easy to mess around with them, especially in the space I have provided below :).

In [41]:
# change these to examine their behavior
x = true
y = true

println(!x) # not x

println(x && y) # x and y

println(x || y) # x or y
false
true
true

It can be helpful to know a few equalities as well (play around with the truth values of x, y, and z if you don't believe they will always be true):

In [42]:
# DeMorgan's Law
println(!(x && y) == (!x || !y))
println(!(x || y) == (!x && !y))

# Distribution of and over or and vice versa
z = true
println((z && (x || y)) == ((z && x) || (x && y)))
println((z || (x && y)) == ((z || x) && (x || y)))
true
true
true
true

There is also a helpful tool called short-circut evaluation. Basically when Julia is presented with an ||, if the thing to the left is true, it marks the statement as true and doesn't bother evaluating the other side. This means we can avoid the out of bounds error in the following situation:

In [45]:
arr = [1,2,3]

println(length(arr) > 4 && arr[4] == 4) # notice that arr[4] would throw an error
false

structs and consts

A struct in Julia is a lot like a struct in C, if you've seen those before. It's a custom data type with specific properties. Julia actually isn't an object-oriented language, so structs are as close as you get to objects in Julia.

In [46]:
# Run this block once to declare a Person type
struct Person{X}
    name::String
    age::Int
    adult::Bool
    pocket::X  # we can specify a custom type here and attach it to person
end
In [60]:
function convert(me::Person)
    return me.age
end
error in method definition: function Base.convert must be explicitly imported to be extended

Stacktrace:
 [1] top-level scope at none:0
 [2] top-level scope at In[60]:1
In [47]:
# Now run this block to create our person
jeff = Person{Rational}("Jeff", 30, true, 7)
Out[47]:
Person{Rational}("Jeff", 30, true, 7//1)

Notice how 7 gets coerced into a Rational, because we declared the Person with type Rational. We can access the properties of jeff like so:

In [48]:
println(jeff.name)
println(jeff.pocket)
Jeff
7//1

A const keyword on a variable in Julia just means we can only define the variable once. See below for an example:

In [49]:
const myConstant = 10

myConstant = "new value"
invalid redefinition of constant myConstant

Stacktrace:
 [1] top-level scope at In[49]:2

Loops

Let's talk about for loops and while loops. As you probably know, for loops run for every element in the set it is fed. while loops run while some condidition is true. For example, if we feed a for loop the range 1:5. Note: Ranges are inclusive on both ends in Julia, unlike Python.

In [50]:
# for loops
for n in 1:5
    println(n)
end
1
2
3
4
5
In [51]:
# while loops
n = 1
while n <= 5
    println(n)
    n += 1 # n++ does not work unfortunately
end
1
2
3
4
5

Obligatory LOOPS HAVE THEIR OWN SCOPE announcement

Scope is like the area of a program a variable is acessible in.

This one will get ya. If you're writing a Julia script (not in a notebook!), you need to specify if you're using a variable that isn't declared inside the foor loop. To do this, we use the global keyword.

In [53]:
# Code in notebook
classes_christian_taught = 0
for i in 1:6
    classes_christian_taught += 1
end

# try running it as a script
run(`julia -e "classes_christian_taught = 0
for i in 1:6
    global classes_christian_taught
    classes_christian_taught += 1
end
    println(classes_christian_taught)"`)
6
Out[53]:
Process(`julia -e 'classes_christian_taught = 0
for i in 1:6
    global classes_christian_taught
    classes_christian_taught += 1
end
    println(classes_christian_taught)'`, ProcessExited(0))

Now for the great way to initialize an array I promised earlier. Julia supports a lot of single line things, especially when it comes to arrays. This is the most "Julia" way to initialize an array with the numbers 1 through 5 in it.

In [54]:
nums = [n for n in 1:5]
Out[54]:
5-element Array{Int64,1}:
 1
 2
 3
 4
 5
In [56]:
nums = []

for n in 1:5
    push!(nums, n)
end
println(nums)
Any[1, 2, 3, 4, 5]

Another "hacky" thing you can do in Julia is single line nested for loops. To illustrate this, lets create a simple mulitplication table represented as a matrix in 3 different ways, getting progressively more "Julia".

In [57]:
# Method 1
method1 = Array{Int, 2}(undef, 12,12) # start with an undefined 12x12 matrix

# use classic nested for loops
for row in 1:12
    for col in 1:12
        method1[row, col] = row * col
    end
end

method1
Out[57]:
12×12 Array{Int64,2}:
  1   2   3   4   5   6   7   8    9   10   11   12
  2   4   6   8  10  12  14  16   18   20   22   24
  3   6   9  12  15  18  21  24   27   30   33   36
  4   8  12  16  20  24  28  32   36   40   44   48
  5  10  15  20  25  30  35  40   45   50   55   60
  6  12  18  24  30  36  42  48   54   60   66   72
  7  14  21  28  35  42  49  56   63   70   77   84
  8  16  24  32  40  48  56  64   72   80   88   96
  9  18  27  36  45  54  63  72   81   90   99  108
 10  20  30  40  50  60  70  80   90  100  110  120
 11  22  33  44  55  66  77  88   99  110  121  132
 12  24  36  48  60  72  84  96  108  120  132  144
In [58]:
# Method 2
method2 = Array{Int, 2}(undef, 12,12) # start with an undefined 12x12 matrix

# use the more Julia, single line nested for loops
for row in 1:12, col in 1:12
    method2[row, col] = row * col
end

method2
Out[58]:
12×12 Array{Int64,2}:
  1   2   3   4   5   6   7   8    9   10   11   12
  2   4   6   8  10  12  14  16   18   20   22   24
  3   6   9  12  15  18  21  24   27   30   33   36
  4   8  12  16  20  24  28  32   36   40   44   48
  5  10  15  20  25  30  35  40   45   50   55   60
  6  12  18  24  30  36  42  48   54   60   66   72
  7  14  21  28  35  42  49  56   63   70   77   84
  8  16  24  32  40  48  56  64   72   80   88   96
  9  18  27  36  45  54  63  72   81   90   99  108
 10  20  30  40  50  60  70  80   90  100  110  120
 11  22  33  44  55  66  77  88   99  110  121  132
 12  24  36  48  60  72  84  96  108  120  132  144
In [59]:
# Method 3

# use the *very* Julia single line array comprehension
method3 = [row * col for row in 1:12, col in 1:12] # so clean!
Out[59]:
12×12 Array{Int64,2}:
  1   2   3   4   5   6   7   8    9   10   11   12
  2   4   6   8  10  12  14  16   18   20   22   24
  3   6   9  12  15  18  21  24   27   30   33   36
  4   8  12  16  20  24  28  32   36   40   44   48
  5  10  15  20  25  30  35  40   45   50   55   60
  6  12  18  24  30  36  42  48   54   60   66   72
  7  14  21  28  35  42  49  56   63   70   77   84
  8  16  24  32  40  48  56  64   72   80   88   96
  9  18  27  36  45  54  63  72   81   90   99  108
 10  20  30  40  50  60  70  80   90  100  110  120
 11  22  33  44  55  66  77  88   99  110  121  132
 12  24  36  48  60  72  84  96  108  120  132  144

Now that's what I call a times table!

Functions

"Wow! I couldn't function without functions!" - Cameron, probably.

Say we want a function to square things. We would use the keyword function to tell Julia we want to write a function, return to tell her to return, and end to tell her we are done writing the function.

In [61]:
# write and test squareMe
function squareMe(x)
    return x^2
end

println(squareMe(1))
println(squareMe(2))
println(squareMe(5))
1
4
25

Remember how Julia can square strings? What if we tried to throw in a string?

In [62]:
# trying a string
squareMe("Big Green Tractor")
Out[62]:
"Big Green TractorBig Green Tractor"

Julia can handle it! If we wanted to specify numbers only, we could add type definitions to our function definition. Let's make a method called squareMeNumbers and restrict it to numbers only, using Julia's abstract Number type.

In [64]:
# limit squareMe to numbers only
function squareMeNumbers(x::Number)::Number
    return x^2
end

println(squareMeNumbers(7))
println(squareMeNumbers("Test"))
49
MethodError: no method matching squareMeNumbers(::String)
Closest candidates are:
  squareMeNumbers(!Matched::Number) at In[64]:3

Stacktrace:
 [1] top-level scope at In[64]:7

What's cool about these function definitions is that we can specify the same function multiple times and have it act differently based on what type it's given. Check this out:

In [65]:
# write two versions of the same function with multiple dispatch
function guessNumber(x::Int)
    return x == 69 ? "Nice!" : "Nope that's not it."
end

function guessNumber(x) # generic function without type
    return "That's not a number!"
end
Out[65]:
guessNumber (generic function with 2 methods)

Julia figures out what method we want based on our input. This feature is called multiple dispatch.

In [66]:
println(guessNumber(69))
println(guessNumber("abc"))
Nice!
That's not a number!
In [67]:
guessNumber
Out[67]:
guessNumber (generic function with 2 methods)

In fact, for many functions, Julia will accept all types of inputs, as long as they make sense.

More ways to define functions

There are three ways to define functions. Here they are below.

In [68]:
function helloWorldNormal()
    println("Hello, World!")
end

helloWorldVariable = () -> println("Where is Christian today?") # anonymous method

helloWorldInline() = println("Nowhere to be found.")

f(x) = x^2 # mathy way
Out[68]:
f (generic function with 1 method)
In [69]:
helloWorldVariable()
helloWorldInline()

f(5)
Where is Christian today?
Nowhere to be found.
Out[69]:
25

What the ! means in Julia

Remember how ! denote that a function will change the array it is inputed? Here is a great example.

In [70]:
toSort = [5, 2, 7]

println(sort(toSort))

toSort
[2, 5, 7]
Out[70]:
3-element Array{Int64,1}:
 5
 2
 7

Notice how the array was sorted when it was returned, but the array itself was not altered. Compare that to sort!.

In [71]:
toSort = [5, 2, 7]

println(sort!(toSort))

toSort
[2, 5, 7]
Out[71]:
3-element Array{Int64,1}:
 2
 5
 7

The array is actually sorted now. Something to keep in mind while coding.

Euler Homework Problems

Attempt these problems for extra Julia practice for homework. After each problem, you're provided with a code cell to work on your code. You might be able to present your solutions in class.

Euler 1 (Multiples of 3 and 5)

https://projecteuler.net/problem=1

In [ ]:

Euler 2 (Even Fibonacci numbers)

https://projecteuler.net/problem=2

In [ ]:

Euler 4 (Largest palindrome product)

https://projecteuler.net/problem=4

Hint: use the digits() function

In [ ]:

Euler 6 (Sum square difference)

https://projecteuler.net/problem=6

In [ ]:

Euler 8 (Largest product in a series)

https://projecteuler.net/problem=8

In [ ]:

Euler 9 (Special Pythagorean triplet)

https://projecteuler.net/problem=9

Hint: Julia is fast! Just brute force this one.

In [ ]: