Решение на Разлика в сумите от Станислав Траилов

Обратно към всички решения

Към профила на Станислав Траилов

Резултати

  • 7 точки от тестове
  • 0 бонус точки
  • 7 точки общо
  • 10 успешни тест(а)
  • 5 неуспешни тест(а)

Код

package main
func ExtractColumn(logContents string, column uint8) string {
if logContents == `` {
return ``
}
if logContents == "\n" {
return ``
}
var start, end int
var output string
for i := range logContents {
if logContents[i] == '\n' {
end = i
output += ExtractColumnHelp(logContents[start:end], column)
if len(logContents[i+1:]) != 0 {
output += "\n"
}
start = i + 1
}
}
return output + "\n"
}
func ExtractColumnHelp(logLine string, column uint8) string {
var a, b int
switch {
case column == 0:
a = 0
b = 19
case column == 1:
a = 20
for i := 22; i <= len(logLine); i++ {
if logLine[i] == ' ' {
b = i
break
}
}
case column == 2:
var count int = 0
for i := 0; i <= len(logLine); i++ {
if logLine[i] == ' ' {
count = count + 1
if count == 3 {
a = i + 1
break
}
}
}
b = len(logLine)
}
return logLine[a:b]
}

Лог от изпълнението

PASS
ok  	_/tmp/d20151103-24541-1z2mjz	0.003s
PASS
ok  	_/tmp/d20151103-24541-1z2mjz	0.005s
PASS
ok  	_/tmp/d20151103-24541-1z2mjz	0.003s
PASS
ok  	_/tmp/d20151103-24541-1z2mjz	0.003s
--- FAIL: TestSpacesAtTheStartOrEndOfALine (0.00s)
	solution_test.go:260: Expected
		---
		2015-08-23 12:37:03
		2015-08-23 12:37:04
		2015-08-23 12:37:05
		2015-08-22 12:37:06
		0001-01-01 00:00:00
		
		---
		but found
		---
		2015-08-23 12:37:03
		2015-08-23 12:37:04
		2015-08-23 12:37:05
		2015-08-22 12:37:06
		
		
		---
	solution_test.go:260: Expected
		---
		8.8.8.8
		8.8.4.4
		208.122.23.23
		208.122.244.221
		255.255.255.255
		
		---
		but found
		---
		8.8.8.8
		8.8.4.4
		208.122.23.23
		208.122.244.221
		
		
		---
	solution_test.go:260: Expected
		---
		As far as we can tell this is a DNS
		Yet another DNS, how quaint!
		There is definitely some trend here
		 Some spaces at the beginning of this line
		Nothing particularly interesting happened 
		
		---
		but found
		---
		As far as we can tell this is a DNS
		Yet another DNS, how quaint!
		There is definitely some trend here
		 Some spaces at the beginning of this line
		
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1z2mjz	0.003s
--- FAIL: TestNoNewLineAtEndOfInput (0.00s)
	solution_test.go:260: Expected
		---
		As far as we can tell this is a DNS
		There is definitely some trend here
		
		---
		but found
		---
		As far as we can tell this is a DNS
		
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1z2mjz	0.003s
PASS
ok  	_/tmp/d20151103-24541-1z2mjz	0.003s
PASS
ok  	_/tmp/d20151103-24541-1z2mjz	0.003s
PASS
ok  	_/tmp/d20151103-24541-1z2mjz	0.003s
PASS
ok  	_/tmp/d20151103-24541-1z2mjz	0.003s
PASS
ok  	_/tmp/d20151103-24541-1z2mjz	0.003s
--- FAIL: TestLogDoesNotEndInNewLine (0.00s)
	solution_test.go:260: Expected
		---
		8.8.8.8
		8.8.4.4
		208.122.23.23
		
		---
		but found
		---
		8.8.8.8
		8.8.4.4
		
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1z2mjz	0.003s
--- FAIL: TestLogLogLineEndsInIP (0.00s)
	solution_test.go:260: Expected
		---
		8.8.8.8
		8.8.4.4
		208.122.23.23
		
		---
		but found
		---
		8.8.8.8
		8.8.4.4
		
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1z2mjz	0.003s
--- FAIL: TestWithSpaces (0.00s)
	solution_test.go:260: Expected
		---
		spaces   tabs		end
		
		---
		but found
		---
		
		
		---
FAIL
exit status 1
FAIL	_/tmp/d20151103-24541-1z2mjz	0.003s
PASS
ok  	_/tmp/d20151103-24541-1z2mjz	0.003s

История (2 версии и 4 коментара)

Станислав обнови решението на 25.10.2015 00:10 (преди над 2 години)

+package main
+
+func ExtractColumn(logContents string, column uint8) string {
+ var start, end int
+ var output string
+ for i := range logContents {
+ if logContents[i] == '\n' {
+ end = i
+ output += ExtractColumnHelp(logContents[start:end], column)
+ start = i + 1
+ }
+ }
+ return output
+}
+
+func ExtractColumnHelp(logLine string, column uint8) string {
+ var a, b int
+ switch {
+ case column == 0:
+ a = 0
+ b = 19
+ case column == 1:
+ a = 20
+ for i := 22; i <= len(logLine); i++ {
+ if logLine[i] == ' ' {
+ b = i
+ break
+ }
+ }
+ case column == 2:
+ var count int = 0
+ for i := 0; i <= len(logLine); i++ {
+ if logLine[i] == ' ' {
+ count = count + 1
+ if count == 3 {
+ a = i + 1
+ break
+ }
+ }
+ }
+ b = len(logLine)
+ }
+
+ return logLine[a:b] + "\n"
+}

Станислав обнови решението на 31.10.2015 21:03 (преди над 2 години)

package main
func ExtractColumn(logContents string, column uint8) string {
+ if logContents == `` {
+ return ``
+ }
+ if logContents == "\n" {
+ return ``
+ }
var start, end int
var output string
for i := range logContents {
if logContents[i] == '\n' {
end = i
output += ExtractColumnHelp(logContents[start:end], column)
+ if len(logContents[i+1:]) != 0 {
+ output += "\n"
+ }
start = i + 1
}
}
- return output
+ return output + "\n"
}
func ExtractColumnHelp(logLine string, column uint8) string {
var a, b int
switch {
case column == 0:
a = 0
b = 19
case column == 1:
a = 20
for i := 22; i <= len(logLine); i++ {
if logLine[i] == ' ' {
b = i
break
}
}
case column == 2:
var count int = 0
for i := 0; i <= len(logLine); i++ {
if logLine[i] == ' ' {
count = count + 1
if count == 3 {
a = i + 1
break
}
}
}
b = len(logLine)
}
- return logLine[a:b] + "\n"
+ return logLine[a:b]
}