Skip to content

Instantly share code, notes, and snippets.

@Tokiyomi
Tokiyomi / equalsum.cs
Last active October 21, 2022 21:48
Equal sum solution in C#
// Code Jam Individual Problem - Equal Sum - Carolina Garma
// Prev knowledge: binary representation, partitions
using System;
using System.Collections.Generic;
using System.Linq;
namespace GoogleJam
{
class EqualSum
@Tokiyomi
Tokiyomi / powers_of_two.kt
Last active October 21, 2022 21:55
Generate a list of powers of two in Kotlin
// Kotlin solution
fun powers_of_two(N:Int):MutableList<Long> {
/*
This function generates a tactical N set 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
*/
var A = mutableListOf<Long>() // Open empty list
@Tokiyomi
Tokiyomi / equalsum.py
Created October 21, 2022 21:57
powers of two in python
# Python Solution
def powers_of_two(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
"""
A = [2**i for i in range(30)] + [10**9 - n for n in range(N-30)]
@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;
}
@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 / 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 / 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);
// Constructing the string to print multiple times
String plus = "";
String bars = "";
// Plus sign string
for (int i = 0; i < cols ; i ++) {
plus += "+-";
}
plus += "+";
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
// 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()