Arbitrary Interval Ruler
$begingroup$
Make a program that takes a length and list of intervals and outputs a ruler of that length with longer ticks for each interval using the line drawing characters ┌ ┬ ┐ │ ╵
- The first row of the output should begin with the tick for 0 with
┌
and end with a tick for the length with┐
, with a┬
being used for every character in between. There will be a total oflength
+ 1 line drawing characters in this first row. - A tick should be lengthened vertically by half-character increments using
╵
and│
based on the input intervals. - Intervals are listed from smallest to largest, relative to the interval before it. To elaborate:
- The first interval tells how many base ticks (the first row - one character per tick) are in the second-smallest interval (the smallest interval being 1). For example, [3] will lengthen every third tick by a half-character.
- The second and subsequent intervals are in terms of the next smallest interval. For example [3, 5] will lengthen every 15th base tick by a full character and [3, 5, 2] will lengthen every 30th base tick by a character and a half.
- A sub-interval of 1 is valid and effectively means that the last interval lines are lengthened by a full character instead of a half-character.
- The example test cases should help to clarify how this works.
Examples/Test Cases
3, :
┌┬┬┐
9, [3]:
┌┬┬┬┬┬┬┬┬┐
╵ ╵ ╵ ╵
30, [5, 2]:
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ │ ╵ │ ╵ │
32, [4, 2, 2, 2]:
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ │ ╵ │ ╵ │ ╵ │
│ ╵ │
48, [5, 3, 2]
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ ╵ │ ╵ ╵ │ ╵ ╵ │
╵ ╵
24, [7, 3]
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ ╵ │
17, [3, 2, 1]
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ │ ╵ │ ╵
╵ ╵ ╵
1, [23, 19, 13, 11, 7, 5, 3, 2, 1]
┌┐
│
│
│
│
╵
Other Rules/Notes
- Input and output can use any convenient format
- The ruler doesn't have to end on a major tick
- The interval list may be empty
- The zeroth tick is always within all intervals.
- You may assume the ruler length and intervals will always be a positive integers less than 120
- Trailing whitespace is fine, but leading whitespace is not.
- Any fixed-single-wide space is allowed as a spacing character if you, for some reason, want to use something other than ASCII spaces.
Happy Golfing!
code-golf ascii-art
$endgroup$
add a comment |
$begingroup$
Make a program that takes a length and list of intervals and outputs a ruler of that length with longer ticks for each interval using the line drawing characters ┌ ┬ ┐ │ ╵
- The first row of the output should begin with the tick for 0 with
┌
and end with a tick for the length with┐
, with a┬
being used for every character in between. There will be a total oflength
+ 1 line drawing characters in this first row. - A tick should be lengthened vertically by half-character increments using
╵
and│
based on the input intervals. - Intervals are listed from smallest to largest, relative to the interval before it. To elaborate:
- The first interval tells how many base ticks (the first row - one character per tick) are in the second-smallest interval (the smallest interval being 1). For example, [3] will lengthen every third tick by a half-character.
- The second and subsequent intervals are in terms of the next smallest interval. For example [3, 5] will lengthen every 15th base tick by a full character and [3, 5, 2] will lengthen every 30th base tick by a character and a half.
- A sub-interval of 1 is valid and effectively means that the last interval lines are lengthened by a full character instead of a half-character.
- The example test cases should help to clarify how this works.
Examples/Test Cases
3, :
┌┬┬┐
9, [3]:
┌┬┬┬┬┬┬┬┬┐
╵ ╵ ╵ ╵
30, [5, 2]:
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ │ ╵ │ ╵ │
32, [4, 2, 2, 2]:
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ │ ╵ │ ╵ │ ╵ │
│ ╵ │
48, [5, 3, 2]
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ ╵ │ ╵ ╵ │ ╵ ╵ │
╵ ╵
24, [7, 3]
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ ╵ │
17, [3, 2, 1]
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ │ ╵ │ ╵
╵ ╵ ╵
1, [23, 19, 13, 11, 7, 5, 3, 2, 1]
┌┐
│
│
│
│
╵
Other Rules/Notes
- Input and output can use any convenient format
- The ruler doesn't have to end on a major tick
- The interval list may be empty
- The zeroth tick is always within all intervals.
- You may assume the ruler length and intervals will always be a positive integers less than 120
- Trailing whitespace is fine, but leading whitespace is not.
- Any fixed-single-wide space is allowed as a spacing character if you, for some reason, want to use something other than ASCII spaces.
Happy Golfing!
code-golf ascii-art
$endgroup$
$begingroup$
For output, can I print the first row, then return a list of columns?
$endgroup$
– Embodiment of Ignorance
yesterday
$begingroup$
@EmbodimentofIgnorance, I'm gonna say no to that. Output should be consistent.
$endgroup$
– Beefster
23 hours ago
$begingroup$
Can we take the box-drawing characters from a single-byte encoding (provided one exists containing the ones required)?
$endgroup$
– Οurous
2 hours ago
add a comment |
$begingroup$
Make a program that takes a length and list of intervals and outputs a ruler of that length with longer ticks for each interval using the line drawing characters ┌ ┬ ┐ │ ╵
- The first row of the output should begin with the tick for 0 with
┌
and end with a tick for the length with┐
, with a┬
being used for every character in between. There will be a total oflength
+ 1 line drawing characters in this first row. - A tick should be lengthened vertically by half-character increments using
╵
and│
based on the input intervals. - Intervals are listed from smallest to largest, relative to the interval before it. To elaborate:
- The first interval tells how many base ticks (the first row - one character per tick) are in the second-smallest interval (the smallest interval being 1). For example, [3] will lengthen every third tick by a half-character.
- The second and subsequent intervals are in terms of the next smallest interval. For example [3, 5] will lengthen every 15th base tick by a full character and [3, 5, 2] will lengthen every 30th base tick by a character and a half.
- A sub-interval of 1 is valid and effectively means that the last interval lines are lengthened by a full character instead of a half-character.
- The example test cases should help to clarify how this works.
Examples/Test Cases
3, :
┌┬┬┐
9, [3]:
┌┬┬┬┬┬┬┬┬┐
╵ ╵ ╵ ╵
30, [5, 2]:
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ │ ╵ │ ╵ │
32, [4, 2, 2, 2]:
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ │ ╵ │ ╵ │ ╵ │
│ ╵ │
48, [5, 3, 2]
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ ╵ │ ╵ ╵ │ ╵ ╵ │
╵ ╵
24, [7, 3]
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ ╵ │
17, [3, 2, 1]
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ │ ╵ │ ╵
╵ ╵ ╵
1, [23, 19, 13, 11, 7, 5, 3, 2, 1]
┌┐
│
│
│
│
╵
Other Rules/Notes
- Input and output can use any convenient format
- The ruler doesn't have to end on a major tick
- The interval list may be empty
- The zeroth tick is always within all intervals.
- You may assume the ruler length and intervals will always be a positive integers less than 120
- Trailing whitespace is fine, but leading whitespace is not.
- Any fixed-single-wide space is allowed as a spacing character if you, for some reason, want to use something other than ASCII spaces.
Happy Golfing!
code-golf ascii-art
$endgroup$
Make a program that takes a length and list of intervals and outputs a ruler of that length with longer ticks for each interval using the line drawing characters ┌ ┬ ┐ │ ╵
- The first row of the output should begin with the tick for 0 with
┌
and end with a tick for the length with┐
, with a┬
being used for every character in between. There will be a total oflength
+ 1 line drawing characters in this first row. - A tick should be lengthened vertically by half-character increments using
╵
and│
based on the input intervals. - Intervals are listed from smallest to largest, relative to the interval before it. To elaborate:
- The first interval tells how many base ticks (the first row - one character per tick) are in the second-smallest interval (the smallest interval being 1). For example, [3] will lengthen every third tick by a half-character.
- The second and subsequent intervals are in terms of the next smallest interval. For example [3, 5] will lengthen every 15th base tick by a full character and [3, 5, 2] will lengthen every 30th base tick by a character and a half.
- A sub-interval of 1 is valid and effectively means that the last interval lines are lengthened by a full character instead of a half-character.
- The example test cases should help to clarify how this works.
Examples/Test Cases
3, :
┌┬┬┐
9, [3]:
┌┬┬┬┬┬┬┬┬┐
╵ ╵ ╵ ╵
30, [5, 2]:
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ │ ╵ │ ╵ │
32, [4, 2, 2, 2]:
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ │ ╵ │ ╵ │ ╵ │
│ ╵ │
48, [5, 3, 2]
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ ╵ │ ╵ ╵ │ ╵ ╵ │
╵ ╵
24, [7, 3]
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ ╵ │
17, [3, 2, 1]
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ ╵ │ ╵ │ ╵
╵ ╵ ╵
1, [23, 19, 13, 11, 7, 5, 3, 2, 1]
┌┐
│
│
│
│
╵
Other Rules/Notes
- Input and output can use any convenient format
- The ruler doesn't have to end on a major tick
- The interval list may be empty
- The zeroth tick is always within all intervals.
- You may assume the ruler length and intervals will always be a positive integers less than 120
- Trailing whitespace is fine, but leading whitespace is not.
- Any fixed-single-wide space is allowed as a spacing character if you, for some reason, want to use something other than ASCII spaces.
Happy Golfing!
code-golf ascii-art
code-golf ascii-art
asked yesterday
BeefsterBeefster
1,557728
1,557728
$begingroup$
For output, can I print the first row, then return a list of columns?
$endgroup$
– Embodiment of Ignorance
yesterday
$begingroup$
@EmbodimentofIgnorance, I'm gonna say no to that. Output should be consistent.
$endgroup$
– Beefster
23 hours ago
$begingroup$
Can we take the box-drawing characters from a single-byte encoding (provided one exists containing the ones required)?
$endgroup$
– Οurous
2 hours ago
add a comment |
$begingroup$
For output, can I print the first row, then return a list of columns?
$endgroup$
– Embodiment of Ignorance
yesterday
$begingroup$
@EmbodimentofIgnorance, I'm gonna say no to that. Output should be consistent.
$endgroup$
– Beefster
23 hours ago
$begingroup$
Can we take the box-drawing characters from a single-byte encoding (provided one exists containing the ones required)?
$endgroup$
– Οurous
2 hours ago
$begingroup$
For output, can I print the first row, then return a list of columns?
$endgroup$
– Embodiment of Ignorance
yesterday
$begingroup$
For output, can I print the first row, then return a list of columns?
$endgroup$
– Embodiment of Ignorance
yesterday
$begingroup$
@EmbodimentofIgnorance, I'm gonna say no to that. Output should be consistent.
$endgroup$
– Beefster
23 hours ago
$begingroup$
@EmbodimentofIgnorance, I'm gonna say no to that. Output should be consistent.
$endgroup$
– Beefster
23 hours ago
$begingroup$
Can we take the box-drawing characters from a single-byte encoding (provided one exists containing the ones required)?
$endgroup$
– Οurous
2 hours ago
$begingroup$
Can we take the box-drawing characters from a single-byte encoding (provided one exists containing the ones required)?
$endgroup$
– Οurous
2 hours ago
add a comment |
14 Answers
14
active
oldest
votes
$begingroup$
Perl 6, 130 122 102 92 bytes
-10butes thanks tp nwellnhof!
{'┌'~'┬'x$^a-1~'┐',|map {[~] <<' '╵ │>>[:1[$_ X%%@_]for 0..$a]},batch [*] @^b: 2}
Try it online!
Ah yes, much shorter than my previous method. This is an anonymous code block that returns a list of lines.
Explanation:
{ } # Anonymous code block
'┌'~'┬'x$^a-1~'┐', # Return the first line
|[*] @^b # Get the cumulative product of the input list
.batch(2) # And split it into pairs
.map:{ } # Map each pair to
for 0..$a # For each interval
:1[$_ X%%@_] # Whether it is divisible by none of the pair, one of the pair, or both
<<' '╵ │>>[ ] # Map to a list of characters
[~] # And join
$endgroup$
add a comment |
$begingroup$
Emacs Lisp, 303 bytes
(defun f(a)(princ'┌)(dotimes(i(1-(car a)))(princ'┬))(princ'┐)(let((m 1))(while(cadr a)(let((q(caadr a))(w (cadadr a)))(princ"n")(dotimes(i(1+(car a)))(cond((if w(= 0(mod i(* m q w))))(princ'│))((= 0(mod i (* m q)))(princ'╵))(t(princ" "))))(setq m(* m q(if w w 1)))(setcdr a`(,(cddadr a)))))))
Use this function as (f '(30 (5 2)))
.
Better readable version:
(defun f (a)
(princ '┌)
(dotimes (i (1- (car a)))
(princ '┬))
(princ '┐)
(let ((m 1))
(while (cadr a)
(let ((q (caadr a)) (w (cadadr a)))
(princ "n")
(dotimes (i (1+ (car a)))
(cond ((if w (= 0 (mod i (* m q w))))
(princ '│))
((= 0 (mod i (* m q)))
(princ '╵))
(t
(princ " "))))
(setq m (* m q (if w w 1)))
(setcdr a `(,(cddadr a)))))))
New contributor
$endgroup$
add a comment |
$begingroup$
JavaScript (Node.js), 123 bytes
l=>g=([p,q,...t],h='┌'.padEnd(l,'┬')+`┐
`)=>p?h+g(t,h.replace(/S/g,c=>'╵│ '[c>'╴'||++i%p?2:i/p%q<1|0],i=-1)):h
Try it online!
Use this function as f(20)([5, 2])
.
Thanks Arnauld, saves 4 bytes.
$endgroup$
$begingroup$
'┌'.padEnd(l,`┬`)
saves 3 bytes over'┌'+Array(l).join`┬`
.
$endgroup$
– Arnauld
14 hours ago
$begingroup$
Usingc>'╴'
saves another byte.
$endgroup$
– Arnauld
14 hours ago
add a comment |
$begingroup$
Python 3, 173 172 bytes
def f(w,n):
print('┌'+'┬'*~-w+'┐');R=r=range(w+1)
for i,j in zip(*[iter(n+[0])]*2):a=r[::i];r=j*[0]and a[::j];print(''.join(' ╵│'[(v in a)+(v in r)]for v in R))
Try it online!
$endgroup$
add a comment |
$begingroup$
05AB1E, 51 bytes
ÝεyIηPÖO2‰•5·W4•2äç×SI¯Qiεõ}}•áΣ=Yô•3äçy¹QyĀ+èš}ζJ»
Not too happy with the I¯Qiεõ}}
as work-around for empty input-lists.. And can definitely be golfed at some other parts as well..
NOTE: Uses compressed integers converted to the required characters, because using the required characters directly means I'll have to count the entire program in UTF-8, increasing it by too much for all 05AB1E's builtin characters as well.
Try it online or verify all test cases.
Explanation:
Ý # Create a list in the range [0, first (implicit) input-integer]
ε # Map each value `y` to:
Iη # Get the prefixes of the second input-list
P # Get the product of each prefix
y Ö # Check for each if its evenly dividing the value `y`
O # Take the sum of that
2‰ # And then the divmod 2
•5·W4• # Push compressed integer 94749589
2ä # Split into two equal-sized parts: [9474,9589]
ç # Convert each to a character: ["│","╵"]
× # Repeat each based on the divmod 2 result
S # And convert it to a flattened list of characters
I¯Qi } # If the second input-list was empty:
εõ} # Map each list to an empty string
# (for some reason `€õ` doesn't work here..)
•áΣ=Yô• # Push compressed integer 948495169488
3ä # Split into three equal-sized parts: [9484,9516,9488]
ç # Convert each to a character: ["┌","┬","┐"]
y¹Q # Check if the value `y` is equal to the first input-integer
# (1 if truthy; 0 if falsey)
yĀ # Check if the value `y` is NOT 0 (1 if truthy; 0 if falsey)
+ # Add both checks together
è # Use it to index into the list ["┌","┬","┐"]
š # And prepend the result in front of the other characters
}ζ # After the map: zip/transpose; swapping rows and columns (with space filler)
J # Join every inner list together to a single string
» # Join the lines with newline delimiter (and output implicitly)
See this 05AB1E tip of mine (section How to compress large integers?) to understand why •5·W4•
is 94749589
and •áΣ=Yô•
is 948495169488
.
$endgroup$
$begingroup$
×S
can beи
$endgroup$
– Magic Octopus Urn
5 hours ago
add a comment |
$begingroup$
Charcoal, 50 bytes
≔EηΠ…η⊕κη⪫┐┌×┬⊖θ↙↓EE⊕θΣEη¬﹪ιλ⁺×│⊘ι×╵﹪ι²‖
Try it online! Link is to verbose version of code. Box-drawing characters have a 3 byte representation in Charcoal, so the above string is only 40 characters long. Explanation:
≔EηΠ…η⊕κη
Calculate the cumulative product of the intervals.
⪫┐┌×┬⊖θ↙
Print the first row of tick marks. The left and right characters are the wrong way around because the result is reflected later.
↓EE⊕θΣEη¬﹪ιλ⁺×│⊘ι×╵﹪ι²
Calculate the number of intervals that are a factor of each tick mark. Generate a string of │
s of half that length and add ╵
for odd lengths. Print each string downwards with subsequent strings in previous columns, i.e. reverse order.
‖
Reflect everything to get the ruler in left-to-right order.
$endgroup$
add a comment |
$begingroup$
Ruby, 126 bytes
->l,i{y=1;[?┌+?┬*~-l+?┐]+i.each_slice(2).map{|j,k|x=y*j;y=k&&x*k;(0..l).map{|z|'│╵ '[(z%x<=>0)+(k ?z%y<=>0:1)]}*''}}
Try it online!
Looks rather verbose with all that each_slice
stuff, but will do for now, unless I manage to find a golfier approach.
Takes input as l
for length and i
for intervals, returns an array of strings.
$endgroup$
add a comment |
$begingroup$
R, 175 170 bytes
function(l,i,`&`=rep)rbind(c('┌','┬'&l-1,'┐'),if(i)sapply(rowSums(!outer(0:l,cumprod(i),`%%`)),function(j,x=j%/%2,y=j%%2)c('│'&x,'╵'&y,' '&(1+sum(1|i))/2-x-y)))
Try it online!
Takes empty intervals as 0
, returns a matrix of characters. TIO link displays the output pretty-printed.
$endgroup$
add a comment |
$begingroup$
Canvas, 42 41 40 bytes
┐”┬”┌”O⁸╷×oo╵(0)⁷{*J╵;∔}m{2n“╵”×;“│”××]⤢
Try it here! (with a font that monospaces the output)
$endgroup$
add a comment |
$begingroup$
Dyalog APL, 66 bytes
{(∊'┌'(1↓⍵⍴'┬')'┐')⍪⍉↑⊃,¨/(↓0 2⊤+⌿0=(×⍺)∘.|⍳1+⍵)⍴¨¨'│',⎕UCS 9589}
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 167 164 bytes
n%l|let c=take(n+1).cycle;m&(x:y:r)=c('│':init([1..y]>>(m*x)!" "++"╵"))++'n':(m*x*y)&r;m&[x]=c$'╵':(m*x)!" ";m&e=='┌':n!"┬"++"┐n"++1&l
n!s=[2..n]>>s
Try it online! There are still some redundancies which look like they could be exploited, but so far they withstood all further golfing attempts.
The previous 167 byte solution is the same apart from newline handling and is probably slightly better readable:
n%l=unlines$('┌':n!"┬"++"┐"):(take(n+1)<$>1&l)
n!s=[2..n]>>s
m&(x:y:r)=cycle('│':init([1..y]>>(m*x)!" "++"╵")):(m*x*y)&r
m&[x]=[cycle$'╵':(m*x)!" "]
m&e=
Try it online!
$endgroup$
$begingroup$
Different approach at 158 bytes (Try it online!), can probably be shortened quite a bit more since I don't speak Haskell well.
$endgroup$
– Οurous
2 hours ago
add a comment |
$begingroup$
Jelly, 42 41 bytes
‘Rm×}Ṭ€+2/
⁽!ṣ;“½¥÷I‘ÄỌṙ-;⁶
Ḷ¬;.Ḥ~W;ñị¢Y
A full program.
Try it online!
Or see a test-suite
Note: this code has been altered from a full program -- ñ
(next link as a dyad) has been replaced with 1ŀ
(link at index 1 as a dyad) to allow it to be called multiple times by the footer.
How?
‘Rm×}Ṭ€+2/ - Link 1, lower interval tick types: length; intervals e.g. 7; [3,2]
‘ - increment length 8
R - range [1,2,3,4,5,6,7,8]
} - use right argument for this monad as if it were a dyad:
× - cumulative reduce by multiplication [3,6]
m - modulo slice (vectorises) [[1,4,7],[1,7]]
Ṭ€ - untruth €ach [[1,0,0,1,0,0,1],[1,0,0,0,0,0,1]]
+2/ - pairwise reduce with addition [[2,0,0,1,0,0,2]]
- -- yielding a list of types for each row of characters below the first
- where 0 is a space, 1 is a short tick-mark and 2 is a long tick-mark
⁽!ṣ;“½¥÷I‘ÄỌṙ-;⁶ - Link 2, make character set: no arguments
⁽!ṣ - literal 9474
“½¥÷I‘ - list of code-page indices = [10,4,28,73]
; - concatenate [9474,10,4,28,73]
Ä - cumulative addition [9474,9484,9488,9516,9589]
Ọ - to characters "│┌┐┬╵"
ṙ- - rotate left by -1 "╵│┌┐┬"
⁶ - literal space character ' '
; - concatenate "╵│┌┐┬ "
Ḷ¬;.Ḥ~W;ñị¢Y - Main link: length, L; intervals, I
Ḷ - lowered range [ 0, 1, 2, ..., L-1]
¬ - logical Not [ 1, 0, 0, ..., 0]
. - literal 0.5
; - concatenate [ 1, 0, 0, ..., 0, 0.5]
Ḥ - double [ 2, 0, 0, ..., 0, 1]
~ - bitwise NOT [-3,-1,-1, ...,-1,-2]
W - wrap that in a list [[-3,-1,-1, ...,-1,-2]]
ñ - call next Link (1) as a dyad (f(L, I))
; - (left) concatenated with (right)
¢ - call last Link (2) as a nilad (f())
ị - (left) index into (right) (1-indexed and modular)
Y - join with newline characters
- implicit print
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 204 bytes
a=>b=>{Write("┌"+"┐n".PadLeft(++a,'┬'));for(int i=1;;i++,WriteLine())for(int j=0;j<a;){var m=b.Select((c,d)=>b.Take(d+1).Aggregate((e,f)=>e*f)).Count(c=>j++%c<1);Write(m<1|i>m?" ":m<2?"╵":"|");}}
Try it online!
Outputs, but gets stuck in an infinite loop.
$endgroup$
add a comment |
$begingroup$
Clean, 221 201 195 162 bytes
import StdEnv
$n l=[["┌":repeatn(n-1)"┬"]++["┐"]:[[if(?(i-1))if(?i&&l%(i,i)>)"│""╵"" "\p<-[0..n],let?j=1>p rem(prod(l%(0,j)))
]\i<-[1,3..length l]]]
Try it online!
Returns a list of lists of UTF-8 characters (as strings, since Clean has no innate UTF-8 support).
Works by generating the first line, then taking the product of prefixes of the list provided in groups of two, and checks which mark to draw based on whether the product divides the current character position.
Ungolfed:
$ n l
= [
["┌": repeatn (n - 1) "┬"] ++ ["┐"]:
[
[
if(? (i - 1))
if(? i && l%(i, i) > )
"│"
"╵"
" "
\ p <- [0..n]
, let
? j = 1 > p rem (prod (l%(0, j)))
]
\ i <- [1, 3.. length l]
]
]
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f180063%2farbitrary-interval-ruler%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
14 Answers
14
active
oldest
votes
14 Answers
14
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Perl 6, 130 122 102 92 bytes
-10butes thanks tp nwellnhof!
{'┌'~'┬'x$^a-1~'┐',|map {[~] <<' '╵ │>>[:1[$_ X%%@_]for 0..$a]},batch [*] @^b: 2}
Try it online!
Ah yes, much shorter than my previous method. This is an anonymous code block that returns a list of lines.
Explanation:
{ } # Anonymous code block
'┌'~'┬'x$^a-1~'┐', # Return the first line
|[*] @^b # Get the cumulative product of the input list
.batch(2) # And split it into pairs
.map:{ } # Map each pair to
for 0..$a # For each interval
:1[$_ X%%@_] # Whether it is divisible by none of the pair, one of the pair, or both
<<' '╵ │>>[ ] # Map to a list of characters
[~] # And join
$endgroup$
add a comment |
$begingroup$
Perl 6, 130 122 102 92 bytes
-10butes thanks tp nwellnhof!
{'┌'~'┬'x$^a-1~'┐',|map {[~] <<' '╵ │>>[:1[$_ X%%@_]for 0..$a]},batch [*] @^b: 2}
Try it online!
Ah yes, much shorter than my previous method. This is an anonymous code block that returns a list of lines.
Explanation:
{ } # Anonymous code block
'┌'~'┬'x$^a-1~'┐', # Return the first line
|[*] @^b # Get the cumulative product of the input list
.batch(2) # And split it into pairs
.map:{ } # Map each pair to
for 0..$a # For each interval
:1[$_ X%%@_] # Whether it is divisible by none of the pair, one of the pair, or both
<<' '╵ │>>[ ] # Map to a list of characters
[~] # And join
$endgroup$
add a comment |
$begingroup$
Perl 6, 130 122 102 92 bytes
-10butes thanks tp nwellnhof!
{'┌'~'┬'x$^a-1~'┐',|map {[~] <<' '╵ │>>[:1[$_ X%%@_]for 0..$a]},batch [*] @^b: 2}
Try it online!
Ah yes, much shorter than my previous method. This is an anonymous code block that returns a list of lines.
Explanation:
{ } # Anonymous code block
'┌'~'┬'x$^a-1~'┐', # Return the first line
|[*] @^b # Get the cumulative product of the input list
.batch(2) # And split it into pairs
.map:{ } # Map each pair to
for 0..$a # For each interval
:1[$_ X%%@_] # Whether it is divisible by none of the pair, one of the pair, or both
<<' '╵ │>>[ ] # Map to a list of characters
[~] # And join
$endgroup$
Perl 6, 130 122 102 92 bytes
-10butes thanks tp nwellnhof!
{'┌'~'┬'x$^a-1~'┐',|map {[~] <<' '╵ │>>[:1[$_ X%%@_]for 0..$a]},batch [*] @^b: 2}
Try it online!
Ah yes, much shorter than my previous method. This is an anonymous code block that returns a list of lines.
Explanation:
{ } # Anonymous code block
'┌'~'┬'x$^a-1~'┐', # Return the first line
|[*] @^b # Get the cumulative product of the input list
.batch(2) # And split it into pairs
.map:{ } # Map each pair to
for 0..$a # For each interval
:1[$_ X%%@_] # Whether it is divisible by none of the pair, one of the pair, or both
<<' '╵ │>>[ ] # Map to a list of characters
[~] # And join
edited 15 hours ago
answered yesterday
Jo KingJo King
23.2k253121
23.2k253121
add a comment |
add a comment |
$begingroup$
Emacs Lisp, 303 bytes
(defun f(a)(princ'┌)(dotimes(i(1-(car a)))(princ'┬))(princ'┐)(let((m 1))(while(cadr a)(let((q(caadr a))(w (cadadr a)))(princ"n")(dotimes(i(1+(car a)))(cond((if w(= 0(mod i(* m q w))))(princ'│))((= 0(mod i (* m q)))(princ'╵))(t(princ" "))))(setq m(* m q(if w w 1)))(setcdr a`(,(cddadr a)))))))
Use this function as (f '(30 (5 2)))
.
Better readable version:
(defun f (a)
(princ '┌)
(dotimes (i (1- (car a)))
(princ '┬))
(princ '┐)
(let ((m 1))
(while (cadr a)
(let ((q (caadr a)) (w (cadadr a)))
(princ "n")
(dotimes (i (1+ (car a)))
(cond ((if w (= 0 (mod i (* m q w))))
(princ '│))
((= 0 (mod i (* m q)))
(princ '╵))
(t
(princ " "))))
(setq m (* m q (if w w 1)))
(setcdr a `(,(cddadr a)))))))
New contributor
$endgroup$
add a comment |
$begingroup$
Emacs Lisp, 303 bytes
(defun f(a)(princ'┌)(dotimes(i(1-(car a)))(princ'┬))(princ'┐)(let((m 1))(while(cadr a)(let((q(caadr a))(w (cadadr a)))(princ"n")(dotimes(i(1+(car a)))(cond((if w(= 0(mod i(* m q w))))(princ'│))((= 0(mod i (* m q)))(princ'╵))(t(princ" "))))(setq m(* m q(if w w 1)))(setcdr a`(,(cddadr a)))))))
Use this function as (f '(30 (5 2)))
.
Better readable version:
(defun f (a)
(princ '┌)
(dotimes (i (1- (car a)))
(princ '┬))
(princ '┐)
(let ((m 1))
(while (cadr a)
(let ((q (caadr a)) (w (cadadr a)))
(princ "n")
(dotimes (i (1+ (car a)))
(cond ((if w (= 0 (mod i (* m q w))))
(princ '│))
((= 0 (mod i (* m q)))
(princ '╵))
(t
(princ " "))))
(setq m (* m q (if w w 1)))
(setcdr a `(,(cddadr a)))))))
New contributor
$endgroup$
add a comment |
$begingroup$
Emacs Lisp, 303 bytes
(defun f(a)(princ'┌)(dotimes(i(1-(car a)))(princ'┬))(princ'┐)(let((m 1))(while(cadr a)(let((q(caadr a))(w (cadadr a)))(princ"n")(dotimes(i(1+(car a)))(cond((if w(= 0(mod i(* m q w))))(princ'│))((= 0(mod i (* m q)))(princ'╵))(t(princ" "))))(setq m(* m q(if w w 1)))(setcdr a`(,(cddadr a)))))))
Use this function as (f '(30 (5 2)))
.
Better readable version:
(defun f (a)
(princ '┌)
(dotimes (i (1- (car a)))
(princ '┬))
(princ '┐)
(let ((m 1))
(while (cadr a)
(let ((q (caadr a)) (w (cadadr a)))
(princ "n")
(dotimes (i (1+ (car a)))
(cond ((if w (= 0 (mod i (* m q w))))
(princ '│))
((= 0 (mod i (* m q)))
(princ '╵))
(t
(princ " "))))
(setq m (* m q (if w w 1)))
(setcdr a `(,(cddadr a)))))))
New contributor
$endgroup$
Emacs Lisp, 303 bytes
(defun f(a)(princ'┌)(dotimes(i(1-(car a)))(princ'┬))(princ'┐)(let((m 1))(while(cadr a)(let((q(caadr a))(w (cadadr a)))(princ"n")(dotimes(i(1+(car a)))(cond((if w(= 0(mod i(* m q w))))(princ'│))((= 0(mod i (* m q)))(princ'╵))(t(princ" "))))(setq m(* m q(if w w 1)))(setcdr a`(,(cddadr a)))))))
Use this function as (f '(30 (5 2)))
.
Better readable version:
(defun f (a)
(princ '┌)
(dotimes (i (1- (car a)))
(princ '┬))
(princ '┐)
(let ((m 1))
(while (cadr a)
(let ((q (caadr a)) (w (cadadr a)))
(princ "n")
(dotimes (i (1+ (car a)))
(cond ((if w (= 0 (mod i (* m q w))))
(princ '│))
((= 0 (mod i (* m q)))
(princ '╵))
(t
(princ " "))))
(setq m (* m q (if w w 1)))
(setcdr a `(,(cddadr a)))))))
New contributor
New contributor
answered 2 hours ago
adladl
1211
1211
New contributor
New contributor
add a comment |
add a comment |
$begingroup$
JavaScript (Node.js), 123 bytes
l=>g=([p,q,...t],h='┌'.padEnd(l,'┬')+`┐
`)=>p?h+g(t,h.replace(/S/g,c=>'╵│ '[c>'╴'||++i%p?2:i/p%q<1|0],i=-1)):h
Try it online!
Use this function as f(20)([5, 2])
.
Thanks Arnauld, saves 4 bytes.
$endgroup$
$begingroup$
'┌'.padEnd(l,`┬`)
saves 3 bytes over'┌'+Array(l).join`┬`
.
$endgroup$
– Arnauld
14 hours ago
$begingroup$
Usingc>'╴'
saves another byte.
$endgroup$
– Arnauld
14 hours ago
add a comment |
$begingroup$
JavaScript (Node.js), 123 bytes
l=>g=([p,q,...t],h='┌'.padEnd(l,'┬')+`┐
`)=>p?h+g(t,h.replace(/S/g,c=>'╵│ '[c>'╴'||++i%p?2:i/p%q<1|0],i=-1)):h
Try it online!
Use this function as f(20)([5, 2])
.
Thanks Arnauld, saves 4 bytes.
$endgroup$
$begingroup$
'┌'.padEnd(l,`┬`)
saves 3 bytes over'┌'+Array(l).join`┬`
.
$endgroup$
– Arnauld
14 hours ago
$begingroup$
Usingc>'╴'
saves another byte.
$endgroup$
– Arnauld
14 hours ago
add a comment |
$begingroup$
JavaScript (Node.js), 123 bytes
l=>g=([p,q,...t],h='┌'.padEnd(l,'┬')+`┐
`)=>p?h+g(t,h.replace(/S/g,c=>'╵│ '[c>'╴'||++i%p?2:i/p%q<1|0],i=-1)):h
Try it online!
Use this function as f(20)([5, 2])
.
Thanks Arnauld, saves 4 bytes.
$endgroup$
JavaScript (Node.js), 123 bytes
l=>g=([p,q,...t],h='┌'.padEnd(l,'┬')+`┐
`)=>p?h+g(t,h.replace(/S/g,c=>'╵│ '[c>'╴'||++i%p?2:i/p%q<1|0],i=-1)):h
Try it online!
Use this function as f(20)([5, 2])
.
Thanks Arnauld, saves 4 bytes.
edited 38 mins ago
answered 15 hours ago
tshtsh
9,03511650
9,03511650
$begingroup$
'┌'.padEnd(l,`┬`)
saves 3 bytes over'┌'+Array(l).join`┬`
.
$endgroup$
– Arnauld
14 hours ago
$begingroup$
Usingc>'╴'
saves another byte.
$endgroup$
– Arnauld
14 hours ago
add a comment |
$begingroup$
'┌'.padEnd(l,`┬`)
saves 3 bytes over'┌'+Array(l).join`┬`
.
$endgroup$
– Arnauld
14 hours ago
$begingroup$
Usingc>'╴'
saves another byte.
$endgroup$
– Arnauld
14 hours ago
$begingroup$
'┌'.padEnd(l,`┬`)
saves 3 bytes over '┌'+Array(l).join`┬`
.$endgroup$
– Arnauld
14 hours ago
$begingroup$
'┌'.padEnd(l,`┬`)
saves 3 bytes over '┌'+Array(l).join`┬`
.$endgroup$
– Arnauld
14 hours ago
$begingroup$
Using
c>'╴'
saves another byte.$endgroup$
– Arnauld
14 hours ago
$begingroup$
Using
c>'╴'
saves another byte.$endgroup$
– Arnauld
14 hours ago
add a comment |
$begingroup$
Python 3, 173 172 bytes
def f(w,n):
print('┌'+'┬'*~-w+'┐');R=r=range(w+1)
for i,j in zip(*[iter(n+[0])]*2):a=r[::i];r=j*[0]and a[::j];print(''.join(' ╵│'[(v in a)+(v in r)]for v in R))
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 3, 173 172 bytes
def f(w,n):
print('┌'+'┬'*~-w+'┐');R=r=range(w+1)
for i,j in zip(*[iter(n+[0])]*2):a=r[::i];r=j*[0]and a[::j];print(''.join(' ╵│'[(v in a)+(v in r)]for v in R))
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 3, 173 172 bytes
def f(w,n):
print('┌'+'┬'*~-w+'┐');R=r=range(w+1)
for i,j in zip(*[iter(n+[0])]*2):a=r[::i];r=j*[0]and a[::j];print(''.join(' ╵│'[(v in a)+(v in r)]for v in R))
Try it online!
$endgroup$
Python 3, 173 172 bytes
def f(w,n):
print('┌'+'┬'*~-w+'┐');R=r=range(w+1)
for i,j in zip(*[iter(n+[0])]*2):a=r[::i];r=j*[0]and a[::j];print(''.join(' ╵│'[(v in a)+(v in r)]for v in R))
Try it online!
edited 18 hours ago
answered 18 hours ago
TFeldTFeld
15.2k21245
15.2k21245
add a comment |
add a comment |
$begingroup$
05AB1E, 51 bytes
ÝεyIηPÖO2‰•5·W4•2äç×SI¯Qiεõ}}•áΣ=Yô•3äçy¹QyĀ+èš}ζJ»
Not too happy with the I¯Qiεõ}}
as work-around for empty input-lists.. And can definitely be golfed at some other parts as well..
NOTE: Uses compressed integers converted to the required characters, because using the required characters directly means I'll have to count the entire program in UTF-8, increasing it by too much for all 05AB1E's builtin characters as well.
Try it online or verify all test cases.
Explanation:
Ý # Create a list in the range [0, first (implicit) input-integer]
ε # Map each value `y` to:
Iη # Get the prefixes of the second input-list
P # Get the product of each prefix
y Ö # Check for each if its evenly dividing the value `y`
O # Take the sum of that
2‰ # And then the divmod 2
•5·W4• # Push compressed integer 94749589
2ä # Split into two equal-sized parts: [9474,9589]
ç # Convert each to a character: ["│","╵"]
× # Repeat each based on the divmod 2 result
S # And convert it to a flattened list of characters
I¯Qi } # If the second input-list was empty:
εõ} # Map each list to an empty string
# (for some reason `€õ` doesn't work here..)
•áΣ=Yô• # Push compressed integer 948495169488
3ä # Split into three equal-sized parts: [9484,9516,9488]
ç # Convert each to a character: ["┌","┬","┐"]
y¹Q # Check if the value `y` is equal to the first input-integer
# (1 if truthy; 0 if falsey)
yĀ # Check if the value `y` is NOT 0 (1 if truthy; 0 if falsey)
+ # Add both checks together
è # Use it to index into the list ["┌","┬","┐"]
š # And prepend the result in front of the other characters
}ζ # After the map: zip/transpose; swapping rows and columns (with space filler)
J # Join every inner list together to a single string
» # Join the lines with newline delimiter (and output implicitly)
See this 05AB1E tip of mine (section How to compress large integers?) to understand why •5·W4•
is 94749589
and •áΣ=Yô•
is 948495169488
.
$endgroup$
$begingroup$
×S
can beи
$endgroup$
– Magic Octopus Urn
5 hours ago
add a comment |
$begingroup$
05AB1E, 51 bytes
ÝεyIηPÖO2‰•5·W4•2äç×SI¯Qiεõ}}•áΣ=Yô•3äçy¹QyĀ+èš}ζJ»
Not too happy with the I¯Qiεõ}}
as work-around for empty input-lists.. And can definitely be golfed at some other parts as well..
NOTE: Uses compressed integers converted to the required characters, because using the required characters directly means I'll have to count the entire program in UTF-8, increasing it by too much for all 05AB1E's builtin characters as well.
Try it online or verify all test cases.
Explanation:
Ý # Create a list in the range [0, first (implicit) input-integer]
ε # Map each value `y` to:
Iη # Get the prefixes of the second input-list
P # Get the product of each prefix
y Ö # Check for each if its evenly dividing the value `y`
O # Take the sum of that
2‰ # And then the divmod 2
•5·W4• # Push compressed integer 94749589
2ä # Split into two equal-sized parts: [9474,9589]
ç # Convert each to a character: ["│","╵"]
× # Repeat each based on the divmod 2 result
S # And convert it to a flattened list of characters
I¯Qi } # If the second input-list was empty:
εõ} # Map each list to an empty string
# (for some reason `€õ` doesn't work here..)
•áΣ=Yô• # Push compressed integer 948495169488
3ä # Split into three equal-sized parts: [9484,9516,9488]
ç # Convert each to a character: ["┌","┬","┐"]
y¹Q # Check if the value `y` is equal to the first input-integer
# (1 if truthy; 0 if falsey)
yĀ # Check if the value `y` is NOT 0 (1 if truthy; 0 if falsey)
+ # Add both checks together
è # Use it to index into the list ["┌","┬","┐"]
š # And prepend the result in front of the other characters
}ζ # After the map: zip/transpose; swapping rows and columns (with space filler)
J # Join every inner list together to a single string
» # Join the lines with newline delimiter (and output implicitly)
See this 05AB1E tip of mine (section How to compress large integers?) to understand why •5·W4•
is 94749589
and •áΣ=Yô•
is 948495169488
.
$endgroup$
$begingroup$
×S
can beи
$endgroup$
– Magic Octopus Urn
5 hours ago
add a comment |
$begingroup$
05AB1E, 51 bytes
ÝεyIηPÖO2‰•5·W4•2äç×SI¯Qiεõ}}•áΣ=Yô•3äçy¹QyĀ+èš}ζJ»
Not too happy with the I¯Qiεõ}}
as work-around for empty input-lists.. And can definitely be golfed at some other parts as well..
NOTE: Uses compressed integers converted to the required characters, because using the required characters directly means I'll have to count the entire program in UTF-8, increasing it by too much for all 05AB1E's builtin characters as well.
Try it online or verify all test cases.
Explanation:
Ý # Create a list in the range [0, first (implicit) input-integer]
ε # Map each value `y` to:
Iη # Get the prefixes of the second input-list
P # Get the product of each prefix
y Ö # Check for each if its evenly dividing the value `y`
O # Take the sum of that
2‰ # And then the divmod 2
•5·W4• # Push compressed integer 94749589
2ä # Split into two equal-sized parts: [9474,9589]
ç # Convert each to a character: ["│","╵"]
× # Repeat each based on the divmod 2 result
S # And convert it to a flattened list of characters
I¯Qi } # If the second input-list was empty:
εõ} # Map each list to an empty string
# (for some reason `€õ` doesn't work here..)
•áΣ=Yô• # Push compressed integer 948495169488
3ä # Split into three equal-sized parts: [9484,9516,9488]
ç # Convert each to a character: ["┌","┬","┐"]
y¹Q # Check if the value `y` is equal to the first input-integer
# (1 if truthy; 0 if falsey)
yĀ # Check if the value `y` is NOT 0 (1 if truthy; 0 if falsey)
+ # Add both checks together
è # Use it to index into the list ["┌","┬","┐"]
š # And prepend the result in front of the other characters
}ζ # After the map: zip/transpose; swapping rows and columns (with space filler)
J # Join every inner list together to a single string
» # Join the lines with newline delimiter (and output implicitly)
See this 05AB1E tip of mine (section How to compress large integers?) to understand why •5·W4•
is 94749589
and •áΣ=Yô•
is 948495169488
.
$endgroup$
05AB1E, 51 bytes
ÝεyIηPÖO2‰•5·W4•2äç×SI¯Qiεõ}}•áΣ=Yô•3äçy¹QyĀ+èš}ζJ»
Not too happy with the I¯Qiεõ}}
as work-around for empty input-lists.. And can definitely be golfed at some other parts as well..
NOTE: Uses compressed integers converted to the required characters, because using the required characters directly means I'll have to count the entire program in UTF-8, increasing it by too much for all 05AB1E's builtin characters as well.
Try it online or verify all test cases.
Explanation:
Ý # Create a list in the range [0, first (implicit) input-integer]
ε # Map each value `y` to:
Iη # Get the prefixes of the second input-list
P # Get the product of each prefix
y Ö # Check for each if its evenly dividing the value `y`
O # Take the sum of that
2‰ # And then the divmod 2
•5·W4• # Push compressed integer 94749589
2ä # Split into two equal-sized parts: [9474,9589]
ç # Convert each to a character: ["│","╵"]
× # Repeat each based on the divmod 2 result
S # And convert it to a flattened list of characters
I¯Qi } # If the second input-list was empty:
εõ} # Map each list to an empty string
# (for some reason `€õ` doesn't work here..)
•áΣ=Yô• # Push compressed integer 948495169488
3ä # Split into three equal-sized parts: [9484,9516,9488]
ç # Convert each to a character: ["┌","┬","┐"]
y¹Q # Check if the value `y` is equal to the first input-integer
# (1 if truthy; 0 if falsey)
yĀ # Check if the value `y` is NOT 0 (1 if truthy; 0 if falsey)
+ # Add both checks together
è # Use it to index into the list ["┌","┬","┐"]
š # And prepend the result in front of the other characters
}ζ # After the map: zip/transpose; swapping rows and columns (with space filler)
J # Join every inner list together to a single string
» # Join the lines with newline delimiter (and output implicitly)
See this 05AB1E tip of mine (section How to compress large integers?) to understand why •5·W4•
is 94749589
and •áΣ=Yô•
is 948495169488
.
answered 18 hours ago
Kevin CruijssenKevin Cruijssen
38.2k557197
38.2k557197
$begingroup$
×S
can beи
$endgroup$
– Magic Octopus Urn
5 hours ago
add a comment |
$begingroup$
×S
can beи
$endgroup$
– Magic Octopus Urn
5 hours ago
$begingroup$
×S
can be и
$endgroup$
– Magic Octopus Urn
5 hours ago
$begingroup$
×S
can be и
$endgroup$
– Magic Octopus Urn
5 hours ago
add a comment |
$begingroup$
Charcoal, 50 bytes
≔EηΠ…η⊕κη⪫┐┌×┬⊖θ↙↓EE⊕θΣEη¬﹪ιλ⁺×│⊘ι×╵﹪ι²‖
Try it online! Link is to verbose version of code. Box-drawing characters have a 3 byte representation in Charcoal, so the above string is only 40 characters long. Explanation:
≔EηΠ…η⊕κη
Calculate the cumulative product of the intervals.
⪫┐┌×┬⊖θ↙
Print the first row of tick marks. The left and right characters are the wrong way around because the result is reflected later.
↓EE⊕θΣEη¬﹪ιλ⁺×│⊘ι×╵﹪ι²
Calculate the number of intervals that are a factor of each tick mark. Generate a string of │
s of half that length and add ╵
for odd lengths. Print each string downwards with subsequent strings in previous columns, i.e. reverse order.
‖
Reflect everything to get the ruler in left-to-right order.
$endgroup$
add a comment |
$begingroup$
Charcoal, 50 bytes
≔EηΠ…η⊕κη⪫┐┌×┬⊖θ↙↓EE⊕θΣEη¬﹪ιλ⁺×│⊘ι×╵﹪ι²‖
Try it online! Link is to verbose version of code. Box-drawing characters have a 3 byte representation in Charcoal, so the above string is only 40 characters long. Explanation:
≔EηΠ…η⊕κη
Calculate the cumulative product of the intervals.
⪫┐┌×┬⊖θ↙
Print the first row of tick marks. The left and right characters are the wrong way around because the result is reflected later.
↓EE⊕θΣEη¬﹪ιλ⁺×│⊘ι×╵﹪ι²
Calculate the number of intervals that are a factor of each tick mark. Generate a string of │
s of half that length and add ╵
for odd lengths. Print each string downwards with subsequent strings in previous columns, i.e. reverse order.
‖
Reflect everything to get the ruler in left-to-right order.
$endgroup$
add a comment |
$begingroup$
Charcoal, 50 bytes
≔EηΠ…η⊕κη⪫┐┌×┬⊖θ↙↓EE⊕θΣEη¬﹪ιλ⁺×│⊘ι×╵﹪ι²‖
Try it online! Link is to verbose version of code. Box-drawing characters have a 3 byte representation in Charcoal, so the above string is only 40 characters long. Explanation:
≔EηΠ…η⊕κη
Calculate the cumulative product of the intervals.
⪫┐┌×┬⊖θ↙
Print the first row of tick marks. The left and right characters are the wrong way around because the result is reflected later.
↓EE⊕θΣEη¬﹪ιλ⁺×│⊘ι×╵﹪ι²
Calculate the number of intervals that are a factor of each tick mark. Generate a string of │
s of half that length and add ╵
for odd lengths. Print each string downwards with subsequent strings in previous columns, i.e. reverse order.
‖
Reflect everything to get the ruler in left-to-right order.
$endgroup$
Charcoal, 50 bytes
≔EηΠ…η⊕κη⪫┐┌×┬⊖θ↙↓EE⊕θΣEη¬﹪ιλ⁺×│⊘ι×╵﹪ι²‖
Try it online! Link is to verbose version of code. Box-drawing characters have a 3 byte representation in Charcoal, so the above string is only 40 characters long. Explanation:
≔EηΠ…η⊕κη
Calculate the cumulative product of the intervals.
⪫┐┌×┬⊖θ↙
Print the first row of tick marks. The left and right characters are the wrong way around because the result is reflected later.
↓EE⊕θΣEη¬﹪ιλ⁺×│⊘ι×╵﹪ι²
Calculate the number of intervals that are a factor of each tick mark. Generate a string of │
s of half that length and add ╵
for odd lengths. Print each string downwards with subsequent strings in previous columns, i.e. reverse order.
‖
Reflect everything to get the ruler in left-to-right order.
answered 14 hours ago
NeilNeil
80.8k744178
80.8k744178
add a comment |
add a comment |
$begingroup$
Ruby, 126 bytes
->l,i{y=1;[?┌+?┬*~-l+?┐]+i.each_slice(2).map{|j,k|x=y*j;y=k&&x*k;(0..l).map{|z|'│╵ '[(z%x<=>0)+(k ?z%y<=>0:1)]}*''}}
Try it online!
Looks rather verbose with all that each_slice
stuff, but will do for now, unless I manage to find a golfier approach.
Takes input as l
for length and i
for intervals, returns an array of strings.
$endgroup$
add a comment |
$begingroup$
Ruby, 126 bytes
->l,i{y=1;[?┌+?┬*~-l+?┐]+i.each_slice(2).map{|j,k|x=y*j;y=k&&x*k;(0..l).map{|z|'│╵ '[(z%x<=>0)+(k ?z%y<=>0:1)]}*''}}
Try it online!
Looks rather verbose with all that each_slice
stuff, but will do for now, unless I manage to find a golfier approach.
Takes input as l
for length and i
for intervals, returns an array of strings.
$endgroup$
add a comment |
$begingroup$
Ruby, 126 bytes
->l,i{y=1;[?┌+?┬*~-l+?┐]+i.each_slice(2).map{|j,k|x=y*j;y=k&&x*k;(0..l).map{|z|'│╵ '[(z%x<=>0)+(k ?z%y<=>0:1)]}*''}}
Try it online!
Looks rather verbose with all that each_slice
stuff, but will do for now, unless I manage to find a golfier approach.
Takes input as l
for length and i
for intervals, returns an array of strings.
$endgroup$
Ruby, 126 bytes
->l,i{y=1;[?┌+?┬*~-l+?┐]+i.each_slice(2).map{|j,k|x=y*j;y=k&&x*k;(0..l).map{|z|'│╵ '[(z%x<=>0)+(k ?z%y<=>0:1)]}*''}}
Try it online!
Looks rather verbose with all that each_slice
stuff, but will do for now, unless I manage to find a golfier approach.
Takes input as l
for length and i
for intervals, returns an array of strings.
answered 12 hours ago
Kirill L.Kirill L.
4,4051523
4,4051523
add a comment |
add a comment |
$begingroup$
R, 175 170 bytes
function(l,i,`&`=rep)rbind(c('┌','┬'&l-1,'┐'),if(i)sapply(rowSums(!outer(0:l,cumprod(i),`%%`)),function(j,x=j%/%2,y=j%%2)c('│'&x,'╵'&y,' '&(1+sum(1|i))/2-x-y)))
Try it online!
Takes empty intervals as 0
, returns a matrix of characters. TIO link displays the output pretty-printed.
$endgroup$
add a comment |
$begingroup$
R, 175 170 bytes
function(l,i,`&`=rep)rbind(c('┌','┬'&l-1,'┐'),if(i)sapply(rowSums(!outer(0:l,cumprod(i),`%%`)),function(j,x=j%/%2,y=j%%2)c('│'&x,'╵'&y,' '&(1+sum(1|i))/2-x-y)))
Try it online!
Takes empty intervals as 0
, returns a matrix of characters. TIO link displays the output pretty-printed.
$endgroup$
add a comment |
$begingroup$
R, 175 170 bytes
function(l,i,`&`=rep)rbind(c('┌','┬'&l-1,'┐'),if(i)sapply(rowSums(!outer(0:l,cumprod(i),`%%`)),function(j,x=j%/%2,y=j%%2)c('│'&x,'╵'&y,' '&(1+sum(1|i))/2-x-y)))
Try it online!
Takes empty intervals as 0
, returns a matrix of characters. TIO link displays the output pretty-printed.
$endgroup$
R, 175 170 bytes
function(l,i,`&`=rep)rbind(c('┌','┬'&l-1,'┐'),if(i)sapply(rowSums(!outer(0:l,cumprod(i),`%%`)),function(j,x=j%/%2,y=j%%2)c('│'&x,'╵'&y,' '&(1+sum(1|i))/2-x-y)))
Try it online!
Takes empty intervals as 0
, returns a matrix of characters. TIO link displays the output pretty-printed.
answered 10 hours ago
Kirill L.Kirill L.
4,4051523
4,4051523
add a comment |
add a comment |
$begingroup$
Canvas, 42 41 40 bytes
┐”┬”┌”O⁸╷×oo╵(0)⁷{*J╵;∔}m{2n“╵”×;“│”××]⤢
Try it here! (with a font that monospaces the output)
$endgroup$
add a comment |
$begingroup$
Canvas, 42 41 40 bytes
┐”┬”┌”O⁸╷×oo╵(0)⁷{*J╵;∔}m{2n“╵”×;“│”××]⤢
Try it here! (with a font that monospaces the output)
$endgroup$
add a comment |
$begingroup$
Canvas, 42 41 40 bytes
┐”┬”┌”O⁸╷×oo╵(0)⁷{*J╵;∔}m{2n“╵”×;“│”××]⤢
Try it here! (with a font that monospaces the output)
$endgroup$
Canvas, 42 41 40 bytes
┐”┬”┌”O⁸╷×oo╵(0)⁷{*J╵;∔}m{2n“╵”×;“│”××]⤢
Try it here! (with a font that monospaces the output)
edited 8 hours ago
answered 11 hours ago
dzaimadzaima
15k21856
15k21856
add a comment |
add a comment |
$begingroup$
Dyalog APL, 66 bytes
{(∊'┌'(1↓⍵⍴'┬')'┐')⍪⍉↑⊃,¨/(↓0 2⊤+⌿0=(×⍺)∘.|⍳1+⍵)⍴¨¨'│',⎕UCS 9589}
Try it online!
$endgroup$
add a comment |
$begingroup$
Dyalog APL, 66 bytes
{(∊'┌'(1↓⍵⍴'┬')'┐')⍪⍉↑⊃,¨/(↓0 2⊤+⌿0=(×⍺)∘.|⍳1+⍵)⍴¨¨'│',⎕UCS 9589}
Try it online!
$endgroup$
add a comment |
$begingroup$
Dyalog APL, 66 bytes
{(∊'┌'(1↓⍵⍴'┬')'┐')⍪⍉↑⊃,¨/(↓0 2⊤+⌿0=(×⍺)∘.|⍳1+⍵)⍴¨¨'│',⎕UCS 9589}
Try it online!
$endgroup$
Dyalog APL, 66 bytes
{(∊'┌'(1↓⍵⍴'┬')'┐')⍪⍉↑⊃,¨/(↓0 2⊤+⌿0=(×⍺)∘.|⍳1+⍵)⍴¨¨'│',⎕UCS 9589}
Try it online!
answered 7 hours ago
dzaimadzaima
15k21856
15k21856
add a comment |
add a comment |
$begingroup$
Haskell, 167 164 bytes
n%l|let c=take(n+1).cycle;m&(x:y:r)=c('│':init([1..y]>>(m*x)!" "++"╵"))++'n':(m*x*y)&r;m&[x]=c$'╵':(m*x)!" ";m&e=='┌':n!"┬"++"┐n"++1&l
n!s=[2..n]>>s
Try it online! There are still some redundancies which look like they could be exploited, but so far they withstood all further golfing attempts.
The previous 167 byte solution is the same apart from newline handling and is probably slightly better readable:
n%l=unlines$('┌':n!"┬"++"┐"):(take(n+1)<$>1&l)
n!s=[2..n]>>s
m&(x:y:r)=cycle('│':init([1..y]>>(m*x)!" "++"╵")):(m*x*y)&r
m&[x]=[cycle$'╵':(m*x)!" "]
m&e=
Try it online!
$endgroup$
$begingroup$
Different approach at 158 bytes (Try it online!), can probably be shortened quite a bit more since I don't speak Haskell well.
$endgroup$
– Οurous
2 hours ago
add a comment |
$begingroup$
Haskell, 167 164 bytes
n%l|let c=take(n+1).cycle;m&(x:y:r)=c('│':init([1..y]>>(m*x)!" "++"╵"))++'n':(m*x*y)&r;m&[x]=c$'╵':(m*x)!" ";m&e=='┌':n!"┬"++"┐n"++1&l
n!s=[2..n]>>s
Try it online! There are still some redundancies which look like they could be exploited, but so far they withstood all further golfing attempts.
The previous 167 byte solution is the same apart from newline handling and is probably slightly better readable:
n%l=unlines$('┌':n!"┬"++"┐"):(take(n+1)<$>1&l)
n!s=[2..n]>>s
m&(x:y:r)=cycle('│':init([1..y]>>(m*x)!" "++"╵")):(m*x*y)&r
m&[x]=[cycle$'╵':(m*x)!" "]
m&e=
Try it online!
$endgroup$
$begingroup$
Different approach at 158 bytes (Try it online!), can probably be shortened quite a bit more since I don't speak Haskell well.
$endgroup$
– Οurous
2 hours ago
add a comment |
$begingroup$
Haskell, 167 164 bytes
n%l|let c=take(n+1).cycle;m&(x:y:r)=c('│':init([1..y]>>(m*x)!" "++"╵"))++'n':(m*x*y)&r;m&[x]=c$'╵':(m*x)!" ";m&e=='┌':n!"┬"++"┐n"++1&l
n!s=[2..n]>>s
Try it online! There are still some redundancies which look like they could be exploited, but so far they withstood all further golfing attempts.
The previous 167 byte solution is the same apart from newline handling and is probably slightly better readable:
n%l=unlines$('┌':n!"┬"++"┐"):(take(n+1)<$>1&l)
n!s=[2..n]>>s
m&(x:y:r)=cycle('│':init([1..y]>>(m*x)!" "++"╵")):(m*x*y)&r
m&[x]=[cycle$'╵':(m*x)!" "]
m&e=
Try it online!
$endgroup$
Haskell, 167 164 bytes
n%l|let c=take(n+1).cycle;m&(x:y:r)=c('│':init([1..y]>>(m*x)!" "++"╵"))++'n':(m*x*y)&r;m&[x]=c$'╵':(m*x)!" ";m&e=='┌':n!"┬"++"┐n"++1&l
n!s=[2..n]>>s
Try it online! There are still some redundancies which look like they could be exploited, but so far they withstood all further golfing attempts.
The previous 167 byte solution is the same apart from newline handling and is probably slightly better readable:
n%l=unlines$('┌':n!"┬"++"┐"):(take(n+1)<$>1&l)
n!s=[2..n]>>s
m&(x:y:r)=cycle('│':init([1..y]>>(m*x)!" "++"╵")):(m*x*y)&r
m&[x]=[cycle$'╵':(m*x)!" "]
m&e=
Try it online!
edited 5 hours ago
answered 5 hours ago
LaikoniLaikoni
19.9k436100
19.9k436100
$begingroup$
Different approach at 158 bytes (Try it online!), can probably be shortened quite a bit more since I don't speak Haskell well.
$endgroup$
– Οurous
2 hours ago
add a comment |
$begingroup$
Different approach at 158 bytes (Try it online!), can probably be shortened quite a bit more since I don't speak Haskell well.
$endgroup$
– Οurous
2 hours ago
$begingroup$
Different approach at 158 bytes (Try it online!), can probably be shortened quite a bit more since I don't speak Haskell well.
$endgroup$
– Οurous
2 hours ago
$begingroup$
Different approach at 158 bytes (Try it online!), can probably be shortened quite a bit more since I don't speak Haskell well.
$endgroup$
– Οurous
2 hours ago
add a comment |
$begingroup$
Jelly, 42 41 bytes
‘Rm×}Ṭ€+2/
⁽!ṣ;“½¥÷I‘ÄỌṙ-;⁶
Ḷ¬;.Ḥ~W;ñị¢Y
A full program.
Try it online!
Or see a test-suite
Note: this code has been altered from a full program -- ñ
(next link as a dyad) has been replaced with 1ŀ
(link at index 1 as a dyad) to allow it to be called multiple times by the footer.
How?
‘Rm×}Ṭ€+2/ - Link 1, lower interval tick types: length; intervals e.g. 7; [3,2]
‘ - increment length 8
R - range [1,2,3,4,5,6,7,8]
} - use right argument for this monad as if it were a dyad:
× - cumulative reduce by multiplication [3,6]
m - modulo slice (vectorises) [[1,4,7],[1,7]]
Ṭ€ - untruth €ach [[1,0,0,1,0,0,1],[1,0,0,0,0,0,1]]
+2/ - pairwise reduce with addition [[2,0,0,1,0,0,2]]
- -- yielding a list of types for each row of characters below the first
- where 0 is a space, 1 is a short tick-mark and 2 is a long tick-mark
⁽!ṣ;“½¥÷I‘ÄỌṙ-;⁶ - Link 2, make character set: no arguments
⁽!ṣ - literal 9474
“½¥÷I‘ - list of code-page indices = [10,4,28,73]
; - concatenate [9474,10,4,28,73]
Ä - cumulative addition [9474,9484,9488,9516,9589]
Ọ - to characters "│┌┐┬╵"
ṙ- - rotate left by -1 "╵│┌┐┬"
⁶ - literal space character ' '
; - concatenate "╵│┌┐┬ "
Ḷ¬;.Ḥ~W;ñị¢Y - Main link: length, L; intervals, I
Ḷ - lowered range [ 0, 1, 2, ..., L-1]
¬ - logical Not [ 1, 0, 0, ..., 0]
. - literal 0.5
; - concatenate [ 1, 0, 0, ..., 0, 0.5]
Ḥ - double [ 2, 0, 0, ..., 0, 1]
~ - bitwise NOT [-3,-1,-1, ...,-1,-2]
W - wrap that in a list [[-3,-1,-1, ...,-1,-2]]
ñ - call next Link (1) as a dyad (f(L, I))
; - (left) concatenated with (right)
¢ - call last Link (2) as a nilad (f())
ị - (left) index into (right) (1-indexed and modular)
Y - join with newline characters
- implicit print
$endgroup$
add a comment |
$begingroup$
Jelly, 42 41 bytes
‘Rm×}Ṭ€+2/
⁽!ṣ;“½¥÷I‘ÄỌṙ-;⁶
Ḷ¬;.Ḥ~W;ñị¢Y
A full program.
Try it online!
Or see a test-suite
Note: this code has been altered from a full program -- ñ
(next link as a dyad) has been replaced with 1ŀ
(link at index 1 as a dyad) to allow it to be called multiple times by the footer.
How?
‘Rm×}Ṭ€+2/ - Link 1, lower interval tick types: length; intervals e.g. 7; [3,2]
‘ - increment length 8
R - range [1,2,3,4,5,6,7,8]
} - use right argument for this monad as if it were a dyad:
× - cumulative reduce by multiplication [3,6]
m - modulo slice (vectorises) [[1,4,7],[1,7]]
Ṭ€ - untruth €ach [[1,0,0,1,0,0,1],[1,0,0,0,0,0,1]]
+2/ - pairwise reduce with addition [[2,0,0,1,0,0,2]]
- -- yielding a list of types for each row of characters below the first
- where 0 is a space, 1 is a short tick-mark and 2 is a long tick-mark
⁽!ṣ;“½¥÷I‘ÄỌṙ-;⁶ - Link 2, make character set: no arguments
⁽!ṣ - literal 9474
“½¥÷I‘ - list of code-page indices = [10,4,28,73]
; - concatenate [9474,10,4,28,73]
Ä - cumulative addition [9474,9484,9488,9516,9589]
Ọ - to characters "│┌┐┬╵"
ṙ- - rotate left by -1 "╵│┌┐┬"
⁶ - literal space character ' '
; - concatenate "╵│┌┐┬ "
Ḷ¬;.Ḥ~W;ñị¢Y - Main link: length, L; intervals, I
Ḷ - lowered range [ 0, 1, 2, ..., L-1]
¬ - logical Not [ 1, 0, 0, ..., 0]
. - literal 0.5
; - concatenate [ 1, 0, 0, ..., 0, 0.5]
Ḥ - double [ 2, 0, 0, ..., 0, 1]
~ - bitwise NOT [-3,-1,-1, ...,-1,-2]
W - wrap that in a list [[-3,-1,-1, ...,-1,-2]]
ñ - call next Link (1) as a dyad (f(L, I))
; - (left) concatenated with (right)
¢ - call last Link (2) as a nilad (f())
ị - (left) index into (right) (1-indexed and modular)
Y - join with newline characters
- implicit print
$endgroup$
add a comment |
$begingroup$
Jelly, 42 41 bytes
‘Rm×}Ṭ€+2/
⁽!ṣ;“½¥÷I‘ÄỌṙ-;⁶
Ḷ¬;.Ḥ~W;ñị¢Y
A full program.
Try it online!
Or see a test-suite
Note: this code has been altered from a full program -- ñ
(next link as a dyad) has been replaced with 1ŀ
(link at index 1 as a dyad) to allow it to be called multiple times by the footer.
How?
‘Rm×}Ṭ€+2/ - Link 1, lower interval tick types: length; intervals e.g. 7; [3,2]
‘ - increment length 8
R - range [1,2,3,4,5,6,7,8]
} - use right argument for this monad as if it were a dyad:
× - cumulative reduce by multiplication [3,6]
m - modulo slice (vectorises) [[1,4,7],[1,7]]
Ṭ€ - untruth €ach [[1,0,0,1,0,0,1],[1,0,0,0,0,0,1]]
+2/ - pairwise reduce with addition [[2,0,0,1,0,0,2]]
- -- yielding a list of types for each row of characters below the first
- where 0 is a space, 1 is a short tick-mark and 2 is a long tick-mark
⁽!ṣ;“½¥÷I‘ÄỌṙ-;⁶ - Link 2, make character set: no arguments
⁽!ṣ - literal 9474
“½¥÷I‘ - list of code-page indices = [10,4,28,73]
; - concatenate [9474,10,4,28,73]
Ä - cumulative addition [9474,9484,9488,9516,9589]
Ọ - to characters "│┌┐┬╵"
ṙ- - rotate left by -1 "╵│┌┐┬"
⁶ - literal space character ' '
; - concatenate "╵│┌┐┬ "
Ḷ¬;.Ḥ~W;ñị¢Y - Main link: length, L; intervals, I
Ḷ - lowered range [ 0, 1, 2, ..., L-1]
¬ - logical Not [ 1, 0, 0, ..., 0]
. - literal 0.5
; - concatenate [ 1, 0, 0, ..., 0, 0.5]
Ḥ - double [ 2, 0, 0, ..., 0, 1]
~ - bitwise NOT [-3,-1,-1, ...,-1,-2]
W - wrap that in a list [[-3,-1,-1, ...,-1,-2]]
ñ - call next Link (1) as a dyad (f(L, I))
; - (left) concatenated with (right)
¢ - call last Link (2) as a nilad (f())
ị - (left) index into (right) (1-indexed and modular)
Y - join with newline characters
- implicit print
$endgroup$
Jelly, 42 41 bytes
‘Rm×}Ṭ€+2/
⁽!ṣ;“½¥÷I‘ÄỌṙ-;⁶
Ḷ¬;.Ḥ~W;ñị¢Y
A full program.
Try it online!
Or see a test-suite
Note: this code has been altered from a full program -- ñ
(next link as a dyad) has been replaced with 1ŀ
(link at index 1 as a dyad) to allow it to be called multiple times by the footer.
How?
‘Rm×}Ṭ€+2/ - Link 1, lower interval tick types: length; intervals e.g. 7; [3,2]
‘ - increment length 8
R - range [1,2,3,4,5,6,7,8]
} - use right argument for this monad as if it were a dyad:
× - cumulative reduce by multiplication [3,6]
m - modulo slice (vectorises) [[1,4,7],[1,7]]
Ṭ€ - untruth €ach [[1,0,0,1,0,0,1],[1,0,0,0,0,0,1]]
+2/ - pairwise reduce with addition [[2,0,0,1,0,0,2]]
- -- yielding a list of types for each row of characters below the first
- where 0 is a space, 1 is a short tick-mark and 2 is a long tick-mark
⁽!ṣ;“½¥÷I‘ÄỌṙ-;⁶ - Link 2, make character set: no arguments
⁽!ṣ - literal 9474
“½¥÷I‘ - list of code-page indices = [10,4,28,73]
; - concatenate [9474,10,4,28,73]
Ä - cumulative addition [9474,9484,9488,9516,9589]
Ọ - to characters "│┌┐┬╵"
ṙ- - rotate left by -1 "╵│┌┐┬"
⁶ - literal space character ' '
; - concatenate "╵│┌┐┬ "
Ḷ¬;.Ḥ~W;ñị¢Y - Main link: length, L; intervals, I
Ḷ - lowered range [ 0, 1, 2, ..., L-1]
¬ - logical Not [ 1, 0, 0, ..., 0]
. - literal 0.5
; - concatenate [ 1, 0, 0, ..., 0, 0.5]
Ḥ - double [ 2, 0, 0, ..., 0, 1]
~ - bitwise NOT [-3,-1,-1, ...,-1,-2]
W - wrap that in a list [[-3,-1,-1, ...,-1,-2]]
ñ - call next Link (1) as a dyad (f(L, I))
; - (left) concatenated with (right)
¢ - call last Link (2) as a nilad (f())
ị - (left) index into (right) (1-indexed and modular)
Y - join with newline characters
- implicit print
edited 1 hour ago
answered 11 hours ago
Jonathan AllanJonathan Allan
52.1k535170
52.1k535170
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 204 bytes
a=>b=>{Write("┌"+"┐n".PadLeft(++a,'┬'));for(int i=1;;i++,WriteLine())for(int j=0;j<a;){var m=b.Select((c,d)=>b.Take(d+1).Aggregate((e,f)=>e*f)).Count(c=>j++%c<1);Write(m<1|i>m?" ":m<2?"╵":"|");}}
Try it online!
Outputs, but gets stuck in an infinite loop.
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 204 bytes
a=>b=>{Write("┌"+"┐n".PadLeft(++a,'┬'));for(int i=1;;i++,WriteLine())for(int j=0;j<a;){var m=b.Select((c,d)=>b.Take(d+1).Aggregate((e,f)=>e*f)).Count(c=>j++%c<1);Write(m<1|i>m?" ":m<2?"╵":"|");}}
Try it online!
Outputs, but gets stuck in an infinite loop.
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 204 bytes
a=>b=>{Write("┌"+"┐n".PadLeft(++a,'┬'));for(int i=1;;i++,WriteLine())for(int j=0;j<a;){var m=b.Select((c,d)=>b.Take(d+1).Aggregate((e,f)=>e*f)).Count(c=>j++%c<1);Write(m<1|i>m?" ":m<2?"╵":"|");}}
Try it online!
Outputs, but gets stuck in an infinite loop.
$endgroup$
C# (Visual C# Interactive Compiler), 204 bytes
a=>b=>{Write("┌"+"┐n".PadLeft(++a,'┬'));for(int i=1;;i++,WriteLine())for(int j=0;j<a;){var m=b.Select((c,d)=>b.Take(d+1).Aggregate((e,f)=>e*f)).Count(c=>j++%c<1);Write(m<1|i>m?" ":m<2?"╵":"|");}}
Try it online!
Outputs, but gets stuck in an infinite loop.
edited 19 hours ago
answered 20 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
1,020119
1,020119
add a comment |
add a comment |
$begingroup$
Clean, 221 201 195 162 bytes
import StdEnv
$n l=[["┌":repeatn(n-1)"┬"]++["┐"]:[[if(?(i-1))if(?i&&l%(i,i)>)"│""╵"" "\p<-[0..n],let?j=1>p rem(prod(l%(0,j)))
]\i<-[1,3..length l]]]
Try it online!
Returns a list of lists of UTF-8 characters (as strings, since Clean has no innate UTF-8 support).
Works by generating the first line, then taking the product of prefixes of the list provided in groups of two, and checks which mark to draw based on whether the product divides the current character position.
Ungolfed:
$ n l
= [
["┌": repeatn (n - 1) "┬"] ++ ["┐"]:
[
[
if(? (i - 1))
if(? i && l%(i, i) > )
"│"
"╵"
" "
\ p <- [0..n]
, let
? j = 1 > p rem (prod (l%(0, j)))
]
\ i <- [1, 3.. length l]
]
]
$endgroup$
add a comment |
$begingroup$
Clean, 221 201 195 162 bytes
import StdEnv
$n l=[["┌":repeatn(n-1)"┬"]++["┐"]:[[if(?(i-1))if(?i&&l%(i,i)>)"│""╵"" "\p<-[0..n],let?j=1>p rem(prod(l%(0,j)))
]\i<-[1,3..length l]]]
Try it online!
Returns a list of lists of UTF-8 characters (as strings, since Clean has no innate UTF-8 support).
Works by generating the first line, then taking the product of prefixes of the list provided in groups of two, and checks which mark to draw based on whether the product divides the current character position.
Ungolfed:
$ n l
= [
["┌": repeatn (n - 1) "┬"] ++ ["┐"]:
[
[
if(? (i - 1))
if(? i && l%(i, i) > )
"│"
"╵"
" "
\ p <- [0..n]
, let
? j = 1 > p rem (prod (l%(0, j)))
]
\ i <- [1, 3.. length l]
]
]
$endgroup$
add a comment |
$begingroup$
Clean, 221 201 195 162 bytes
import StdEnv
$n l=[["┌":repeatn(n-1)"┬"]++["┐"]:[[if(?(i-1))if(?i&&l%(i,i)>)"│""╵"" "\p<-[0..n],let?j=1>p rem(prod(l%(0,j)))
]\i<-[1,3..length l]]]
Try it online!
Returns a list of lists of UTF-8 characters (as strings, since Clean has no innate UTF-8 support).
Works by generating the first line, then taking the product of prefixes of the list provided in groups of two, and checks which mark to draw based on whether the product divides the current character position.
Ungolfed:
$ n l
= [
["┌": repeatn (n - 1) "┬"] ++ ["┐"]:
[
[
if(? (i - 1))
if(? i && l%(i, i) > )
"│"
"╵"
" "
\ p <- [0..n]
, let
? j = 1 > p rem (prod (l%(0, j)))
]
\ i <- [1, 3.. length l]
]
]
$endgroup$
Clean, 221 201 195 162 bytes
import StdEnv
$n l=[["┌":repeatn(n-1)"┬"]++["┐"]:[[if(?(i-1))if(?i&&l%(i,i)>)"│""╵"" "\p<-[0..n],let?j=1>p rem(prod(l%(0,j)))
]\i<-[1,3..length l]]]
Try it online!
Returns a list of lists of UTF-8 characters (as strings, since Clean has no innate UTF-8 support).
Works by generating the first line, then taking the product of prefixes of the list provided in groups of two, and checks which mark to draw based on whether the product divides the current character position.
Ungolfed:
$ n l
= [
["┌": repeatn (n - 1) "┬"] ++ ["┐"]:
[
[
if(? (i - 1))
if(? i && l%(i, i) > )
"│"
"╵"
" "
\ p <- [0..n]
, let
? j = 1 > p rem (prod (l%(0, j)))
]
\ i <- [1, 3.. length l]
]
]
edited 2 hours ago
answered 3 hours ago
ΟurousΟurous
7,06111035
7,06111035
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f180063%2farbitrary-interval-ruler%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
For output, can I print the first row, then return a list of columns?
$endgroup$
– Embodiment of Ignorance
yesterday
$begingroup$
@EmbodimentofIgnorance, I'm gonna say no to that. Output should be consistent.
$endgroup$
– Beefster
23 hours ago
$begingroup$
Can we take the box-drawing characters from a single-byte encoding (provided one exists containing the ones required)?
$endgroup$
– Οurous
2 hours ago