Skip to content

Instantly share code, notes, and snippets.

View reinder42's full-sized avatar

Reinder de Vries reinder42

View GitHub Profile
@reinder42
reinder42 / ListResource.java
Last active May 25, 2023 09:26
Data retourneren met Jackson
package week4.college7.bigshopper.shopping.webservices;
import week4.college7.bigshopper.shopping.helpers.SimpleShoppingListResponse;
import week4.college7.bigshopper.shopping.model.Shop;
import week4.college7.bigshopper.shopping.model.ShoppingList;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
{
"uid": 42,
"username": "reinder42",
"name": "Reinder de Vries",
"likes": 999,
"location": "Netherlands",
"job": "iOS dev"
}
[
{
"id": 1,
"title": "Blade Runner",
"year": 1982
}, {
"id": 2,
"title": "Tron",
"year": 1982
}, {
[
{
"id": 1,
"title": "Nineteen Eighty-Four: A Novel",
"author": "George Orwell"
}, {
"id": 2,
"title": "Animal Farm",
"author": "George Orwell"
}, {
[
{
"first_name": "Ford",
"last_name": "Prefect",
"age": 5000
},
{
"first_name": "Zaphod",
"last_name": "Beeblebrox",
"age": 999
@reinder42
reinder42 / hipsum.swift
Created May 11, 2019 13:52
Generate a string of random words
// Generates a random string of words
// Words courtesy of hipsum.co
import Foundation
func hipsum(_ count:Int = 8) -> String
{
// Split words and shuffle
var words = "Lorem ipsum dolor amet pinterest waistcoat live-edge kogi salvia umami tumblr YOLO organic vice fixie twee vinyl wolf gentrify hammock green juice pitchfork neutra YOLO cred art party pitchfork vegan tousled organic tilde drinking vinegar master cleanse chambray forage literally offal listicle food truck beard four dollar toast ethical pug DIY reindeer VHS salvia squid franzen echo park literally ugh godard thundercats next level pop-up keytar kogi truffaut hell of street art occupy prism tbh gentrify asymmetrical forage mustache plaid kitsch unicorn sriracha poutine photo booth roof party".split(separator: " ").shuffled()

Can you change the Add 1 game to include the number 9? Yes you can!

Original video (part 1) · Original tutorial

The game initially calculates whether a given input is OK by subtracting the input from the given numbers, and if the result is 1111, the input is correct. This is based on the idea that the difference between two sequences 0000-8888 is 1111 if you added 1 to each of the given numbers. This rules out the number 9 from the game, though!

Adding number 9 back into the game is fairly simple:

  1. First, we need to determine that, given we're working with single digits, 9 plus one = 0. So, the user needs to input 0 to add one to a 9.
  2. Then, we'll iterate over the digits of the input and the given number, and check that the difference between them is 1. This will go wrong when comparing 9 and 0, so we'll write an exception for that.