Skip to content

Commit

Permalink
Fix for new nim version
Browse files Browse the repository at this point in the history
  • Loading branch information
def- committed Apr 8, 2018
1 parent d210b7c commit b91bf6f
Show file tree
Hide file tree
Showing 71 changed files with 127 additions and 121 deletions.
2 changes: 1 addition & 1 deletion amb.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import future, strutils
import sugar, strutils

proc amb(comp: proc(a, b: string): bool, options: seq[seq[string]],
prev: string = nil): seq[string] =
Expand Down
6 changes: 3 additions & 3 deletions asciialphabet.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(a: a, b: z)
(a: 'a', b: 'z')
true
false
{a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z}
{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
true
true
@[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]
@['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
k
8 changes: 4 additions & 4 deletions avg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ proc myReadLine(f: File, line: var TaintedString): bool =
setLen(line.string, 0)
result = true
while true:
if fgets(buf, 8192, f) == nil:
if fgets(cstring(addr buf), 8192, f) == nil:
result = false
break
let l = cstring(buf).len-1
let l = cstring(addr buf).len-1
if buf[l] == '\l':
buf[l] = '\0'
add(line, cstring(buf))
add(line, cstring(addr buf))
break
add(line, cstring(buf))
add(line, cstring(addr buf))

# compute average line length
var count = 0
Expand Down
2 changes: 1 addition & 1 deletion avglooplength.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ proc test(n, times: int): int =
while (bits and x) == 0:
inc result
bits = bits or x
x = 1 shl random(n)
x = 1 shl rand(n+1)

echo " n\tavg\texp.\tdiff"
echo "-------------------------------"
Expand Down
4 changes: 2 additions & 2 deletions break.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import random
randomize()

while true:
let a = random(20)
let a = rand(19)
echo a
if a == 10:
break
let b = random(20)
let b = rand(19)
echo b
4 changes: 2 additions & 2 deletions bullsandcows.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import random, strutils, rdstdin
randomize()

proc random(a: string): char = a[random(0..a.len)]
proc rand(a: string): char = a[rand(a.high)]

const
digits = "123456789"
Expand All @@ -11,7 +11,7 @@ var digitsSet: set[char] = {}
for d in digits: digitsSet.incl d

var chosen = newString(size)
for i in 0..chosen.high: chosen[i] = random(digits)
for i in 0..chosen.high: chosen[i] = rand(digits)

echo """I have chosen a number from $# unique digits from 1 to 9 arranged in a random order.
You need to input a $# digit, unique digit number as a guess at what I have chosen""".format(size, size)
Expand Down
2 changes: 1 addition & 1 deletion cholesky.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ proc cholesky[T](a: T): T =
result[i][j] = if i == j: sqrt(a[i][i]-s)
else: (1.0 / result[j][j] * (a[i][j] - s))

proc `$`(a: auto): string =
proc `$`[M, N](a: array[M, array[N, float]]): string =
result = ""
for b in a:
for c in b:
Expand Down
2 changes: 1 addition & 1 deletion combinationsrepetitions.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import future, sequtils
import sugar, sequtils

proc combsReps[T](lst: seq[T], k: int): seq[seq[T]] =
if k == 0:
Expand Down
2 changes: 1 addition & 1 deletion combinationsrepetitions.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@[@[iced, iced], @[iced, jam], @[iced, plain], @[jam, jam], @[jam, plain], @[plain, plain]]
@[@["iced", "iced"], @["iced", "jam"], @["iced", "plain"], @["jam", "jam"], @["jam", "plain"], @["plain", "plain"]]
220
2 changes: 1 addition & 1 deletion compose.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import future
import sugar

proc compose[A,B,C](f: A -> B, g: B -> C): A -> C = (x: A) => f(g(x))

Expand Down
4 changes: 2 additions & 2 deletions crc32.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ proc createCrcTable(): array[0..255, TCrc32] =
for i in 0..255:
var rem = TCrc32(i)
for j in 0..7:
if (rem and 1) > 0: rem = (rem shr 1) xor TCrc32(0xedb88320)
if (rem and 1) > 0'u32: rem = (rem shr 1) xor TCrc32(0xedb88320)
else: rem = rem shr 1
result[i] = rem

# Table created at compile time
const crc32table = createCrcTable()

proc updateCrc32(c: char, crc: var TCrc32) =
crc = (crc shr 8) xor crc32table[(crc and 0xff) xor ord(c)]
crc = (crc shr 8) xor crc32table[(crc and 0xff) xor uint32(ord(c))]

proc crc32*(s: string): TCrc32 =
result = InitCrc32
Expand Down
2 changes: 1 addition & 1 deletion curry.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import future, sequtils
import sugar, sequtils

proc fs[T1,T2](f: T1 -> T2, s: seq[T1]): seq[T2] = s.map f

Expand Down
2 changes: 1 addition & 1 deletion currying.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ proc addN[T](n: T): auto = (proc(x: T): T = x + n)
let add2 = addN(2)
echo add2(7)

import future
import sugar

proc addM[T](n: T): auto = (x: T) => x + n

Expand Down
2 changes: 1 addition & 1 deletion datemanipulation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import posix, times
var ts: Tm
discard "March 7 2009 7:30pm EST".strptime("%B %d %Y %I:%M%p %Z", ts)
ts.tmHour += 12
echo ts.mktime
echo fromUnix(ts.mktime.int64)
4 changes: 2 additions & 2 deletions dayoftheweek.nim
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import times

var timeinfo = getLocalTime getTime()
var timeinfo = getTime().local
timeinfo.monthday = 25
timeinfo.month = mDec
for year in 2008..2121:
timeinfo.year = year
if getLocalTime(toTime timeinfo).weekday == dSun:
if timeinfo.toTime.local.weekday == dSun:
stdout.write year," "
echo ""
2 changes: 1 addition & 1 deletion dealcards.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ proc randomGenerator(seed: int): iterator: int =
var seed = seed
return iterator: int =
while true:
seed = (seed.int64 * 214013 + 2531011) and int32.high
seed = int((seed.int64 * 214013 + 2531011) and int32.high)
yield seed shr 16

proc deal(seed: int): seq[int] =
Expand Down
6 changes: 3 additions & 3 deletions diningphilosophers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ var

proc run(p: Philosopher) {.thread.} =
while true:
sleep random 1 .. 10
sleep rand 1 .. 9
echo p.name, " is hungry."

acquire forks[min(p.forkLeft, p.forkRight)]
sleep random 1 .. 5
sleep rand 1 .. 4
acquire forks[max(p.forkLeft, p.forkRight)]

echo p.name, " starts eating."
sleep random 1 .. 10
sleep rand 1 .. 9

echo p.name, " finishes eating and leaves to think."

Expand Down
2 changes: 1 addition & 1 deletion drawcuboid.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ proc cline(n, x, y: int, cde: string) =
cde[0], cde[2..2].align y+1

proc cuboid(x, y, z: int) =
cline y+1, x, 0, "+-"
cline y+1, x, 0, "+- "
for i in 1..y: cline y-i+1, x, i-1, "/ |"
cline 0, x, y, "+-|"
for i in 0..4*z-y-3: cline 0, x, y, "| |"
Expand Down
6 changes: 3 additions & 3 deletions evolutionary.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ const
p = 0.05
c = 100

proc random(a: string): char = a[random(a.low..a.len)]
proc rand(a: string): char = a[rand(a.low..a.high)]

proc negFitness(trial: string): int =
for i in 0 ..< trial.len:
if target[i] != trial[i]: inc result

proc mutate(parent: string): string =
result = ""
for c in parent: result.add if random(1.0) < p: random(alphabet) else: c
for c in parent: result.add if rand(1.0) < p: rand(alphabet) else: c

var parent = ""
for i in 1..target.len: parent.add random(alphabet)
for i in 1..target.len: parent.add rand(alphabet)

var i = 0
while parent != target:
Expand Down
10 changes: 5 additions & 5 deletions fasta.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ proc myReadLine(f: File, line: var TaintedString): bool =
setLen(line.string, 0)
result = true
while true:
if fgets(buf, 8192, f) == nil:
if fgets(cstring(addr buf), 8192, f) == nil:
result = false
break
if buf[cstring(buf).len-1] == '\l':
buf[cstring(buf).len-1] = '\0'
add(line, cstring(buf))
if buf[cstring(addr buf).len-1] == '\l':
buf[cstring(addr buf).len-1] = '\0'
add(line, cstring(addr buf))
break
add(line, cstring(buf))
add(line, cstring(addr buf))

iterator fasta_pairs*(f: File): tuple[header: string, sequence: string] =
#var sequence = newStringOfCap(15_000_000) # If you know the approximate size beforehand
Expand Down
10 changes: 5 additions & 5 deletions fasta3.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ proc myReadLine(f: File, line: var TaintedString): bool =
setLen(line.string, 0)
result = true
while true:
if fgets(buf, 8192, f) == nil:
if fgets(cstring(addr buf), 8192, f) == nil:
result = false
break
if buf[cstring(buf).len-1] == '\l':
buf[cstring(buf).len-1] = '\0'
add(line, cstring(buf))
if buf[cstring(addr buf).len-1] == '\l':
buf[cstring(addr buf).len-1] = '\0'
add(line, cstring(addr buf))
break
add(line, cstring(buf))
add(line, cstring(addr buf))

proc handleFasta(header, sequence: string) =
echo header.len, " ", sequence.len
Expand Down
4 changes: 2 additions & 2 deletions fiveweekends.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import times

const LongMonths = {mJan, mMar, mMay, mJul, mAug, mOct, mDec}

var timeinfo = getLocalTime getTime()
var timeinfo = getTime().local
timeinfo.monthday = 1

var sumNone = 0
Expand All @@ -11,7 +11,7 @@ for year in 1900..2100:
for month in LongMonths:
timeinfo.year = year
timeinfo.month = month
if getLocalTime(toTime timeinfo).weekday == dFri:
if timeinfo.toTime.local.weekday == dFri:
echo month," ",year
none = false
if none: inc sumNone
Expand Down
2 changes: 1 addition & 1 deletion forestfire.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const
treeProb = 0.01
burnProb = 0.001

proc chance(prob: float): bool = random(1.0) < prob
proc chance(prob: float): bool = rand(1.0) < prob

# Set the size
var w, h: int
Expand Down
2 changes: 1 addition & 1 deletion game24.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import random, strutils, algorithm, sequtils
randomize()

var
problem = newSeqWith(4, random(1..9))
problem = newSeqWith(4, rand(1..8))
stack = newSeq[float]()
digits = newSeq[int]()

Expand Down
2 changes: 1 addition & 1 deletion gameoflife.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ iterator fields(a = (0,0), b = (h-1,w-1)): (int,int) =
var univ, univNew = newSeqWith(h, newSeq[bool] w)

for y,x in fields():
if random(10) < 1: univ[y][x] = true
if rand(9) < 1: univ[y][x] = true

while true:
# Show
Expand Down
2 changes: 1 addition & 1 deletion gost2814789.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ proc kboxInit =
k43[i] = k4[i shr 4] shl 4 or k3[i and 15]
k21[i] = k2[i shr 4] shl 4 or k1[i and 15]

proc f(x: int64): int64 =
proc f(x: int): int64 =
let x = k87[x shr 24 and 255] shl 24 or k65[x shr 16 and 255] shl 16 or
k43[x shr 8 and 255] shl 8 or k21[x and 255]
x shl 11 or x shr (32 - 11)
Expand Down
2 changes: 1 addition & 1 deletion guessthenumber.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ randomize()
let iRange = 1..100

echo "Guess my target number that is between ", iRange.a, " and ", iRange.b, " (inclusive)."
let target = random(iRange)
let target = rand(iRange)
var answer, i = 0
while answer != target:
inc i
Expand Down
2 changes: 1 addition & 1 deletion hello.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Hello World
@[0, 1, 2]
@[0, 1, 2, 3]
{a: 2, b: 3, c: 4}
{'a': 2, 'b': 3, 'c': 4}
2
9223372036854775807
6
2 changes: 1 addition & 1 deletion htmltable.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import random, htmlgen
randomize()

template randTD: untyped = td($random(1000..9999))
template randTD: untyped = td($rand(1000..9999))
proc randTR(x: int): auto =
tr(td($x, style="font-weight: bold"), randTD, randTD, randTD)

Expand Down
2 changes: 1 addition & 1 deletion josephus.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sequtils, strutils, future
import sequtils, strutils, sugar

proc j(n, k: int): string =
var
Expand Down
2 changes: 1 addition & 1 deletion largestint.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import algorithm, sequtils, strutils, future
import algorithm, sequtils, strutils, sugar

proc maxNum(x: seq[int]): string =
var c = x.mapIt(string, $it)
Expand Down
7 changes: 3 additions & 4 deletions lastfriday.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import times, os, strutils
let year = paramStr(1).parseInt
for month in mJan .. mDec:
for day in countdown(getDaysInMonth(month, year), 1):
let t = getGMTime toTime TimeInfo(second: 0, minute: 0, hour: 12,
monthday: day, month: month, year: year, timezone: 0)
if t.weekday == dFri:
echo t.format "yyyy-MM-dd"
let date = initDateTime(day, month, year, 0, 0, 0, utc())
if date.weekday == dFri:
echo date.format "yyyy-MM-dd"
break
7 changes: 3 additions & 4 deletions lastsunday.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import times, os, strutils
let year = paramStr(1).parseInt
for month in mJan .. mDec:
for day in countdown(getDaysInMonth(month, year), 1):
let t = getGMTime toTime TimeInfo(second: 0, minute: 0, hour: 12,
monthday: day, month: month, year: year, timezone: 0)
if t.weekday == dSun:
echo t.format "yyyy-MM-dd"
let date = initDateTime(day, month, year, 0, 0, 0, utc())
if date.weekday == dSun:
echo date.format "yyyy-MM-dd"
break
2 changes: 1 addition & 1 deletion manboy.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import future
import sugar

proc a(k: int; x1, x2, x3, x4, x5: proc(): int): int =
var k = k
Expand Down
2 changes: 1 addition & 1 deletion maprange.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ proc mapRange(a,b: FloatRange, s: float): float =

for i in 0..10:
let m = mapRange((0.0,10.0), (-1.0, 0.0), float(i))
echo i, " maps to ", formatFloat(m, precision = 0)
echo i, " maps to ", formatFloat(m, precision = -1)
2 changes: 1 addition & 1 deletion matrixarithmeticseq.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sequtils, permutationsswap, future
import sequtils, permutationsswap, sugar

proc det(a: seq[seq[float]]): float =
let n = toSeq 0..a.high
Expand Down
2 changes: 1 addition & 1 deletion maxtrianglepathsum.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import strutils, sequtils, future
import strutils, sequtils, sugar

proc solve(tri: seq[seq[int]]): int =
var tri = tri
Expand Down
Loading

0 comments on commit b91bf6f

Please sign in to comment.