## Why Are E-Books More Expensive Than Printed Books?

Today, I saw this site on Hackernews and I shared the link with my friends. Then, I wanted to know if there was an e-book version and yes, there is. But something caught my attention. When I checked the printed version of this book, It’s price is same with e-book version!! This is a complete nonsense! Sometimes e-books are more expensive than printed books!

It is logical that e-books should be cheaper than printed books. I searched on web and I found this article. Apparently, the prices of e-books are too high because of the publisher’s greed!! This must be stopped!!

I prefer e-books because there is no paper consumption, access is easier, and for a lot of reasons, but all these beautiful things do not happen because of the publisher’s greed.

I hope this situation will improve soon.

## Project Euler – Problem 3 Solution

Problem: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?
* https://projecteuler.net/problem=3

Php;

```<?php

class ProblemSolver
{
private \$original_number;
private \$number;
private \$current_prime_number = 2;
private \$prime_numbers = [];
private \$largest_prime_number;

/**
* ProblemSolver constructor.
* @param int \$number
*/
public function __construct(int \$number)
{
\$this->number = \$this->original_number = \$number;
}

/**
* Finds the next prime number
*/
private function find_next_prime_number()
{
if (\$this->current_prime_number == 2) {
\$this->current_prime_number++;
} else {
\$this->current_prime_number += 2;
}
\$can_divide = false;
\$number = 2;
while (\$number < \$this->current_prime_number) {
if (\$this->current_prime_number % \$number == 0) {
\$can_divide = true;
}
\$number++;
}
if (\$can_divide) {
\$this->find_next_prime_number();
}
}

/**
* Finds the prime factors and largest prime factor of given number
*/
public function find_prime_factors()
{
while (\$this->number > 0) {
if (\$this->number == 1) {
\$this->largest_prime_number = \$this->current_prime_number;
break;
} else {
if (\$this->number % \$this->current_prime_number == 0) {
\$this->prime_numbers[] = \$this->current_prime_number;
\$this->number /= \$this->current_prime_number;
} else {
\$this->find_next_prime_number();
}
}
}
echo \$this->largest_prime_number;
}
}

\$solver = new ProblemSolver(600851475143);
\$solver->find_prime_factors();```

Javascript;

```'use strict';

var number = 600851475143, prime_number = 2;

function find_next_prime_number() {
var can_divide = false;
var n = 2;
if (prime_number === 2) {
prime_number++;
} else {
prime_number += 2;
}
while (n < prime_number) {
if (prime_number % n === 0) {
can_divide = true;
}
n++;
}
if (can_divide) {
find_next_prime_number();
}
}

while (number > 1) {
if (number % prime_number === 0) {
number /= prime_number;
} else {
find_next_prime_number();
}
}
console.log(prime_number);```

## Project Euler – Problem 2 Solution

Problem: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, … By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
* https://projecteuler.net/problem=2

Php;

```<?php

// Parameters
\$total = 2;
\$array = [1, 2];

while (true) {
\$array_count = count(\$array);
\$sum = \$array[\$array_count - 1] + \$array[\$array_count - 2];
if (\$sum < 4000000) {
\$array[] = \$sum;
if (\$sum % 2 == 0) {
\$total += \$sum;
}
} else {
break;
}
}
echo \$total;```

Javascript;

```'use strict';

// Parameters
var total = 2,
array = [1, 2],
sum,
array_count;

while (true) {
array_count = array.length;
sum = array[array_count -1] + array[array_count - 2];
if (sum < 4000000) {
array.push(sum);
if (sum % 2 === 0) {
total += sum;
}
} else {
break
}
}

console.log(total);```

## Project Euler – Problem 1 Solution

Problem: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
* https://projecteuler.net/problem=1

Php;

```<?php

// Parameters
\$total = 0;

for (\$i = 1; \$i < 1000; \$i++) {
if (\$i % 3 == 0 || \$i % 5 == 0) {
\$total += \$i;
}
}
echo \$total;```

Javascript

```'use strict';

// Parameters
var total = 0, i;

for (i = 1;i < 1000; i++) {
if (i % 3 === 0 || i % 5 === 0) {
total += i;
}
}

console.log(total);```

## Making Snake Game With Javascript

Ever since childhood I have always wondered how to make games and I wanted to make my own game one day. After spending so much time in the software industry, I asked myself why I should not do it anymore. Thus, I will improve my Javascript skill and I will also look at the software development process in a way that I have never looked at before.

Before I started coding the game, I began to think about how the algorithm of the snake’s movement would be. Some of the first options that came to mind were; scan the entire playground in every move, to keep the coordinates of each cell of the snake on a array and update the old and new cells while moving. At the end, I understood that it was best to erase the last cell of the snake and attach a cell to the head.

First I created a snake object and I wrote the code that would create the playground. After creating the playground, I found a nice font for the game and added it. I wrote the algorithm that would make the snake move after I wrote a code that composes the snake and puts it into the playground.

When I wrote the snake’s movement for the first time, it continued to move outside the playing field and could go back inside. For example, while the snake was moving upwards, if I pressed down, it was moving within itself.

First of all, if the snake came to the edge of the playing field, I wrote the codes that would allow it to continue from the other end. So, for example, if the snake reached the left edge, it would have entered the right edge.

After that, I wrote the codes that control the direction key that moves according to the direction the snake moves. So, for example, if I press down on the button while the snake is moving up, it doesn’t do anything. After this I added the ability to start and stop the game.

At this point, I stopped taking care of for about a month or two. A lot of different thoughts and things got in.

Today the game came to mind again and I started again. Finally, I finished the game by adding the bait, the game score and the ability to manage game settings.

I enjoyed making this game very much and I am very excited to see the result. Only problem is if we press the arrow keys too fast, the snake starts to act ridiculous. I think this is caused by the frame rate of the game, but I have not figured it out yet.

My next goal is to write a tetris or a simpler than tetris.

You can play the game on here.

You can check the codes on here.

## How to get timezone offset on MySQL?

Hello to everyone.

When I was working recently, I needed a timezone offset on one subject. I could calculate timezone offset on php but I thought it would be easier and more advantageous to find it on MySQL. So I created a query that calculates the timezone offset and I will share it with you.

`SELECT TIME_FORMAT(TIMEDIFF(NOW(), CONVERT_TZ(NOW(), 'Asia/Kathmandu', 'UTC')), '%H:%i') as offset;`

Result will be;

’05:45′