Skip to content

Instantly share code, notes, and snippets.

// Main in Kotlin
fun main() {
val T:Int = readln().toInt(); // Read number of cases
for (t in 0..T-1) {
var N:Int = readln().toInt(); // Read N int
if (N == -1) {
break
# Main in python
def main():
T = int(input())
for t in range(T):
N = int(input()) # Read N
if N==-1:
break
# Solve Sum in Python
def solve_sum(A, B):
"""
This function implements a greedy approach to minimize the sum difference
among two sets A and B
"""
C = sorted(A + B, reverse=True) # Join both subsets and sort them in reversed order
a_sum = 0
b_sum = 0
// Solve sum in Kotlin
fun solve_sum(A:MutableList<Long>, B:MutableList<Long>):MutableList<Long> {
/*
This function implements a greedy approach to minimize the sum difference
among two sets A and B
*/
var C = A + B
C = C.sortedDescending().toMutableList()
def solveTree():
N = int(input()) # Number of nodes/modules/leaves
F = [0] + [int(f) for f in str(input()).split(' ')] # List of fun factors + an extra 0 at the begining to store the abyss (root value)
P = [int(p) for p in str(input()).split(' ')] # List of pointers
adj = [[] for i in range(N+1)] # Create an array of adjacency lists of all the nodes + 1 list for the abyss adj nodes
for i in range(len(P)): # For each pointer
# Add the adj nodes to the node pointed
adj[P[i]].append(i+1) # append the index + 1 as we added the abyss as a node,so adj[0] are the nodes pointing to the abyss then
// Constructing the string to print multiple times
String plus = "";
String bars = "";
// Plus sign string
for (int i = 0; i < cols ; i ++) {
plus += "+-";
}
plus += "+";
@Tokiyomi
Tokiyomi / top-left.dart
Created October 24, 2022 03:00
dart punched cards
// Top left print
String top_left_plus = "..";
for (int i = 0; i < cols - 1 ; i ++) {
top_left_plus += "+-";
}
top_left_plus += "+";
print(top_left_plus);
@Tokiyomi
Tokiyomi / solve_sum.cs
Created October 21, 2022 22:14
solve sum in C#
// Solve sum in C#
static List<long> solve_sum(List<long> A, List<long> B)
/*
This function implements a greedy approach to minimize the sum difference
among two sets A and B
*/
{
// Join A and B into a new list C
var C = new List<long>();
@Tokiyomi
Tokiyomi / powers_of_two.cs
Created October 21, 2022 22:13
powers of two in C#
// Powers of two in C#
static List<long> powers_of_two(int N)
/*
This function generates my proposed tactical N sets of numbers made of powers of 2
and the remaining N-30 numbers will be the last N numbers before 10**9 inclusive.
As N is always 100, this fuction is always performed without problems
*/
{
@Tokiyomi
Tokiyomi / main.cs
Last active October 21, 2022 22:17
powers of two in C#
// Main function in C#
static void Main(string[] args)
{
long T = Convert.ToInt64(Console.ReadLine()); // Read # of Cases
for (int i = 0; i < T; i++){
int N = Convert.ToInt32(Console.ReadLine()); // Read N
if (N == -1) { // if N==-1, end program
break;
}