| Bytes | Lang | Time | Link |
|---|---|---|---|
| 060 | AWK | 250910T143717Z | xrs |
| 019 | Thunno | 230302T164614Z | The Thon |
| 049 | Excel | 230302T152638Z | pneumann |
| 018 | Stax | 180302T225527Z | Weijun Z |
| 039 | Perl 6 | 180302T202703Z | bb94 |
| 019 | 05AB1E | 180302T181256Z | Magic Oc |
| 034 | V | 180302T093043Z | oktupol |
| 044 | R | 170909T172649Z | Giuseppe |
| 041 | Jotlin | 180228T210233Z | jrtapsel |
| 030 | K oK | 180228T223022Z | mkst |
| 053 | Excel | 170911T100058Z | Wernisch |
| 050 | Rabbit~ | 170915T130859Z | Adam |
| 059 | PowerShell | 170911T130816Z | AdmBorkB |
| 050 | Python 3 | 170909T170927Z | Mr. Xcod |
| 021 | Japt | 170909T155413Z | Shaggy |
| 055 | Java 8 | 170911T083247Z | Kevin Cr |
| 055 | Bash | 170911T013234Z | Justin M |
| 110 | C# | 170910T211622Z | snorepio |
| 074 | Ly | 170910T082405Z | LyricLy |
| 025 | Pyth | 170909T171816Z | Mr. Xcod |
| 028 | Pyke | 170909T203855Z | Mr. Xcod |
| 051 | Javascript ES6 | 170909T142705Z | Endenite |
| 061 | C | 170909T141725Z | Steadybo |
| 040 | TIBasic | 170909T185743Z | Timtech |
| 056 | Kotlin | 170909T174724Z | jrtapsel |
| nan | Perl 5 | 170909T173323Z | Xcali |
| 030 | Recursiva | 170909T145729Z | 0xffcour |
| 031 | J | 170909T152229Z | miles |
| 014 | Jelly | 170909T150049Z | Jonathan |
| 030 | Pyth | 170909T145953Z | Karan El |
| 019 | Jelly | 170909T145839Z | fireflam |
| 077 | Python 2 | 170909T140752Z | Jonathan |
Thunno, 19 bytes
"\rª´ĦĬ"O>S70_C
Uses the same method as quite a few other answers.
Explanation
"\rª´ĦĬ"O>S70_C # Implicit input
"\rª´ĦĬ"O # Push the list [13, 170, 180, 294, 300]
> # Check if the input is greater than these numbers
S # Sum the resulting list
70_ # Subtract the sum from 70
C # And this codepoint into a character
# Implicit output
Excel, 49 bytes
=MID("FEDCBA",MATCH(A1,{0;14;171;181;295;301}),1)
just taking advantage of the MATCH function's default match type behaviour but i'm sure there's a shorter answer
if someone has more experience with excel, please comment any ways i can improve this answer!
Stax, 18 bytes
5"«µħĭ",+|oH-VA@]
Explanation
Bytes counted in CP437.
5"«µħĭ",+|oH-VA@]
5 - 5 minus the result of the following
"«µħĭ" [14, 171, 181, 295, 301]
,+ Append input
|oH Index of last element if the array were to be sorted
VA@] Letter in the alphabet with the given index
Perl 6, 42 39 bytes
{chr(65+[+] "\rª´ĦĬ".ords »>»$_)}
V, 37 34 bytes
aFEDCBA5äh113äh9äh156äh13ähÀ|vyVp
Hexdump:
00000000: 3133 4146 1b31 3536 4145 1b39 4144 1b31 13AF.156AE.9AD.1
00000010: 3133 4143 1b35 4142 1b36 3441 411b eec0 13AC.5AB.64AA...
00000020: 7c76 7956 70 |vyVp
Basic idea:
- Print
FEDCBA, create 5 copies of B, 113 copies of C etc. resulting in the stringFFFFFFFFFFFFFEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCBBBBBA(There is probably a more efficient way to do this) - Go to
nth column (nis the first argument), copy a single character and replace the entire string with it.
R, 50 44 bytes
LETTERS[6-sum(scan()>c(13,170,180,294,300))]
same as the javascript answer, but uses R's vectorization and LETTERS builtin to come in a tiny bit shorter.
Thanks to rturnbull for shaving off those last 6 bytes.
Jotlin, 48 41 bytes
{v->'F'-l(13,170,180,294,300).f{a<v}.l()}
Whole program:
var x:(Int)->Char =
{v->'F'-l(13,170,180,294,300).f{a<v}.l()}
println(x(12))
println(x(15))
println(x(301))
println(x(181))
Ported my previous Kotlin answer here.
K (oK), 30 bytes
Solution:
"FEDCBA"@0 14 171 181 295 301'
Explanation:
Index into the correct bucket:
"FEDCBA"@0 14 171 181 295 301' / the solution
0 14 171 181 295 301' / bin (') input in a bucket
"FEDCBA"@ / index (@) into "FEDCBA"
Excel, 53 bytes
Sum of conditions, then returns the required ASCII character:
=CHAR((A1<14)+(A1<171)+(A1<181)+(A1<295)+(A1<301)+65)
Alternative solutions:
Summing conditions, return string index (63 bytes):
=MID("ABCDEF",(A1<14)+(A1<171)+(A1<181)+(A1<295)+(A1<301)+1,1)
Rabbit~, 50 bytes
(Noncompeting, postdates question. I just finished the interpreter(yay) and wanted to try and solve something. This is also my first code golf thing ever)
=>FEDCBA$<({.0-\_-^\-&^?n&&}_}\>\{{\>:.¤})Ð"ỤṅỌrḲA
It basically takes the differences from one grade to the next 14,157,10,114,6,65 (encoded as ỤṅỌrḲA) and subtracts from the input. If a negative number is found it stops progressing along the 'FEDCBA' sequence and outputs the letter.
Small explanation of this beautiful piece of syntax
Rabbit~ uses a grid based memory with one or several carets you can move around; this solution uses 2.
=>FEDCBA$<({.0-\_-^\-&^?n&&}_}\>\{{\>:.¤})Ð"ỤṅỌrḲA - Full program.
FEDCBA - Load bytes into grid
Ð"ỤṅỌrḲA - Load bytes 14,157,10,114,6,65 into second line of data grid
= - Read input
> < _ ^ ^ _ > > - Move caret (most instructions read from the grid below the active caret)
$ - Create a new caret
( ) - Loop
{.0 } } {{ } - Conditional statement checking if value at caret == 0 then move active caret to next grade else print and quit
- - - - Subtract
\ \ \ \ - Cycle active caret
& && - Bitwise and to see if number is negative
?n - Get negative sign bit
:. - Print value at caret as character
¤ - Terminate program
PowerShell, 59 bytes
(,'F'*14+,'E'*157+,'D'*10+,'C'*114+,'B'*6+,'A'*65)["$args"]
Similar-ish to Jonathan Allen's Jelly answer, in that we're constructing an array of all the letters concatenated together, then indexing into that array with the input $args.
Python 3, 50 bytes
Thanks to @jferard for -4 bytes.
lambda n:chr(70-sum(n>ord(x)for x in"\rª´ĦĬ"))
Python 3, 54 bytes
lambda n:chr(70-sum(n>x for x in[13,170,180,294,300]))
Saved 2 bytes thanks to @mathmandan, and indirectly thanks to @JonathanFrech.
Python 2, 56 bytes
lambda n:"ABCDEF"[sum(n<x for x in[14,171,181,295,301])]
Japt, 23 21 bytes
'Gc-[#ªT#´D294L*3]è<U
Explantion
Implicit input of integer U.
'Gc-
Subtract from the codepoints of the (single character) string G ...
è<U
The count of elements less than U ...
[#ªT#´D294L*3]
In the array of 170 (#ª), 0 (T), 180 (#´), 13 (D), 294 (literal) & 300 (L*3), so formatted and ordered to avoid the use of delimiting commas. 0 could be removed (subtracting from the codepoint of F instead) but then a comma would need to be added or C*F (12*15) used for 180, ultimately saving no bytes.
Java 8, 55 bytes
n->n<14?'F':n<171?'E':n<181?'D':n<295?'C':n<301?'B':'A'
Alternative 57 bytes:
n->(char)(n<14?70:n<171?69:n<181?68:n<295?67:n<301?66:65)
Alternative 60 bytes:
n->"FEDCBA".charAt(n<14?0:n<171?1:n<181?2:n<295?3:n<301?4:5)
Maybe some kind of formula can be find to get 0-5 in a shorter way than n<14?0:n<171?1:n<181?2:n<295?3:n<301?4:5 using the last approach. Still investigating this.
Bash, 55 bytes
echo obase=16\;10 $[$1<{14,171,181,295,301}]|tr \ +|bc
C#, 110 bytes
x=>{if(x<14)return"F";if(x<171)return"E";if(x<181)return"D";if(x<295)return"C";if(x<301)return"B";return"A";};
Ly, 74 bytes
n(14)L["F"o;]p(171)L["E"o;]p(181)L["D"o;]p(195)L["C"o;]p(301)L["B"o;]"A"o;
A simple if-chain approach. I doubt it can be made much shorter.
Pyth, 25 26 bytes
@<G6sgRQ[13*17T180*30T294
Explanation
@<G6sgRQ[13*17T180*30T294 - Full program.
G - The lowercase alphabet.
< 6 - With the letters after the index 6 trimmed. We will call "S".
[ - Initialise a list literal.
13 - The literal 13.
*17T - The integer 170, composed by 17 * 10, so save whitespace.
180 - The literal 180.
294 - The literal 294.
*30T - The integer 300, composed by 30 * 10.
gRQ - For each element, return 1 if is is ≥ the input. 0 otherwise.
s - Sum.
@ - Get the index into S of ^.
- Output implicitly.
Pyke, 28 bytes
G6<13T17*180T30*294]5FhQ>)s@
Explanation
G6<13T17*180T30*294]5FhQ>)s@ - Full program. T is the constant for 10.
G - The lowercase alphabet.
6< - With the letters after the index 6 trimmed.
13 - The literal 13.
T17* - The integer 170, composed by 17 * 10, to save whitespace.
180 - The literal 180.
T30* - The integer 300, composed by 30 * 10.
294 - The literal 294.
]5 - Create a list of 5 elements.
FhQ>) - For each element in the list.
h - Increment.
Q - The input.
> - Is smaller ^^ than ^? Yields 1 for truthy and 0 for falsy.
)s - Close loop and sum.
@ - Get the index in the alphabet substring explained above.
Javascript (ES6), 51 bytes
n=>"ABCDEF"[(n<14)+(n<171)+(n<181)+(n<295)+(n<301)]
Alternative solutions (longer):
53 52 bytes (-1 byte thanks to @Arnauld)
n=>"FEDCBA"[n>300?5:n>294?4:n>180?3:n>170?2:+(n>13)]
55 53 bytes (-2 bytes thanks to @Neil)
n=>"AFEDCB"[[14,171,181,295,301].findIndex(m=>n<m)+1]
55 bytes
n=>"FEDCBA"[[13,170,180,294,300].filter(m=>n>m).length]
Example code snippet:
f=
n=>"ABCDEF"[(n<14)+(n<171)+(n<181)+(n<295)+(n<301)]
console.log(f(12))
console.log(f(15))
console.log(f(301))
console.log(f(181))
C, 62 61 bytes
Thanks to @Jonathan Frech for saving a byte!
f(n){putchar(70-(n<14?0:n<171?1:n<181?2:n<295?3:n<301?4:5));}
C, 57 bytes
#define f(n)70-(n<14?0:n<171?1:n<181?2:n<295?3:n<301?4:5)
C (gcc), 54 bytes
f(n){n=70-(n<14?0:n<171?1:n<181?2:n<295?3:n<301?4:5);}
C (gcc), 50 bytes
Using @Herman Lauenstein's solution.
f(n){n=65+(n<14)+(n<171)+(n<181)+(n<295)+(n<301);}
TI-Basic, 40 bytes
sub("FEDCBA",sum(Ans≥{0,14,171,181,295,301}),1
Kotlin, 56 bytes
{v->'F'-listOf(13,170,180,294,300).filter{it<v}.count()}
Beautified
{ v->
// Count the grades passed, then subtract that from F
'F' - listOf(13,170,180,294,300)
.filter { it < v }
.count()
}
Test
var x:(Int)->Char =
{v->'F'-listOf(13,170,180,294,300).filter{it<v}.count()}
fun main(args: Array<String>) {
println(x(12))
println(x(15))
println(x(301))
println(x(181))
}
Recursiva, 49 30 bytes
Y(++++<a301<a295<a181<a171<a14
Allow me to answer my own question in my own language. :D
- saved 19 bytes by using technique from @Herman Lauenstein's amazing JS answer
Explanation:
Y(++++<a301<a295<a181<a171<a14
<a301<a295<a181<a171<a14 calculate true/false for all the conditions
++++ sum up all the conditions to obtain n which can be either 0,1,2,3,4 or 5
( yield upper-case Alphabet
Y Get n-th element
J, 31 bytes
'FEDCBA'{~13 170 180 294 300&I.
Explanation
'FEDCBA'{~13 170 180 294 300&I. Input: n
13 170 180 294 300 Constant array [13, 170, 180, 294, 300]
&I. Use it with interval index to find which of
the intervals (-∞, 13], (13, 170], (170, 180],
(180, 294], (294, 300], (300, ∞) n can be inserted at
{~ Index into
'FEDCBA' This string and return that char
Jelly, 18 17 15 14 bytes
NịØAx“A©r½ɗÇ‘¤
A monadic link taking a number and returning a character.
Try it online! or see all input-output pairs.
How?
NịØAx“A©r½ɗÇ‘¤ - Link: number, d
N - negate d
¤ - nilad followed by link(s) as a nilad:
ØA - uppercase alphabet yield = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
“A©r½ɗÇ‘ - code-page indices = [65,6,114,10,157,14]
x - times = 'A'x65+'B'*6+'C'x114+'D'x10+'E'*157+'F'*14
ị - index into (1-indexed & modular - hence the negation to allow all Fs
to be together at one end)
Pyth, 30 bytes
@GtlfgTQmCdc"\r ª ´ & , m"d
The site doesn't seem to show the character with code point 1, so you need to insert a character with code point 1 before the &, ,, and m at the end
(Replace all 1s with character with code point 1):
@GtlfgTQmCdc"\r ª ´ 1& 1, 1m"d
Python 2, 77 bytes
lambda n:chr(70-sorted(_*(n>(0,13,170,180,294,300)[_])for _ in range(6))[-1])