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
resource "aws_subnet" "subnet_1" { | |
availability_zone = "eu-west-1a" | |
cidr_block = "172.18.0.0/28" | |
tags = { | |
"Name" = "private-subnet-1" | |
} | |
vpc_id = aws_vpc.private_and_public_subnets.id | |
} |
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
resource "aws_vpc" "private_and_public_subnets" { | |
cidr_block = "172.18.0.0/27" # 32 IPs | |
enable_dns_hostnames = true | |
enable_dns_support = true | |
instance_tenancy = "default" | |
tags = { | |
"Name" = "${local.project}-vpc" | |
} | |
} |
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
locals { | |
project = "private-public-subnets" | |
region = "eu-west-1" | |
} |
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
provider "aws" { | |
region = local.region | |
default_tags { | |
tags = { | |
project = local.project | |
terraform = "1" | |
} | |
} | |
} |
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
terraform { | |
required_providers { | |
aws = { | |
source = "hashicorp/aws" | |
version = "5.8.0" | |
} | |
} | |
required_version = ">=1.5.3" | |
} |
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
import java.util.Scanner; | |
public class IntegerToBinary { | |
public static void main(String[] args) { | |
System.out.print("Give me an integer number: "); | |
Scanner scanner = new Scanner(System.in); | |
if (scanner.hasNextInt()) { | |
int integer = scanner.nextInt(); | |
System.out.printf("Binary: %s\n", Integer.toString(integer, 2)); |
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
import java.util.Scanner; | |
public class IntegerToBinaryRecursive { | |
/** | |
* Given an integer N, its binary representation is | |
* the binary representation of N/2 suffixed with the modulo of N % 2 | |
*/ | |
public static String toBinary(int integer) { | |
if (integer <= 1) { | |
return Integer.toString(integer); |
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
import java.util.Scanner; | |
import java.util.Stack; | |
public class IntegerToBinary { | |
/** | |
* Takes an integer and returns its binary representation. | |
* It uses a Stack structure to print the digits. | |
* | |
*/ | |
public static String toBinary(int integer) { |
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
class IntegerToBinary | |
def initialize(integer) | |
@integer = integer | |
end | |
def binary | |
return integer.to_s if integer <= 1 | |
"#{IntegerToBinary.new(integer / 2).binary}#{integer % 2}" | |
end |
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
class IntegerToBinary | |
def initialize(integer) | |
@integer = integer | |
end | |
def binary | |
return '0' if integer.zero? | |
stack = [] |