HOB Software Competition

For their 25th anniversary HOB Software decided to have a Problem Solving competition

 

1

2

I was at work and decided to give it a go during the break. After decompressing the HSM Problem solving Competition.rar6

Stage 1:

I opened the raw class file in vim and noticed something interesting

7

<p style=”font-size:110%”><b>Stage 2: U3RhZ2UgMzogNTMgNzQgNjEgNjcgNjUgMjAgMzQgM2EgMjAgMzEgMzMgMzQgMzcgMzcgMzcgMzMgMzcgMzUgMzY=</b></p>

To me this seemed like a base64 encoded string prefixed with Stage 2: meant I somehow solved the first Stage. Not being satisfied I decided to decompile the class back to java which produced the following code:

import Main;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagLayout;
import java.awt.LayoutManager;
import java.io.File;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.Border;

public class Competition
extends JFrame {
final String gz = "STAGE 1 COMPLETE! 4 STAGES LEFT!";
private static final long serialVersionUID = 1;
private String gotostage2dottxt = "gotostage2.txt";
private JTextPane label;

public Competition() {
super("HOB Software Malta Competition");
this.setDefaultCloseOperation(3);
this.setLayout(new GridBagLayout());
this.label = new JTextPane();
this.label.setEditable(false);
this.label.setBackground(null);
this.label.setBorder(null);
this.label.setContentType("text/html");
File file = new File(String.valueOf(this.getExecutableLocation()) + this.gotostage2dottxt);
if (file.exists() && !file.isDirectory()) {
this.doTextFilePresentProcedure();
this.setSize(1000, 200);
} else {
this.doTextFileAbsentProcedure();
this.setSize(600, 200);
}
this.setLocationRelativeTo(null);
this.setVisible(true);
}

String getExecutableLocation() {
return Main.class.getProtectionDomain().getCodeSource().getLocation().getPath().replaceAll("%20", " ");
}

void doTextFilePresentProcedure() {
this.label.setText("<p style=\"font-size:110%\"><b>Stage 2: U3RhZ2UgMzogNTMgNzQgNjEgNjcgNjUgMjAgMzQgM2EgMjAgMzEgMzMgMzQgMzcgMzcgMzcgMzMgMzcgMzUgMzY=</b></p>");
JPanel panel1 = new JPanel(new GridBagLayout());
panel1.add(this.label);
this.add(panel1);
}

void doTextFileAbsentProcedure() {
this.label.setText("<p style=\"font-size:150%\"><b>404 - File Not Found</b></p>");
JPanel panel1 = new JPanel(new GridBagLayout());
panel1.add(this.label);
this.add(panel1);
}
}

There is a conditional looking for a file named gotostage2.txt, so in reality the first stage was to create an empty text file named gotostage2.txt and execute the run_me.bat.

3

another fact seems like that from “STAGE 1 COMPLETE! 4 STAGES LEFT!” this competition has 5 stages.

Stage 2:

https://www.base64decode.org/

4

U3RhZ2UgMzogNTMgNzQgNjEgNjcgNjUgMjAgMzQgM2EgMjAgMzEgMzMgMzQgMzcgMzcgMzcgMzMgMzcgMzUgMzY=

Stage 3: 53 74 61 67 65 20 34 3a 20 31 33 34 37 37 37 33 37 35 36

 

Stage 3:

http://www.rapidtables.com/convert/number/hex-to-ascii.htm

53 74 61 67 65 20 34 3a 20 31 33 34 37 37 37 33 37 35 36

5

Stage 4: 1347773756

Stage 4:

1347773756

 

I tried a lot of things including trying to map the numbers to letters on the phone keypad but yielded no success.

Stuck here!!

 

Stage 5:

??

CodingChillout.Malta: Prefix-suffix balance

http://codechillout.sphere-contest.com/problems/onlineround/PREFSUFF

Prefix-suffix balance

One of the most popular problems presented during the initial stages of IT recruitment is that of finding a place in a sequence of integers which divides it into two groups of equal sum, i.e., at a position where the sum of the prefix is equal to the sum of the suffix. Your task is to find this position.

Input

The first line contains exactly one number t, representing the number of data sets. Each data set i is a single line, consisting of the sequence length mi and exactly mi integers which form the sequence. Numbers in data sets are separated by spaces.

Output

For each data set i print the shortest possible length of the prefix for which the sum of elements is equal to the sum of elements of the determined suffix. If desired number does not exist, then print 0. Answers for data sets should be separated by new lines.

Notes

The prefix and suffix cannot be empty.

Example

Input:
4
5 4 2 3 1 2
5 4 -2 1 1 -2
6 1 -1 1 -1 1 -1
3 0 0 0

Output:
2
0
2
1

 

Answer

#include 

int main(void) {
	int instances;
	scanf("%d", &instances);
	int n;
	int i;
	for(i = 0 ; i < instances ; i++){
		scanf("%d", &n);
		int entries[n];
		int j;
		for(j = 0 ; j < n ; j++){
			scanf("%d", &entries[j]);
		}
		int sumA[n-1];
    	int total = 0;
    	int k;
    	int flag1 =1;
    	for(k = 0 ; k <= n-2 ; k++){
    		if(entries[k] != entries[n-(k)]) // Check for palindrome
    		     flag1=0;
	    	total +=entries[k];
	    	sumA[k] = total;
    	}
    	if(flag1 == 1 && entries[n/2] == entries[(n/2)-1])
    	    return (n/2)-1;
    	
	    total +=entries[n-1];
	    int flag = 1;
        if(total%2 == 0){ // If it is odd it cannot be split
        	int j;
        	int tot2 = total/2;
	    	for(j = 0 ; j <= n-2 ; j++){
		      if(sumA[j] == tot2){
		         printf("%d\n", j+1);
		         flag = 0;
		         break;
		      }
		    }
        }
       if(flag ==1)
          printf("0\n");
	}
	return 0;
}

CodingChillout.Malta: Warm-up Session

Warm-Up round at Codingchillout.Malta http://codechillout.sphere-contest.com/round/test

http://codechillout.sphere-contest.com/problems/test/TEST

TEST

Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely… rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.

Example

Input:
1
2
88
42
99

Output:
1
2
88

Answer

#include 

int main(void) {
	int i;
	while (scanf("%d", &i)==1){
		if(i == 42) break;
		printf("%d\n",i);
	}

	return 0;
}

http://codechillout.sphere-contest.com/problems/test/FCTRL2

Small factorials

You are asked to calculate factorials of some small positive integers.

Input

An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.

Output

For each integer n given at input, display a line with the value of n! (“n factorial”).

Example

Sample input:

4
1
2
5
3

Sample output:

1
2
120
6

Answer

import math

n = int(raw_input());
for v in range(0,n):
	print math.factorial(int(raw_input()))

http://codechillout.sphere-contest.com/problems/test/ADDTWO

Add two number

Calculate the sum a+b for given integers a and b.

Input

There will be provided certain number of data sets for the problem. Each data set consist of two integer numbers ai and bi separated with a space, where i is the number of the data set. Data sets are separated with a new line.

Output

For ith data set print the value of ai + bi. Answers should be separated with a new line.

Example

Input:
2 3
10 -2
-1 5
-3 -3
0 1

Output:
5
8
4
-6
1

Answer

import fileinput

for line in fileinput.input():
    n = line.split();
    print int(n[0]) + int(n[1])

http://codechillout.sphere-contest.com/problems/test/REVARR

Reverse array

For a given array reverse its order.

Input

In the first line there will be a number of the data sets t. In the next t lines data sets follows. Each data set is a line of numbers separated by spaces. First number ni is the length of the array. Next ni numbers are the values in array.

Output

For ith data set write values from array in reversed order. Numbers should be separated by spaces and answers for data sets should be separated by a new line.

Example

Input:
2
7 1 2 3 4 5 6 7
3 3 2 11

Output:
7 6 5 4 3 2 1
11 2 3

Answer

n = int(raw_input())
for v in range(0,n):
    j = raw_input().split(" ")
    del j[0]
    j = " ".join(reversed(j))
    print j

CodingChillout.Malta: Gluttons

http://codechillout.sphere-contest.com/problems/onlineround/GLUTTONS

Gluttons

Every year Megabyteland hosts The Great Gluttony Festival. According to tradition, during the first day of the festival all participants eat cookies nonstop for 24 hours (with not even a fraction of a second’s break!). As soon as a glutton has finished eating one cookie, he immediately stars to eat the next one (this does not apply only to the situation at the end of the day, when the participant is not allowed to start eating a cookie if he knows that he cannot finish eating it before the end of the day). Another important part of the tradition is that each glutton eats a single cookie at his very own constant characteristic pace.

For the coming festival, the organizers have invited only those gluttons who have already participated in the previous editions. This means that the pace of each glutton is already known (they don’t really like to change their natural pace). Based on this data, the organizers of the festival want to determine how many cookies they need to buy. However, the cookies in the shop are sold in boxes of fixed size, thus they may have to buy more cookies than the number that is going to be eaten.

Your task is to establish the number of boxes with cookies that are needed to carry out the competition. The number of participants, along with the pace of each of them (given in seconds needed to eat a single cookie) will be given.

Input

The first line of input contains the number of test cases t. Each test case has the following form: two numbers N and M, separated by a space, in the first line (1 ≤ N ≤ 10000, 1 ≤ M ≤ 1000000000). The first number N is the number of invited gluttons and the second number M is the numbers of cookies in the box. Each line of the next N lines contains a single integer number, representing the pace of the glutton. The pace of the glutton is expressed as the number of seconds (not greater than 100000) needed to eat a single cookie.

Output

For each test case you need to write exactly one integer denoting the number of boxes which have to be bought by the organizers to carry out the contest. Answers for distinct test cases should be written in separate lines.

Example

Input:
2
2 10
3600
1800
3 356
123
32999
10101

Output:
8
2

Answers

C

#include 
#include 
int main(void) {
	int n;
	int invites;
	int nBox;
	int i;
	scanf("%d", &n);
	for(i = 0 ; i < n ; i++){
		scanf("%d %d", &invites,&nBox);
	    double total = 0;
		int j;
		for(j = 0 ; j < invites;j++){
			    int time;
			    scanf("%d",&time);
		    	total += 86400/time;
        }
        printf("%d\n",(int)ceil(total/nBox));
	}
	return 0;

Python 2.7

import math
contestDuration = 86400
instances = int(raw_input())
for v in range(0,instances):
    data = raw_input().split(" ") # Invited/Cookies
    i = int(data[0])
    cookies = int(data[1])
    total = 0
    for k in range(0,i):
       total = total + contestDuration/int(raw_input())
    print int(math.ceil(total/cookies))

Java 7

import java.util.*;
import java.lang.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		 java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
		 int instances = Integer.parseInt(r.readLine());
		 
		 for(int k = 0 ; k < instances; k++){
		    String [] data = r.readLine().split("\\s+");
		    int invites = Integer.parseInt(data[0]);
		    double total = 0;
		    for(int i = 0 ; i < invites; i++){
		    	total += 86400/Integer.parseInt(r.readLine());
		 
		    }
		    System.out.println((int)Math.ceil(total/Integer.parseInt(data[1])));
		 }
	}
}

A short story of a Developer Challenge

Yesterday I came across https://www.konnekt.com/Challenge/Developer and I decided to give it a go

konnekt

Firebug was used to check for hidden elements and the pesky display:none;  was removed

firebug

… and the following text appeared

Capture

So there must be a GetKey function probably javascript and it was found

getkey

There are 5 rows and 32 columns. Make use of a [5,15][3, 8]S algorithm with mode ECB. Oh, and you will need a key, try GetKey with a certain binary parameter!

What is ECB? Electronic Code book and learned that it has to do with encryption.

Who would name an algorithm [5,15][3, 8]S ? Aha that must be some coordinates

Untitled

So [5,15][3, 8]S stands for DES. Then “There are 5 rows and 32 columns. Make use of a DES algorithm with mode ECB. Oh, and you will need a key, try GetKey with a certain binary parameter!”

Next is the key. It was staring at me in front of the elephant {01000111 01101111}

  1. function bin2txt(bin) {
  2. var res = bin.replace(/ /g,"").replace(/[01]{8}/g, function(v) {
  3. return String.fromCharCode( parseInt(v,2) );
  4. });
  5. return res;
  6. }

funnily enough when you convert this to string it becomes “Go” to complete Ready Set Go.

But when passed as a parameter to Getkey the word “origami” pops out

Other methods of finding the key in GetKey function the list

  1. var asciiToUse = [111, 114, 105, 103, 97, 109, 105]

is the ascii of  “origami” in order

Since my knowledge of DES is next to none, I thought I must convert it to hex and was trying all sorts of website encrypter/decrypters At some point I also thought that “origami elephant” is the key in hex 🙂

Then I found http://des.online-domain-tools.com/tool-form-submit/

I pasted the encrypted text and entered origami as key

result

The result was: https://www.konnekt.com/Challenge/Developer/58fb1b4f9ac643cfa5fbsbb7def6eb29

win

Other curious things

https://www.konnekt.com/Blog/News/52/Developer-Challenge

Give it a try. We’re warning you, it’s {01100100 01100001 01101101 01101110 00100000 01100101 01100001 01110011 01111001}.
bintotext the binary results in “damn easy”

Tools used

JSFIDDLE http://jsfiddle.net/fairmutex/fGHeG/1/

http://des.online-domain-tools.com/tool-form-submit/

 

GetKey description

This function checks if the binary represents the string “Go” in unrelated ways like using  Math.sqrt(5041) which is 71 which is the ascii of “G” and  110.91935  and ceil  to get 111 which is the ascii of “o” and then lists the string “origami” if the string criteria is satisfied.

Thanks for reading

Javascript Pre-Init equivalent

var treeData = [
{title: “item1 with key and tooltip”, tooltip: “Look, a tool tip!” },
{title: “item2: selected on init”, select: true },
{title: “Folder”, isFolder: true, key: “id3”,
children: [
{title: “Sub-item 3.1”,
children: [
{title: “Sub-item 3.1.1”, key: “id3.1.1” },
{title: “Sub-item 3.1.2”, key: “id3.1.2” }
]
},
{title: “Sub-item 3.2”,
children: [
{title: “Sub-item 3.2.1”, key: “id3.2.1” },
{title: “Sub-item 3.2.2”, key: “id3.2.2” }
]
}
]
},
{title: “Document with some children (expanded on init)”, key: “id4”, expand: true,
children: [
{title: “Sub-item 4.1 (active on init)”, activate: true,
children: [
{title: “Sub-item 4.1.1”, key: “id4.1.1” },
{title: “Sub-item 4.1.2”, key: “id4.1.2” }
]
},
{title: “Sub-item 4.2 (selected on init)”, select: true,
children: [
{title: “Sub-item 4.2.1”, key: “id4.2.1” },
{title: “Sub-item 4.2.2”, key: “id4.2.2” }
]
},
{title: “Sub-item 4.3 (hideCheckbox)” },
{title: “Sub-item 4.4 (unselectable)” }
]
}
];

 
var tryTree = [{}];
tryTree[0] = {};
tryTree[0].title = “item1 with key and tooltip”;
tryTree[0].tooltip = “Look, a tool tip!”;

tryTree[1] = {};
tryTree[1].title = “item2: selected on init”;
tryTree[1].select = true;

tryTree[2] = {};
tryTree[2].title = “Folder”;
tryTree[2].isFolder = true;
tryTree[2].key = “id3”;
tryTree[2].children = [{}];
tryTree[2].children[0] = {};
tryTree[2].children[0].title = “Sub-item 3.1”;
tryTree[2].children[0].children = [{}];
tryTree[2].children[0].children[0] = {};
tryTree[2].children[0].children[0].title = “Sub-item 3.1.1”;
tryTree[2].children[0].children[0].key = “id3.1.1”;
tryTree[2].children[0].children[1] = {};
tryTree[2].children[0].children[1].title = “Sub-item 3.1.2”;
tryTree[2].children[0].children[1].key = “id3.1.2”;
tryTree[2].children[1] = {};
tryTree[2].children[1].title = “Sub-item 3.2”;
tryTree[2].children[1].children = [{}];
tryTree[2].children[1].children[0] = {};
tryTree[2].children[1].children[0].title = “Sub-item 3.2.1”;
tryTree[2].children[1].children[0].key = “id3.2.1”;
tryTree[2].children[1].children[1] = {};
tryTree[2].children[1].children[1].title = “Sub-item 3.2.2”;
tryTree[2].children[1].children[1].key = “id3.2.2”;

tryTree[3] = {};
tryTree[3].title = “Document with some children (expanded on init)”;
tryTree[3].expand = true;
tryTree[3].key = “id3”;

tryTree[3].children = [{}];
tryTree[3].children[0] = {};
tryTree[3].children[0].title = “Sub-item 4.1 (active on init)”;
tryTree[3].children[0].activate = true;
tryTree[3].children[0].children = [{}];
tryTree[3].children[0].children[0] = {};
tryTree[3].children[0].children[0].title = “Sub-item 4.1.1”;
tryTree[3].children[0].children[0].key = “id4.1.1”;
tryTree[3].children[0].children[1] = {};
tryTree[3].children[0].children[1].title = “Sub-item 4.1.2”;
tryTree[3].children[0].children[1].key = “id4.1.2”;

tryTree[3].children[1] = {};
tryTree[3].children[1].title = “Sub-item 4.2 (selected on init)”;
tryTree[3].children[1].select = true;
tryTree[3].children[1].children = [{}];
tryTree[3].children[1].children[0] = {};
tryTree[3].children[1].children[0].title = “Sub-item 4.2.1”;
tryTree[3].children[1].children[0].key = “id4.2.1”;
tryTree[3].children[1].children[1] = {};
tryTree[3].children[1].children[1].title = “Sub-item 4.2.2”;
tryTree[3].children[1].children[1].key = “id4.2.2”;

tryTree[3].children[2] = {};
tryTree[3].children[2].title = “Sub-item 4.3 (hideCheckbox)”;

tryTree[3].children[3] = {};
tryTree[3].children[3].title = “Sub-item 4.4 (unselectable)”;

 

 

 

Tested with

//called with every property and it’s value
function process(key,value) {
document.write(key + ” : “+value+'<br/>’);
}

function traverse(o,func) {
for (i in o) {
func.apply(this,[i,o[i]]);
if (typeof(o[i])==”object”) {
//going on step down in the object tree!!
traverse(o[i],func);
}
}
}

//that’s all… no magic, no bloated framework
document.write(‘<br/><br/><br/><br/><br/><br/><br/><br/><table><tr><td>’);
traverse(treeData,process);
document.write(‘</td><td>’);
traverse(tryTree,process);
document.write(‘</td></tr></table>’);