-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cd709b9
Showing
57 changed files
with
1,808 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public enum Direction { | ||
UP, | ||
DOWN, | ||
LEFT, | ||
RIGHT | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class HelloWorld { | ||
public static void main(String args[]) { | ||
System.out.println("Hello world!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class Main { | ||
public static void main(String args[]) { | ||
System.out.println("It's alive! It's alive!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
public class Robot { | ||
private int x=0; | ||
private int y=0; | ||
private Direction direction = Direction.UP; | ||
|
||
public Robot(int x, int y, Direction direction) { | ||
this.x = x; | ||
this.y = y; | ||
this.direction = direction; | ||
} | ||
|
||
public Direction getDirection() { | ||
// текущее направление взгляда | ||
return(direction); | ||
} | ||
|
||
public int getX() { | ||
// текущая координата X | ||
return(x); | ||
} | ||
|
||
public int getY() { | ||
// текущая координата Y | ||
return(y); | ||
} | ||
|
||
public void turnLeft() { | ||
// повернуться на 90 градусов против часовой стрелки | ||
switch (getDirection()){ | ||
default: | ||
case DOWN: | ||
direction = Direction.RIGHT; | ||
break; | ||
case UP: | ||
direction = Direction.LEFT; | ||
break; | ||
case RIGHT: | ||
direction = Direction.UP; | ||
break; | ||
case LEFT: | ||
direction = Direction.DOWN; | ||
} | ||
} | ||
|
||
public void turnRight() { | ||
// повернуться на 90 градусов по часовой стрелке | ||
switch (getDirection()){ | ||
default: | ||
case DOWN: | ||
direction = Direction.LEFT; | ||
break; | ||
case UP: | ||
direction = Direction.RIGHT; | ||
break; | ||
case RIGHT: | ||
direction = Direction.DOWN; | ||
break; | ||
case LEFT: | ||
direction = Direction.UP; | ||
} | ||
} | ||
|
||
public void stepForward() { | ||
// шаг в направлении взгляда | ||
// за один шаг робот изменяет одну свою координату на единицу | ||
switch (getDirection()){ | ||
default: | ||
case DOWN: y--; | ||
break; | ||
case UP: y++; | ||
break; | ||
case RIGHT: x++; | ||
break; | ||
case LEFT: x--; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class task2_1_1 { | ||
public static boolean booleanExpression(boolean a, boolean b, boolean c, boolean d) { | ||
if (((a ^ b) && (c ^ d)) || | ||
((a && b) && !c && !d) || | ||
(!a && !b && (c && d))) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
public static void main(String args[]) { | ||
boolean a = booleanExpression(false, true, true, true); | ||
System.out.println(a); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import java.math.*; | ||
|
||
public class task2_1_3 { | ||
public static boolean doubleExpression(double a, double b, double c) { | ||
return Math.abs(a + b - c) < 1e-4; | ||
} | ||
public static void main(String args[]) { | ||
boolean a = doubleExpression(0.1, 0.2, 0.3); | ||
System.out.println(a); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import java.math.*; | ||
|
||
public class task2_1_4 { | ||
/** | ||
* Flips one bit of the given <code>value</code>. | ||
* | ||
* @param value any number | ||
* @param bitIndex index of the bit to flip, 1 <= bitIndex <= 32 | ||
* @return new value with one bit flipped | ||
*/ | ||
public static int flipBit(int value, int bitIndex) { | ||
return value ^= 1 << --bitIndex; | ||
} | ||
public static void main(String args[]) { | ||
int a = flipBit(4, 4); | ||
System.out.println(a); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import java.math.*; | ||
import java.lang.*; | ||
|
||
public class task2_3_1 { | ||
/** | ||
* Flips one bit of the given <code>value</code>. | ||
* | ||
* @param value any number | ||
* @param bitIndex index of the bit to flip, 1 <= bitIndex <= 32 | ||
* @return new value with one bit flipped | ||
*/ | ||
public static boolean isPalindrome(String text) { | ||
StringBuilder strb = new StringBuilder(text.replaceAll("[\\W]", "")); | ||
|
||
return (new String(strb)).equalsIgnoreCase(new String(strb.reverse())); | ||
} | ||
public static void main(String args[]) { | ||
System.out.println(isPalindrome("Madam, I'm Adam!")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import java.math.*; | ||
import java.lang.*; | ||
|
||
public class task2_4_1 { | ||
/** | ||
* Flips one bit of the given <code>value</code>. | ||
* | ||
* @param value any number | ||
* @param bitIndex index of the bit to flip, 1 <= bitIndex <= 32 | ||
* @return new value with one bit flipped | ||
*/ | ||
public static BigInteger factorial(int value) { | ||
if (value == 1) { | ||
return BigInteger.ONE; | ||
} | ||
else { | ||
return factorial(value-1).multiply(BigInteger.valueOf(value)); | ||
} | ||
} | ||
public static void main(String args[]) { | ||
for (int i = 1; i <= 10; i++) { | ||
System.out.println(i + " " + factorial(i).toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import java.math.*; | ||
import java.util.Arrays; | ||
import java.lang.*; | ||
|
||
public class task2_4_2 { | ||
/** | ||
* Flips one bit of the given <code>value</code>. | ||
* | ||
* @param value any number | ||
* @param bitIndex index of the bit to flip, 1 <= bitIndex <= 32 | ||
* @return new value with one bit flipped | ||
*/ | ||
public static int[] mergeArrays(int[] a1, int[] a2) { | ||
int[] merge = new int[a1.length + a2.length]; | ||
int i1 = 0, i2 = 0; | ||
|
||
for (int k = 0; k < merge.length; k++) { | ||
if (i1 > a1.length-1) { | ||
merge[k] = a2[i2]; | ||
i2++; | ||
} | ||
else if (i2 > a2.length-1) { | ||
merge[k] = a1[i1]; | ||
i1++; | ||
} | ||
else if (a1[i1] < a2[i2]) { | ||
merge[k] = a1[i1]; | ||
i1++; | ||
} | ||
else { | ||
merge[k] = a2[i2]; | ||
i2++; | ||
} | ||
} | ||
return merge; // your implementation here | ||
} | ||
public static void main(String args[]) { | ||
int[] a1 = {0}; | ||
int[] a2 = {0, 1, 3}; | ||
|
||
System.out.println(Arrays.toString(mergeArrays(a1, a2))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
public class task3_3_1 { | ||
|
||
public static void moveRobot(Robot robot, int toX, int toY) { | ||
Direction destDir; | ||
// Определим направление движения по оси X | ||
destDir = toX - robot.getX() >= 0 ? Direction.RIGHT : Direction.LEFT; | ||
while (robot.getDirection() != destDir) { | ||
robot.turnLeft(); | ||
// System.out.println(destDir+" "+robot.getDirection()); | ||
} | ||
// Двигаемся по оси X | ||
while (robot.getX() != toX) { | ||
robot.stepForward(); | ||
// System.out.println(toX+" "+robot.getDirection()+" "+ (toX - robot.getX())); | ||
} | ||
// Определим направление движения по оси Y | ||
destDir = toY - robot.getY() >= 0 ? Direction.UP : Direction.DOWN; | ||
while (robot.getDirection() != destDir) { | ||
robot.turnLeft(); | ||
// System.out.println(destDir+" "+robot.getDirection()); | ||
} | ||
// Двигаемся по оси Y | ||
while (robot.getY() != toY) { | ||
robot.stepForward(); | ||
// System.out.println(toY+" "+robot.getDirection()+" "+ (toY - robot.getY())); | ||
} | ||
} | ||
public static void main(String args[]) { | ||
Robot R = new Robot(1, 8, Direction.UP); | ||
moveRobot(R, -10, -5); | ||
System.out.println(R.getX()+" "+R.getY()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
arr = ((0, -0.5), (1, 0), (0, 0.5), (0, 1.5), (1, 2.5), (2,3)) | ||
|
||
def sqerr(a, b): | ||
return (a - b)**2 | ||
|
||
def abserr(a, b): | ||
return abs(a - b) | ||
|
||
def errsum(err_fun): | ||
return sum(list(map(lambda pair: err_fun(pair[0], pair[1]), arr))) | ||
|
||
print(str(max(errsum(abserr), errsum(sqerr)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
def z(x,y): | ||
return x**3 + 4 * y**3 - 3*x - 3*y | ||
|
||
def dz2xx(x, y): | ||
return 6*x | ||
|
||
def dz2xy(x, y): | ||
return 0 | ||
|
||
def dz2yy(x, y): | ||
return 24*y | ||
|
||
ans = [(1, 0.5), (1, -0.5), (-1, 0.5), (-1, -0.5)] | ||
|
||
for a in ans: | ||
print(a, z(*a)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import numpy as np | ||
|
||
A = np.eye(3, 4) * 2 | ||
B = np.eye(3, 4, 1) | ||
mat = (A + B).flatten().reshape(12,1) | ||
|
||
print(mat) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import numpy as np | ||
|
||
x_shape = tuple(map(int, input().split())) | ||
X = np.fromiter(map(int, input().split()), np.int).reshape(x_shape) | ||
|
||
y_shape = tuple(map(int, input().split())) | ||
Y = np.fromiter(map(int, input().split()), np.int).reshape(y_shape) | ||
|
||
if x_shape[1] != y_shape[1]: | ||
print('matrix shapes do not match') | ||
else: | ||
print(X @ Y.T) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import numpy as np | ||
from urllib.request import urlopen | ||
|
||
f = urlopen(input()) | ||
|
||
A = np.loadtxt(f, skiprows=1, delimiter=',') | ||
print(A.mean(axis=0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import numpy as np | ||
|
||
X = np.array([[1, 60], | ||
[1, 50], | ||
[1, 75] | ||
]) | ||
|
||
Y = np.array([ | ||
[10], | ||
[7], | ||
[12] | ||
]) | ||
|
||
XtX1 = np.linalg.inv(X.T @ X) | ||
b = XtX1 @ X.T @ Y | ||
|
||
print(b.flatten()) | ||
print(b) | ||
print('{0:.3f}, {1:.3f}'.format(*b.flatten())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
''' | ||
Найдите оптимальные коэффициенты для построения линейной регрессии. | ||
''' | ||
import numpy as np | ||
from urllib.request import urlopen | ||
|
||
# загрузим данные из URL из входа | ||
f = urlopen(input()) | ||
A = np.loadtxt(f, skiprows=1, delimiter=',') | ||
|
||
# Конструируем матрицы X и Y | ||
Y= A[:,0] | ||
Y.shape = (Y.shape[0],1) | ||
X = np.hstack((np.ones_like(Y), A[:,1:])) | ||
|
||
# Считаем коэффициенты линейной регрессии | ||
# b = (X.T * X) ** -1 * X.T * Y | ||
# | ||
b = np.linalg.inv(X.T @ X) @ X.T @ Y | ||
|
||
print(*list(map('{0:.4f}'.format, b.flatten()))) |
Oops, something went wrong.