From 80fe5ec8fe385eb5e84b060ef31f7f140b55fb83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Mu=CC=88ller?= Date: Fri, 25 May 2018 00:20:59 +0200 Subject: [PATCH 1/7] One possible solution. --- HeatWaves/CharacterCount.txt | 2 +- HeatWaves/HeatWaves.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HeatWaves/CharacterCount.txt b/HeatWaves/CharacterCount.txt index f837576..d117d77 100644 --- a/HeatWaves/CharacterCount.txt +++ b/HeatWaves/CharacterCount.txt @@ -1 +1 @@ -12 bytes. +74 bytes. diff --git a/HeatWaves/HeatWaves.swift b/HeatWaves/HeatWaves.swift index b32c34e..c4c0b13 100644 --- a/HeatWaves/HeatWaves.swift +++ b/HeatWaves/HeatWaves.swift @@ -26,5 +26,5 @@ // // The shortest answer in bytes wins. public func isHeatWaveIncludedIn(waves w: [Int]) -> Bool { - return false + return w.split{$0<25}.filter{$0.count>4&&$0.filter{$0>29}.count>2}.count>0 } From 06c0f7d52853068140c838e05c37f29270fa605c Mon Sep 17 00:00:00 2001 From: Sven Titgemeyer Date: Fri, 25 May 2018 00:43:15 +0200 Subject: [PATCH 2/7] Saved two more bytes. --- HeatWaves/CharacterCount.txt | 2 +- HeatWaves/HeatWaves.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HeatWaves/CharacterCount.txt b/HeatWaves/CharacterCount.txt index d117d77..d8a2710 100644 --- a/HeatWaves/CharacterCount.txt +++ b/HeatWaves/CharacterCount.txt @@ -1 +1 @@ -74 bytes. +72 bytes. diff --git a/HeatWaves/HeatWaves.swift b/HeatWaves/HeatWaves.swift index c4c0b13..d965f83 100644 --- a/HeatWaves/HeatWaves.swift +++ b/HeatWaves/HeatWaves.swift @@ -26,5 +26,5 @@ // // The shortest answer in bytes wins. public func isHeatWaveIncludedIn(waves w: [Int]) -> Bool { - return w.split{$0<25}.filter{$0.count>4&&$0.filter{$0>29}.count>2}.count>0 + return w.split{$0<25}.filter{$0.count>4&&$0.filter{$0>29}.count>2} != [] } From b12ed9430eb6cc26e2b420f872cf98ebd8b83caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Mu=CC=88ller?= Date: Sat, 26 May 2018 20:12:23 +0200 Subject: [PATCH 3/7] Inspired by Udo, optimized Rolands version. --- HeatWaves/CharacterCount.txt | 2 +- HeatWaves/HeatWaves.swift | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/HeatWaves/CharacterCount.txt b/HeatWaves/CharacterCount.txt index d8a2710..737afa2 100644 --- a/HeatWaves/CharacterCount.txt +++ b/HeatWaves/CharacterCount.txt @@ -1 +1 @@ -72 bytes. +60 bytes. diff --git a/HeatWaves/HeatWaves.swift b/HeatWaves/HeatWaves.swift index d965f83..2cf7a5d 100644 --- a/HeatWaves/HeatWaves.swift +++ b/HeatWaves/HeatWaves.swift @@ -26,5 +26,6 @@ // // The shortest answer in bytes wins. public func isHeatWaveIncludedIn(waves w: [Int]) -> Bool { - return w.split{$0<25}.filter{$0.count>4&&$0.filter{$0>29}.count>2} != [] + return w.reduce(1){$1<25 ?($0<1 ?0:1):$0*($1<30 ?2:6)%864}<1 } + From 4d96e7ab7fb0e990fb3e5c487487fe83e44ee0e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Mu=CC=88ller?= Date: Sat, 26 May 2018 20:36:57 +0200 Subject: [PATCH 4/7] Using closures. Closures allow for an even shorter notation because of automatic returns and referencing parameters by $0, $1, and so on. --- HeatWaves/CharacterCount.txt | 2 +- HeatWaves/HeatWaves.swift | 4 +-- HeatWavesTests/HeatWavesTests.swift | 48 ++++++++++++++--------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/HeatWaves/CharacterCount.txt b/HeatWaves/CharacterCount.txt index 737afa2..38c559e 100644 --- a/HeatWaves/CharacterCount.txt +++ b/HeatWaves/CharacterCount.txt @@ -1 +1 @@ -60 bytes. +54 bytes. diff --git a/HeatWaves/HeatWaves.swift b/HeatWaves/HeatWaves.swift index 2cf7a5d..7ec15c5 100644 --- a/HeatWaves/HeatWaves.swift +++ b/HeatWaves/HeatWaves.swift @@ -25,7 +25,7 @@ // wave (as per the above definition). // // The shortest answer in bytes wins. -public func isHeatWaveIncludedIn(waves w: [Int]) -> Bool { - return w.reduce(1){$1<25 ?($0<1 ?0:1):$0*($1<30 ?2:6)%864}<1 +public var isHeatWaveIncludedIn:([Int])->Bool = { + $0.reduce(1){$1<25 ?($0<1 ?0:1):$0*($1<30 ?2:6)%864}<1 } diff --git a/HeatWavesTests/HeatWavesTests.swift b/HeatWavesTests/HeatWavesTests.swift index 2aa327f..99c9dbf 100644 --- a/HeatWavesTests/HeatWavesTests.swift +++ b/HeatWavesTests/HeatWavesTests.swift @@ -38,98 +38,98 @@ class HeatWavesTests: XCTestCase { [25, 20, 30, 29, 32, 25, 22, 21, 31, 22, 23, 25, 22, 31, 23, 25, 33, 23]] func testPositive0() { - XCTAssertTrue(isHeatWaveIncludedIn(waves: positiveExamples[0])) + XCTAssertTrue(isHeatWaveIncludedIn(positiveExamples[0])) } func testPositive1() { - XCTAssertTrue(isHeatWaveIncludedIn(waves: positiveExamples[1])) + XCTAssertTrue(isHeatWaveIncludedIn(positiveExamples[1])) } func testPositive2() { - XCTAssertTrue(isHeatWaveIncludedIn(waves: positiveExamples[2])) + XCTAssertTrue(isHeatWaveIncludedIn(positiveExamples[2])) } func testPositive3() { - XCTAssertTrue(isHeatWaveIncludedIn(waves: positiveExamples[3])) + XCTAssertTrue(isHeatWaveIncludedIn(positiveExamples[3])) } func testPositive4() { - XCTAssertTrue(isHeatWaveIncludedIn(waves: positiveExamples[4])) + XCTAssertTrue(isHeatWaveIncludedIn(positiveExamples[4])) } func testPositive5() { - XCTAssertTrue(isHeatWaveIncludedIn(waves: positiveExamples[5])) + XCTAssertTrue(isHeatWaveIncludedIn(positiveExamples[5])) } func testPositive6() { - XCTAssertTrue(isHeatWaveIncludedIn(waves: positiveExamples[6])) + XCTAssertTrue(isHeatWaveIncludedIn(positiveExamples[6])) } func testPositive7() { - XCTAssertTrue(isHeatWaveIncludedIn(waves: positiveExamples[7])) + XCTAssertTrue(isHeatWaveIncludedIn(positiveExamples[7])) } func testPositive8() { - XCTAssertTrue(isHeatWaveIncludedIn(waves: positiveExamples[8])) + XCTAssertTrue(isHeatWaveIncludedIn(positiveExamples[8])) } func testPositive9() { - XCTAssertTrue(isHeatWaveIncludedIn(waves: positiveExamples[9])) + XCTAssertTrue(isHeatWaveIncludedIn(positiveExamples[9])) } func testPositive10() { - XCTAssertTrue(isHeatWaveIncludedIn(waves: positiveExamples[10])) + XCTAssertTrue(isHeatWaveIncludedIn(positiveExamples[10])) } func testPositive11() { - XCTAssertTrue(isHeatWaveIncludedIn(waves: positiveExamples[11])) + XCTAssertTrue(isHeatWaveIncludedIn(positiveExamples[11])) } func testNegative0() { - XCTAssertFalse(isHeatWaveIncludedIn(waves: negativeExamples[0])) + XCTAssertFalse(isHeatWaveIncludedIn(negativeExamples[0])) } func testNegative1() { - XCTAssertFalse(isHeatWaveIncludedIn(waves: negativeExamples[1])) + XCTAssertFalse(isHeatWaveIncludedIn(negativeExamples[1])) } func testNegative2() { - XCTAssertFalse(isHeatWaveIncludedIn(waves: negativeExamples[2])) + XCTAssertFalse(isHeatWaveIncludedIn(negativeExamples[2])) } func testNegative3() { - XCTAssertFalse(isHeatWaveIncludedIn(waves: negativeExamples[3])) + XCTAssertFalse(isHeatWaveIncludedIn(negativeExamples[3])) } func testNegative4() { - XCTAssertFalse(isHeatWaveIncludedIn(waves: negativeExamples[4])) + XCTAssertFalse(isHeatWaveIncludedIn(negativeExamples[4])) } func testNegative5() { - XCTAssertFalse(isHeatWaveIncludedIn(waves: negativeExamples[5])) + XCTAssertFalse(isHeatWaveIncludedIn(negativeExamples[5])) } func testNegative6() { - XCTAssertFalse(isHeatWaveIncludedIn(waves: negativeExamples[6])) + XCTAssertFalse(isHeatWaveIncludedIn(negativeExamples[6])) } func testNegative7() { - XCTAssertFalse(isHeatWaveIncludedIn(waves: negativeExamples[7])) + XCTAssertFalse(isHeatWaveIncludedIn(negativeExamples[7])) } func testNegative8() { - XCTAssertFalse(isHeatWaveIncludedIn(waves: negativeExamples[8])) + XCTAssertFalse(isHeatWaveIncludedIn(negativeExamples[8])) } func testNegative9() { - XCTAssertFalse(isHeatWaveIncludedIn(waves: negativeExamples[9])) + XCTAssertFalse(isHeatWaveIncludedIn(negativeExamples[9])) } func testNegative10() { - XCTAssertFalse(isHeatWaveIncludedIn(waves: negativeExamples[10])) + XCTAssertFalse(isHeatWaveIncludedIn(negativeExamples[10])) } func testNegative11() { - XCTAssertFalse(isHeatWaveIncludedIn(waves: negativeExamples[11])) + XCTAssertFalse(isHeatWaveIncludedIn(negativeExamples[11])) } } From 66e2dfc2687024d3b1e35f67a6fcd688dec22ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Mu=CC=88ller?= Date: Sat, 26 May 2018 20:47:15 +0200 Subject: [PATCH 5/7] Deleted two superfluous parantheses. --- HeatWaves/CharacterCount.txt | 2 +- HeatWaves/HeatWaves.swift | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/HeatWaves/CharacterCount.txt b/HeatWaves/CharacterCount.txt index 38c559e..02ac62d 100644 --- a/HeatWaves/CharacterCount.txt +++ b/HeatWaves/CharacterCount.txt @@ -1 +1 @@ -54 bytes. +52 bytes. diff --git a/HeatWaves/HeatWaves.swift b/HeatWaves/HeatWaves.swift index 7ec15c5..bdc98f2 100644 --- a/HeatWaves/HeatWaves.swift +++ b/HeatWaves/HeatWaves.swift @@ -26,6 +26,5 @@ // // The shortest answer in bytes wins. public var isHeatWaveIncludedIn:([Int])->Bool = { - $0.reduce(1){$1<25 ?($0<1 ?0:1):$0*($1<30 ?2:6)%864}<1 + $0.reduce(1){$1<25 ?$0<1 ?0:1:$0*($1<30 ?2:6)%864}<1 } - From 5d712eda138b1f0208c83464d5a8d4c6fd05cd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Mu=CC=88ller?= Date: Sun, 27 May 2018 00:48:44 +0200 Subject: [PATCH 6/7] =?UTF-8?q?Added=20Roland=E2=80=99s=20idea=20to=20remo?= =?UTF-8?q?ve=20a=20=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One less ternary conditional operator --- HeatWaves/CharacterCount.txt | 2 +- HeatWaves/HeatWaves.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HeatWaves/CharacterCount.txt b/HeatWaves/CharacterCount.txt index 02ac62d..0ad7331 100644 --- a/HeatWaves/CharacterCount.txt +++ b/HeatWaves/CharacterCount.txt @@ -1 +1 @@ -52 bytes. +50 bytes. diff --git a/HeatWaves/HeatWaves.swift b/HeatWaves/HeatWaves.swift index bdc98f2..a986f0d 100644 --- a/HeatWaves/HeatWaves.swift +++ b/HeatWaves/HeatWaves.swift @@ -26,5 +26,5 @@ // // The shortest answer in bytes wins. public var isHeatWaveIncludedIn:([Int])->Bool = { - $0.reduce(1){$1<25 ?$0<1 ?0:1:$0*($1<30 ?2:6)%864}<1 + $0.reduce(1){$0>0&&$1<25 ?1:$0*($1<30 ?2:6)%864}<1 } From e89b25348d915bc6cb3ea151e27842128765b94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Mu=CC=88ller?= Date: Sun, 27 May 2018 01:18:45 +0200 Subject: [PATCH 7/7] Smaller prime factors --- HeatWaves/HeatWaves.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HeatWaves/HeatWaves.swift b/HeatWaves/HeatWaves.swift index a986f0d..3067502 100644 --- a/HeatWaves/HeatWaves.swift +++ b/HeatWaves/HeatWaves.swift @@ -26,5 +26,5 @@ // // The shortest answer in bytes wins. public var isHeatWaveIncludedIn:([Int])->Bool = { - $0.reduce(1){$0>0&&$1<25 ?1:$0*($1<30 ?2:6)%864}<1 + $0.reduce(1){$0>0&&$1<25 ?1:$0*($1<30 ?2:3)%108}<1 }