Monday, 27 June 2016

Challenge #272 [Easy] What's in the bag?

Another day another challenge, I need to program a lot more as at the moment all I have been doing is studying for the OCP exam, it is harder than I had anticipated with all the functional programming. As I had thought it would be similar to linq, perhaps the understanding was not there at the time. Either way I am not practicing enough and caught up in the what if I fail stuff.

User wins $10,000 due to botched forced Windows 10 upgrade.

Properly want an LED peggy board to make a flashing mooninite sign, it would change between Ignignokt and Err. 

YouTube 500 error that I actually experienced. 

500 error something went wrong with what appears to be a base 64 encoded string

And on to the challenge, I look it against the other examples on daily programmer, so I have a long way to go.

package com.company;

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Map<Character, Integer> fullBag = new HashMap<Character, Integer>() {{
   put('A', 9); put('B', 2); put('C', 2); put('D', 4); put('E', 12);
   put('F', 2); put('G', 3); put('H', 2); put('I', 9); put('J', 1);
   put('K', 1); put('L', 4); put('M', 2); put('N', 6); put('O', 8);
   put('P', 2); put('Q', 1); put('R', 6); put('S', 4); put('T', 6);
   put('U', 4); put('V', 2); put('W', 2); put('X', 1); put('Y', 2);
   put('Z', 1); put('_', 2);
        }};

        //String tilesToRemove = "PQAREIOURSTHGWIOAE_";
        String tilesToRemove = "LQTOONOEFFJZT";
        //String tilesToRemove = "AXHDRUIOR_XHJZUQEE";
        for (Character tile : tilesToRemove.toCharArray()) {
            if (fullBag.keySet().contains(tile)) {
                fullBag.put(tile, fullBag.get(tile) -1);
            }
        }

        boolean hasNegativeTiles = fullBag.values().stream().filter( x -> x < 0 ).limit(1).count() > 0;
        if (hasNegativeTiles) {
            List<Character> negativeTiles = new ArrayList<>();
            for (Character tile : fullBag.keySet()) {
                if (fullBag.get(tile) < 0) { negativeTiles.add(tile);}
            }
            System.out.println("Invalid input. More "
                    +  negativeTiles.toString().substring(1,  negativeTiles.toString().length()-1)
                    + " have been taken from the bag than possible.");
        } else {
            List<Character> charsNeeded;
            Map<Integer, List<Character>> filteredMap = 

              new HashMap<>();
            for (int i = 12; i >= 0; i-- ) {
                charsNeeded = new ArrayList<>();

                for (Character c : fullBag.keySet()) {
                    if (fullBag.get(c) == i) {
                        charsNeeded.add(c);
                    }
                }

                if (!charsNeeded.isEmpty()) {
                    filteredMap.put(i, charsNeeded);
                }
            }

            List<Integer> reversedList = new ArrayList<>(filteredMap.keySet());
            Collections.reverse(reversedList);
            for (Integer key : reversedList) {
                String collectionToPrint = filteredMap.get(key).toString();
                System.out.println(key + ":\t" + collectionToPrint.substring(1, collectionToPrint.length() -1));
            }
        }
    }
}

Monday, 13 June 2016

Passed Java OCA Programmer 1 1Z0-808!!!

Passed, it took a significant amount of work and hopefully I now have the confidence to build more of my own things. To avoid that I did a programming challenge. 

What did help on the exam is the enthuware tests, lots of unique questions with the tougher items having in depth descriptions. I liked the Jeanne Boyarsky and Scott Selikoff study guides, they do keep track of errata

Grey, white and red cover with the image of a light house for exam 1Z0-809

Having made a start, I am now thinking 3 months is optimistic if I am to include practice exams, jpassion, and other exam preparation. It is exciting as there are more interesting language features in the OCP exam, steams, lambdas, generics, and concurrency. They are a lot more fun than how many ways can the examiner confuse me with implicit type casting and chaining string methods.

I also need to keep my eye on the main goal of getting a job as a developer rather than just passing an exam, I have some ideas for my own projects.

There is a lot of doubt, as it is easy to give up where being a developer relies on patience, persistence, and methodical thought which if I am can get that down it would improve much more than my development career.

Pacman walk-through!

Challenge to transpose text, 

Dark coloured IDE showing solution and result of transpose




What I did notice from the solutions on reddit is that they are all different to each other including mine, although I do not agree with the solution using exceptions as program flow.

package com.company;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        String line, EOF = "-1";
        List<String> lines = new ArrayList<>();
        boolean hasNextLine;

        do {
            line = keyboard.nextLine();
            hasNextLine = !line.equals(EOF);
            if (hasNextLine) {
                lines.add(line);
            }
        } while (hasNextLine);

        int rows = 0;
        for (String aline : lines) { 

            if (rows < aline.length()) rows = aline.length(); 
        }
        int cols = lines.size();

        char[][] charGrid = new char[rows][cols];
        for (char[] row : charGrid) {
            for( int i = 0; i < row.length; i++) { row[i] = ' '; }
        }

        for ( int i = 0; i < lines.size(); i++) {
            for (int j = 0; j < lines.get(i).length(); j++) {
                charGrid[j][i] = lines.get(i).charAt(j);
            }
        }

        for (char[] lineOfChars : charGrid) {
            System.out.println(new String(
lineOfChars));
        }
    }
}

Monday, 6 June 2016

Dodge viper parked on my street!

low sports car dodge viper side view orange with black wheels

back of low sports car dodge viper black wheels orange body

And after the excitement I have booked my Java OCA exam for Thursday July 7th, from the mocks it is looking good, some concern over how useful they will be however I would like something / someone else to say hey look this guy can do something. I do have some small ideas for programs to help build up even a small portfolio. Then again might get called on invert a binary tree or something. 

Been having some minor issues with VLC player moving off screen and windows key left right would not move it alt + space, then m, arrow keys to move the window to where you want.

TedX how to learn anything the first 20 hours.
 
Seems a shame most java developers are only really using catch statements for debugging and logging although recovery can be complicated. 

Good discussion on hacker news around two factor authentication and google, to be fair it is a social attack that has happened.

Free book on building problem solvers, added to the reading pile.